You are on page 1of 33

RECOVER THE BST:

1. What is the primary goal of recovering a Binary Search Tree (BST) in an interview context?

a) To demonstrate proficiency in recursion

b) To showcase knowledge of graph theory

c) To exhibit understanding of algorithms and data structures

d) To illustrate expertise in machine learning

**Answer: C**

2. In what scenario would a BST typically need to be recovered?

a) When all nodes in the tree have identical values

b) When the BST is perfectly balanced

c) When two nodes in the BST are swapped or have incorrect values

d) When the BST contains only one node

**Answer: C**

3. Which of the following is NOT a primary approach for recovering a corrupted BST?

a) Inorder Traversal with Two-Pointer Approach

b) Morris Traversal

c) Preorder Traversal

d) None of the above

**Answer: C**

4. What is the purpose of Morris Traversal in the context of recovering a BST?

a) To traverse the tree in reverse order

b) To identify incorrectly placed nodes during traversal

c) To perform an efficient recovery with constant space usage

d) To reconstruct the BST from scratch

**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?

a) Inorder Traversal with Two-Pointer Approach

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

c) In a complete binary tree

d) In a tree with only one node

**Answer: B**

10. Which method is generally preferred when memory constraints are important in recovering a
corrupted BST?

a) Inorder Traversal with Two-Pointer Approach

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?

a) To sort the vertices in ascending order

b) To detect cycles within the structure

c) To mark each vertex as visited while avoiding cycles

d) To search all the vertices in a systematic manner

**Answer: D**

2. In BFS, how are vertices categorized during traversal?

a) Explored and Unexplored

b) Visited and Unvisited

c) Processed and Unprocessed

d) Checked and Unchecked

**Answer: B**

3. Which data structure is typically used to implement BFS?

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?

a) Finding the shortest path between two vertices

b) Detecting cycles within the graph

c) Producing the minimum spanning tree

d) Scheduling jobs based on dependencies among tasks

**Answer: B**
5. How does DFS traversal differ from BFS traversal in terms of the data structure used?

a) DFS uses a queue, while BFS uses a stack

b) DFS uses a stack, while BFS uses a queue

c) Both DFS and BFS use the same data structure

d) DFS uses a priority queue, while BFS uses a regular queue

**Answer: B**

6. Which algorithm is typically used to compute the maximum flow in a flow network?

a) Breadth First Traversal

b) Depth First Search

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?

a) Marking all adjacent nodes as visited

b) Removing the vertex from the stack

c) Creating a list of adjacent nodes for the visited vertex

d) Adding adjacent nodes to the top of the stack

**Answer: D**

8. Which traversal method is primarily used to determine the shortest path in a graph or tree?

a) Depth First Traversal

b) Breadth First Search

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

b) Finding strongly connected components

c) Topological sorting

d) Testing if the graph can be colored with two colors

**Answer: D**

10. Which traversal method is commonly used to find the minimum spanning tree in an unweighted
graph?

a) Depth First Traversal

b) Breadth First Search

c) Dijkstra's algorithm

d) Prim's algorithm

**Answer: A**
VERTICAL ORDER TRAVERSAL
1. What does Vertical Order Traversal of a binary tree involve?

a) Grouping nodes by their horizontal positions

b) Grouping nodes by their vertical positions

c) Sorting nodes based on their depth in the tree

d) Randomly accessing nodes in the tree

**Answer: B**

2. Why is Vertical Order Traversal useful?

a) It helps in sorting nodes alphabetically

b) It organizes nodes in a top-to-bottom manner

c) It prioritizes nodes based on their height in the tree

d) It minimizes the time complexity of tree traversal

**Answer: B**

3. How can Vertical Order Traversal of a binary tree be implemented?

a) Using a stack data structure

b) Using a heap data structure

c) Using a TreeMap to store nodes by their vertical positions

d) Using a linked list to store nodes by their horizontal positions

