Professional Documents
Culture Documents
1. What is the primary goal of recovering a Binary Search Tree (BST) in an interview context?
**Answer: C**
c) When two nodes in the BST are swapped or have incorrect values
**Answer: C**
3. Which of the following is NOT a primary approach for recovering a corrupted BST?
b) Morris Traversal
c) Preorder Traversal
**Answer: C**
**Answer: C**
5. Which complexity measure evaluates the efficiency of an algorithm in terms of the number of nodes
in a BST?
a) Time Complexity
b) Space Complexity
c) Memory Complexity
d) Computational Complexity
**Answer: A**
6. What is the time complexity of both the Inorder Traversal with Two-Pointer Approach and Morris
Traversal?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
**Answer: C**
7. In the context of recovering a BST, what is the space complexity of Morris Traversal?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
**Answer: A**
8. Which traversal method uses threaded binary trees to traverse the BST without using additional
space?
b) Preorder Traversal
c) Postorder Traversal
d) Morris Traversal
**Answer: D**
9. When might the Two-Pointer Approach for recovering a BST have higher space complexity?
a) In a balanced BST
b) In a skewed tree
**Answer: B**
10. Which method is generally preferred when memory constraints are important in recovering a
corrupted BST?
b) Preorder Traversal
c) Postorder Traversal
d) Morris Traversal
**Answer: D**
1. What is the primary purpose of Breadth First Traversal (BFS) in a graph or tree data structure?
**Answer: D**
**Answer: B**
a) Stack
b) Queue
c) Linked List
d) Array
**Answer: B**
4. What is the primary application of Depth First Search (DFS) in an unweighted graph?
**Answer: B**
5. How does DFS traversal differ from BFS traversal in terms of the data structure used?
**Answer: B**
6. Which algorithm is typically used to compute the maximum flow in a flow network?
c) Ford-Fulkerson method
d) Dijkstra's algorithm
**Answer: C**
7. In DFS, what action is taken after adding a vertex to the visited list?
**Answer: D**
8. Which traversal method is primarily used to determine the shortest path in a graph or tree?
c) Preorder Traversal
d) Inorder Traversal
**Answer: B**
9. What is a common application of DFS in the context of a bipartite graph?
a) Detecting cycles
c) Topological sorting
**Answer: D**
10. Which traversal method is commonly used to find the minimum spanning tree in an unweighted
graph?
c) Dijkstra's algorithm
d) Prim's algorithm
**Answer: A**
VERTICAL ORDER TRAVERSAL
1. What does Vertical Order Traversal of a binary tree involve?
**Answer: B**
**Answer: B**
**Answer: C**
a) O(n)
b) O(log n)
c) O(n^2)
d) O(n log n)
**Answer: D**
5. What is the space complexity of Vertical Order Traversal?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
**Answer: C**
6. What data structure is typically used to store nodes by their vertical positions during Vertical Order
Traversal?
a) Queue
b) Stack
c) TreeMap
d) HashMap
**Answer: C**
7. In Vertical Order Traversal, how are nodes within the same vertical column ordered?
c) Randomly
**Answer: A**
8. Which traversal technique is used to process nodes in top-down order within each vertical column
during Vertical Order Traversal?
a) Preorder traversal
b) Inorder traversal
c) Postorder traversal
d) Level-order traversal
**Answer: D**
**Answer: B**
10. What aspect of the binary tree's structure does Vertical Order Traversal emphasize?
**Answer: D**
BOUNDARY TRAVERSAL
1. What is the primary objective of binary tree boundary traversal?
c) To print the root, left leaves, and right leaves of the tree
**Answer: C**
2. What are the main steps involved in binary tree boundary traversal?
**Answer: C**
a) O(log n)
b) O(n)
c) O(n^2)
d) O(1)
**Answer: B**
4. How can you modify the binary tree boundary traversal algorithm to ensure only distinct values are
printed?
**Answer: B**
5. Which factor primarily determines the space complexity of binary tree boundary traversal?
**Answer: B**
6. What data structure can be used to implement an iterative binary tree boundary traversal?
a) Queue
b) Stack
c) Heap
d) Linked list
**Answer: B**
7. What does the binary tree boundary traversal algorithm print after traversing the left subtree and
before printing the leaf nodes?
a) Left boundary
b) Right boundary
c) Root node
**Answer: A**
8. In which order are leaf nodes printed during binary tree boundary traversal?
a) Inorder
b) Postorder
c) Preorder
d) Any order
**Answer: D**
9. Which aspect of the binary tree's structure does boundary traversal emphasize?
**Answer: A**
10. What is the primary benefit of implementing binary tree boundary traversal iteratively?
**Answer: C**
DIAL’S ALGORITHM
1. What is the primary objective of Dial's Algorithm in graph traversal?
**Answer: B**
**Answer: B**
3. What is the primary benefit of Dial's Algorithm in dealing with weighted graphs?
**Answer: B**
4. What is the space complexity of Dial's Algorithm when using an adjacency matrix representation?
a) O(V)
b) O(V log V)
c) O(V^2)
d) O(E)
**Answer: C**
5. When is Dijkstra's Algorithm preferred over other graph algorithms?
d) When finding the shortest path in a weighted graph with non-negative edge weights
**Answer: D**
**Answer: A**
**Answer: B**
**Answer: A**
9. Can Dijkstra's Algorithm handle graphs with negative edge weights?
**Answer: B**
d) When finding the shortest path in a weighted graph with non-negative edge weights
**Answer: D**
BELLMAN-FORD ALGORITHM
1. What problem does the Bellman-Ford algorithm solve?
**Answer: B**
**Answer: C**
3. How does Bellman-Ford detect the presence of a negative weight cycle in a graph?
**Answer: B**
4. What is the space complexity of Bellman-Ford algorithm for the `dist` array?
a) O(V^2)
b) O(V log V)
c) O(E)
d) O(V)
**Answer: D**
5. When is Bellman-Ford algorithm preferred over Dijkstra's algorithm?
**Answer: B**
**Answer: B**
a) O(VE)
b) O(V log V)
c) O(E)
d) O(V)
**Answer: A**
a) Dijkstra's algorithm
b) Prim's algorithm
c) Kruskal's algorithm
d) Bellman-Ford algorithm
**Answer: D**
9. In what type of graphs does Bellman-Ford algorithm work?
**Answer: B**
10. What aspect distinguishes Bellman-Ford from Dijkstra's algorithm in terms of edge weights?
**Answer: B**
TOPOLOGICAL SORT
1. What type of graph is Topological Sorting applicable to?
**Answer: B**
2. Why is Topological Sorting only suitable for Directed Acyclic Graphs (DAGs)?
**Answer: B**
3. In project scheduling, what does it signify if task B comes after task A in the topological order?
**Answer: A**
c) Dijkstra's algorithm
d) Bellman-Ford algorithm
**Answer: B**
5. Can Topological Sorting be applied to graphs with cycles?
**Answer: B**
**Answer: C**
7. In Kahn's algorithm, what data structure is used to store vertices with in-degree 0?
a) Stack
b) Queue
c) Set
d) List
**Answer: B**
c) By comparing the number of visited vertices with the total number of vertices
**Answer: D**
9. What is the significance of in-degree and out-degree in a directed graph?
**Answer: B**
**Answer: D**
HEAP SORT
1. What is the primary data structure used in Heap Sort?
a) Linked list
c) Binary heap
d) Hash table
**Answer: C**
**Answer: D**
3. What is the time complexity of building the initial max-heap in Heap Sort?
a) O(n)
b) O(log n)
c) O(n log n)
d) O(n^2)
**Answer: A**
a) Quick Sort
b) Merge Sort
c) Insertion Sort
d) Heap Sort
**Answer: D**
5. How does Heap Sort differ from Merge Sort in terms of space complexity?
**Answer: A**
6. What is the main advantage of Heap Sort over other sorting algorithms?
**Answer: B**
7. Which operation is repeated in Heap Sort until the entire array is sorted?
a) Swapping elements
b) Building a min-heap
d) Merging subarrays
**Answer: C**
**Answer: B**
9. What is the space complexity of Heap Sort?
a) O(n)
b) O(log n)
c) O(n log n)
d) O(1)
**Answer: D**
**Answer: B**
BINOMIAL HEAP
1. What is the primary focus of a Binomial Heap?
**Answer: B**
a) Linked list
d) Hash table
**Answer: C**
a) Insertion
b) Union
c) Deletion
d) Extraction
**Answer: B**
**Answer: B**
5. How does the decreaseKey operation work in a Binomial Heap?
b) Compares the decreased key with its parent and swaps keys if necessary
**Answer: B**
b) AVL property
d) Red-Black property
**Answer: C**
a) getMin
b) union
c) insert
d) decreaseKey
**Answer: C**
a) They can have multiple binomial trees with the same degree
**Answer: D**
9. What is the main advantage of Binomial Heaps over Binary Heaps?
**Answer: C**
a) Merging two heaps into one while ensuring only one tree with each degree exists
**Answer: A**
STACK PERMUTATION
1. What is a K-ary Heap?
**Answer: D**
**Answer: B**
**Answer: B**
**Answer: C**
5. How are the children of a node represented in a K-ary Heap array?
b) At indices (i + 1) and (i + 2)
**Answer: D**
6. What operation is used to restore the heap property after inserting a new element?
a) heapify-up
b) heapify-down
c) swap
d) delete
**Answer: A**
7. Which type of K-ary Heap ensures that the key at the root is the smallest among all descendants?
c) Binary Heap
d) Balanced Heap
**Answer: B**
8. In a K-ary Heap, what is the index of the last non-leaf node in a heap of size n?
a) (n - 1) / K
b) (n - 2) / K
c) (n - 1) / 2
d) (n - 2) / 2
**Answer: B**
9. How is the insertion operation typically implemented in a K-ary Heap?
c) By adding the new element at the end of the array and then performing heapify-up
d) By adding the new element at the beginning of the array and then performing heapify-down
**Answer: C**
10. What is the primary advantage of a Min K-ary Heap over a Max K-ary Heap?
**Answer: D**
WINNER TREE
1. What is a characteristic feature of a tournament tree?
**Answer: B**
a) Binary tree
b) Selection tree
c) AVL tree
d) Trie
**Answer: B**
**Answer: C**
4. What is the primary difference between a winner tree and a loser tree?
a) Winner trees store the maximum value, while loser trees store the minimum.
b) Winner trees store the minimum value, while loser trees store the maximum.
**Answer: A**
5. How many internal nodes does a tournament tree with 8 players have?
a) 7
b) 8
c) 15
d) 16
**Answer: A**
6. Which type of tournament tree is formed first before creating a loser tree?
a) Max tree
b) Min tree
c) Winner tree
d) Binary tree
**Answer: C**
c) Loser trees only need to examine nodes along the path from leaf nodes to the root for
restructuring
**Answer: C**
**Answer: C**
9. What is the time complexity to initialize a loser tree with n nodes?
a) O(log n)
b) O(n)
c) O(n log n)
d) O(n^2)
**Answer: B**
**Answer: C**