**Answer: C**

4. What is the time complexity of Vertical Order Traversal?

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?

a) From left to right

b) From right to left

c) Randomly

d) Based on their depth in the tree

**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**

9. What is an example use case for Vertical Order Traversal?

a) Sorting nodes in ascending order of their values

b) Displaying nodes in a multi-column binary tree interface

c) Randomly accessing nodes for search operations

d) Finding the maximum depth of the tree

**Answer: B**

10. What aspect of the binary tree's structure does Vertical Order Traversal emphasize?

a) Nodes' left or right positioning

b) Nodes' parent-child relationships

c) Nodes' horizontal positioning

d) Nodes' vertical positioning

**Answer: D**
BOUNDARY TRAVERSAL
1. What is the primary objective of binary tree boundary traversal?

a) To find the maximum depth of the tree

b) To print all nodes in the tree in ascending order

c) To print the root, left leaves, and right leaves of the tree

d) To determine the total number of nodes in the tree

**Answer: C**

2. What are the main steps involved in binary tree boundary traversal?

a) Traverse left subtree, print leaves, traverse right subtree

b) Traverse root, print left leaves, print right leaves

c) Traverse left boundary, print leaves, traverse right boundary

d) Traverse in pre-order, print all nodes encountered

**Answer: C**

3. What is the time complexity of binary tree boundary traversal?

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?

a) Use a queue to track visited nodes

b) Use a set or hash table to track encountered values

c) Ignore leaf nodes during traversal

d) Traverse the tree in reverse order

**Answer: B**
5. Which factor primarily determines the space complexity of binary tree boundary traversal?

a) The number of nodes in the tree

b) The height of the tree

c) The depth of the tree

d) The breadth of the tree

**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

d) None of the above

**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?

a) Nodes' left or right positioning

b) Nodes' parent-child relationships

c) Nodes' horizontal positioning

d) Nodes' vertical positioning

**Answer: A**

10. What is the primary benefit of implementing binary tree boundary traversal iteratively?

a) It guarantees better time complexity than recursive traversal

b) It reduces the space complexity of the algorithm

c) It avoids issues related to stack overflow

d) It allows for easier implementation in programming languages without recursion support

**Answer: C**
DIAL’S ALGORITHM
1. What is the primary objective of Dial's Algorithm in graph traversal?

a) Finding the longest path between two nodes

b) Finding the shortest path between two nodes

c) Counting the total number of nodes in the graph

d) Sorting nodes based on their degree centrality

**Answer: B**

2. How does Dial's Algorithm improve upon Dijkstra's Algorithm?

a) By using a priority queue for node selection

b) By organizing nodes into buckets based on their distance

c) By exploring nodes in decreasing order of distance

d) By considering all possible paths in the graph

**Answer: B**

3. What is the primary benefit of Dial's Algorithm in dealing with weighted graphs?

a) It guarantees the shortest path between any two nodes

b) It efficiently handles graphs with a limited range of edge weights

c) It eliminates the need for priority queues or sets

d) It reduces the time complexity of graph traversal

**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?

a) When dealing with negative edge weights

b) When exploring nodes in unweighted graphs

c) When finding the longest path in a graph

d) When finding the shortest path in a weighted graph with non-negative edge weights

**Answer: D**

6. What problem does Dijkstra's Algorithm solve?

a) Single-source shortest path problem

b) Multi-source shortest path problem

c) Maximum flow problem

d) Minimum spanning tree problem

**Answer: A**

7. How does Dijkstra's Algorithm update distances during traversal?

a) By always selecting the node with the largest tentative distance

b) By always selecting the node with the smallest tentative distance

c) By randomly selecting nodes to explore

d) By ignoring edge weights

**Answer: B**

8. What distinguishes Dijkstra's Algorithm from BFS (Breadth-First Search)?

a) Dijkstra's considers edge weights; BFS does not

b) BFS considers edge weights; Dijkstra's does not

c) Dijkstra's explores nodes in a random order; BFS does not

d) BFS explores nodes in a weighted graph; Dijkstra's does not

**Answer: A**
9. Can Dijkstra's Algorithm handle graphs with negative edge weights?

a) Yes, it works correctly with negative edge weights

b) No, it does not work correctly with negative edge weights

c) It depends on the implementation of the algorithm

d) Only if the graph is acyclic

**Answer: B**

10. When is Dijkstra's Algorithm particularly useful?

a) When finding the maximum flow in a network

b) When exploring nodes in a random order

c) When dealing with negative edge weights

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?

a) Maximum flow in a network

b) Single-source shortest paths in a weighted, directed graph

c) Minimum spanning tree in an undirected graph

d) Bipartite graph detection

**Answer: B**

2. What distinguishes Bellman-Ford from Dijkstra's algorithm regarding edge weights?

a) Bellman-Ford can handle non-negative edge weights

b) Dijkstra's algorithm can handle negative edge weights

c) Bellman-Ford can handle negative edge weights

d) Dijkstra's algorithm cannot handle non-negative edge weights

**Answer: C**

3. How does Bellman-Ford detect the presence of a negative weight cycle in a graph?

a) By performing a depth-first search

b) By checking the distances after V-1 iterations

c) By using a priority queue

d) By applying BFS traversal

**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?

a) When dealing with non-negative edge weights

b) When negative weights or cycles may be present in the graph

c) When the graph is acyclic

d) When finding the maximum flow in a network

**Answer: B**

6. How does Bellman-Ford algorithm work to find shortest paths?

a) By exploring nodes in a priority queue order

b) By iteratively relaxing estimated shortest distances

c) By using a hash table to store distances

d) By performing DFS traversal

**Answer: B**

7. What is the time complexity of Bellman-Ford algorithm?

a) O(VE)

b) O(V log V)

c) O(E)

d) O(V)

**Answer: A**

8. Which algorithm can detect negative weight cycles in a graph?

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?

a) Undirected graphs with positive edge weights

b) Directed graphs with negative edge weights

c) Undirected graphs with non-negative edge weights

d) Directed graphs with positive edge weights

**Answer: B**

10. What aspect distinguishes Bellman-Ford from Dijkstra's algorithm in terms of edge weights?

a) Dijkstra's algorithm can handle negative edge weights

b) Bellman-Ford can handle negative edge weights

c) Dijkstra's algorithm cannot handle non-negative edge weights

d) Bellman-Ford can handle non-negative edge weights

**Answer: B**
TOPOLOGICAL SORT
1. What type of graph is Topological Sorting applicable to?

a) Directed cyclic graph (DCG)

b) Directed acyclic graph (DAG)

c) Undirected cyclic graph (UCG)

d) Undirected acyclic graph (UAG)

**Answer: B**

2. Why is Topological Sorting only suitable for Directed Acyclic Graphs (DAGs)?

a) DAGs provide a linear ordering of vertices

b) DAGs contain no cycles, ensuring a clear linear order

c) DAGs have a unique vertex arrangement

d) DAGs guarantee optimal pathfinding algorithms

**Answer: B**

3. In project scheduling, what does it signify if task B comes after task A in the topological order?

a) Task B is dependent on Task A

b) Task A is dependent on Task B

c) Task A and Task B are independent

d) Task A and Task B are parallel tasks

**Answer: A**

4. Which algorithm is commonly used for Topological Sorting?

a) Breadth-First Search (BFS)

b) Depth-First Search (DFS)

c) Dijkstra's algorithm

d) Bellman-Ford algorithm

**Answer: B**
5. Can Topological Sorting be applied to graphs with cycles?

a) Yes, it can handle cycles efficiently

b) No, it's specifically designed for acyclic graphs

c) Yes, but with modifications to handle cycles

d) No, it's only suitable for undirected graphs

**Answer: B**

6. What is the primary purpose of Kahn's algorithm?

a) To find the shortest path in a graph

b) To detect cycles in a graph

c) To perform Topological Sorting on a graph

d) To compute the maximum flow in a network

**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**

8. How does Kahn's algorithm determine if a graph is directed and acyclic?

a) By counting the number of vertices

b) By checking if all vertices are visited

c) By comparing the number of visited vertices with the total number of vertices

d) By checking if the "visited" variable equals the number of vertices

**Answer: D**
9. What is the significance of in-degree and out-degree in a directed graph?

a) They determine the shortest path between two vertices

b) They represent the number of edges entering and leaving a vertex

c) They indicate the connectivity of a graph

d) They define the weight of each edge in the graph

**Answer: B**

10. Which of the following statements about Topological Sorting is true?

a) It can be applied to any type of graph, regardless of cycles

b) It provides a random ordering of vertices in a graph

c) It's primarily used for finding the maximum flow in a network

d) It arranges vertices so that each edge points from left to right

**Answer: D**
HEAP SORT
1. What is the primary data structure used in Heap Sort?

a) Linked list

b) Binary search tree

c) Binary heap

d) Hash table

**Answer: C**

2. How does Heap Sort arrange elements during sorting?

a) Elements are compared with every other element

b) Elements are grouped into buckets

c) Elements are moved to the end of the array

d) Elements are extracted from a max-heap

**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**

4. Which of the following sorting algorithms is NOT stable?

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?

a) Heap Sort requires extra memory

b) Merge Sort is an in-place algorithm

c) Both algorithms have the same space complexity

d) Heap Sort is more memory-efficient

**Answer: A**

6. What is the main advantage of Heap Sort over other sorting algorithms?

a) It has a faster average-case time complexity

b) It is not dependent on the initial order of elements

c) It requires less memory than Merge Sort

d) It can handle cyclic graphs efficiently

**Answer: B**

7. Which operation is repeated in Heap Sort until the entire array is sorted?

a) Swapping elements

b) Building a min-heap

c) Extracting the maximum element

d) Merging subarrays

**Answer: C**

8. How does Heap Sort handle elements with equal values?

a) It randomly arranges them

b) It maintains their original order

c) It groups them into separate arrays

d) It ignores elements with equal values

**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**

10. Can Heap Sort be adapted to sort data in descending order?

a) No, Heap Sort only works in ascending order

b) Yes, by using a max-heap instead of a min-heap

c) No, Heap Sort is not capable of sorting

d) Yes, by reversing the order of comparison operations

**Answer: B**
BINOMIAL HEAP
1. What is the primary focus of a Binomial Heap?

a) Sorting elements in ascending order

b) Maintaining a collection of elements with efficient priority queue operations

c) Searching for specific elements in a dataset

d) Storing elements in a balanced binary tree structure

**Answer: B**

2. Which data structure does a Binomial Heap consist of?

a) Linked list

b) Binary search tree

c) Collection of Binomial Trees

d) Hash table

**Answer: C**

3. What operation is used to combine two Binomial Heaps into one?

a) Insertion

b) Union

c) Deletion

d) Extraction

**Answer: B**

4. What is the purpose of the getMin operation in a Binomial Heap?

a) Finding the maximum key in the heap

b) Retrieving the minimum key from the heap

c) Inserting a new key into the heap

d) Deleting a specific key from the heap

**Answer: B**
5. How does the decreaseKey operation work in a Binomial Heap?

a) Increases the key of a specific element

b) Compares the decreased key with its parent and swaps keys if necessary

c) Deletes the minimum key from the heap

d) Combines two binomial trees of the same degree

**Answer: B**

6. What property do all binomial trees in a Binomial Heap follow?

a) Max Heap property

b) AVL property

c) Min Heap property

d) Red-Black property

**Answer: C**

7. What operation is used to insert a new key into a Binomial Heap?

a) getMin

b) union

c) insert

d) decreaseKey

**Answer: C**

8. Which of the following statements is true about Binomial Heaps?

a) They can have multiple binomial trees with the same degree

b) Each binomial tree has exactly one child

c) They are always implemented using linked lists

d) They have better average time complexity compared to Binary Heaps

**Answer: D**
9. What is the main advantage of Binomial Heaps over Binary Heaps?

a) Faster insertion operation

b) More straightforward implementation

c) Faster union and decrease key operations

d) Better space efficiency

**Answer: C**

10. What does a Binomial Heap union operation involve?

a) Merging two heaps into one while ensuring only one tree with each degree exists

b) Separating two heaps into individual trees

c) Finding the minimum key in each heap and combining them

d) Removing all elements with keys greater than a certain threshold

**Answer: A**
STACK PERMUTATION
1. What is a K-ary Heap?

a) A heap with at most 3 children per node

b) A heap with an unlimited number of children per node

c) A heap with at most 2 children per node

d) A heap with at most K children per node

**Answer: D**

2. Which property does a Max K-ary Heap satisfy?

a) The key at the root is less than all descendants

b) The key at the root is greater than all descendants

c) The key at the root is equal to all descendants

d) The key at the root is the average of all descendants

**Answer: B**

3. How is a K-ary Heap different from a Binary Heap?

a) K-ary Heap has a root node with K children

b) K-ary Heap allows for at most K children per node

c) K-ary Heap is implemented using an array

d) K-ary Heap uses a different heapify-up operation

**Answer: B**

4. What is the advantage of using a K-ary Heap over a Binary Heap?

a) K-ary Heaps have a simpler insertion operation

b) K-ary Heaps guarantee a shorter height of the tree

c) K-ary Heaps are more space-efficient in certain situations

d) K-ary Heaps have a faster deletion operation

**Answer: C**
5. How are the children of a node represented in a K-ary Heap array?

a) At indices (2*i) and (2*i + 1)

b) At indices (i + 1) and (i + 2)

c) At indices (3*i + 1) through (3*i + 3)

d) At indices (Ki + 1) through (Ki + K)

**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?

a) Max K-ary Heap

b) Min K-ary Heap

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?

a) By adding the new element as the right child of the root

b) By adding the new element as the left child of the root

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?

a) Faster insertion operation

b) Shorter height of the tree

c) Guarantee of the maximum key at the root

d) Ensuring the minimum key at the root

**Answer: D**
WINNER TREE
1. What is a characteristic feature of a tournament tree?

a) It has an equal number of internal and external nodes

b) Each internal node represents the winner of a competition

c) It has a variable number of children per node

d) The root node always contains the maximum value

**Answer: B**

2. What is another name for a tournament tree?

a) Binary tree

b) Selection tree

c) AVL tree

d) Trie

**Answer: B**

3. In a winner tree, where is the overall winner of the competition stored?

a) At the first leaf node

b) At the last leaf node

c) At the root node

d) At the parent of the root node

**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.

c) Winner trees have more internal nodes than loser trees.

d) Winner trees have fewer leaf nodes than loser trees.

**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**

7. What is one advantage of loser trees over winner trees?

a) Loser trees have a faster initialization time

b) Loser trees require less memory

c) Loser trees only need to examine nodes along the path from leaf nodes to the root for
restructuring

d) Loser trees have a simpler update operation

**Answer: C**

8. How is the winner determined in a winner tree?

a) By comparing the values of all leaf nodes

b) By selecting the leaf node with the highest value

c) By recursively comparing nodes to find the minimum value

d) By selecting the leaf node with the lowest index

**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**

10. In what scenario would a winner tree be particularly useful?

a) Finding the maximum value in a dataset

b) Identifying the worst-performing player in a tournament

c) Ranking participants based on their performance

d) Sorting elements in descending order

**Answer: C**

You might also like