MCQ
MCQ
The Bellman-Ford algorithm is used to find the shortest paths from a single source vertex in a
weighted graph. Which of the following is a key feature of this algorithm?
Question 2:
What is the time complexity of the Bellman-Ford algorithm for a graph with V vertices and E
edges?
a) O(V + E)
b) O(V log V)
c) O(E log V)
d) O(V * E)
Answer: d) O(V * E)
Question 3:
How many iterations does the Bellman-Ford algorithm perform to find the shortest paths?
a) V iterations
b) V - 1 iterations
c) E iterations
d) E - 1 iterations
Answer: b) V - 1 iterations
Question 4:
If the Bellman-Ford algorithm detects a negative weight cycle, what does this indicate?
Question 5:
Which of the following scenarios is the Bellman-Ford algorithm best suited for?
c) Graphs with negative edge weights or the possibility of negative weight cycles.
Answer: c) Graphs with negative edge weights or the possibility of negative weight cycles.
Question 1:
What data structure is primarily used in the Breadth-First Search (BFS) algorithm?
a) Stack
b) Queue
c) Priority Queue
d) Linked List
Answer: b) Queue
Question 2:
Which of the following describes the order in which BFS visits nodes in a graph?
a) Depth-first
b) Level-by-level
c) Randomly
d) Inorder
Answer: b) Level-by-level
Question 3:
What is the time complexity of the Breadth-First Search (BFS) algorithm for a graph represented
as an adjacency list?
a) O(V log V)
b) O(E log V)
c) O(V + E)
d) O(V * E)
Answer: c) O(V + E)
Question 4:
If a graph is disconnected and you run BFS from a starting node, what will happen?
a) BFS will visit all nodes in the graph.
b) BFS will only visit the nodes in the connected component of the starting node.
Answer: b) BFS will only visit the nodes in the connected component of the starting node.
Question 5:
MCQ Questions:
Question 1:
b) Linked Lists
c) Binomial Trees
d) Arrays
Question 2:
What is the time complexity of the extractMin() operation in a Binomial Heap?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
Question 3:
How many binomial trees of a specific degree can exist in a Binomial Heap?
a) Any number
b) At most one
c) Exactly two
Question 4:
a) Merge Sort
b) Union
c) Heapify
d) Reverse List
Answer: b) Union
Question 5:
a) 2
b) 3
c) 4
d) 8
Answer: b) 3 (2^3 = 8)
Question 1:
Question 2:
a) Top to bottom
b) Bottom to top
c) Level order
d) Inorder
Answer: b) Bottom to top
Question 3:
Which nodes are excluded from the left and right boundary during a boundary traversal?
a) Root node
b) Leaf nodes
c) Internal nodes
d) All nodes
Question 4:
a) O(log n)
b) O(n)
c) O(n log n)
d) O(n^2)
Answer: b) O(n)
Question 5:
If a left subtree is missing but a right subtree exists, which node is included in the left boundary?
Question 1:
What data structure is implicitly used in the recursive implementation of Depth-First Search
(DFS)?
a) Queue
b) Stack
c) Priority Queue
d) Linked List
Question 2:
Which of the following describes the order in which DFS visits nodes in a graph?
a) Level-by-level
b) Depth-first
c) Randomly
d) Breadth-first
Answer: b) Depth-first
Question 3:
What is the time complexity of the Depth-First Search (DFS) algorithm for a graph represented
as an adjacency list?
a) O(V log V)
b) O(E log V)
c) O(V + E)
d) O(V * E)
Answer: c) O(V + E)
Question 4:
Answer: b) DFS might enter an infinite loop (if not handled properly).
Question 5:
Question 1:
d) Unweighted edges.
Question 2:
What data structure does Dial's Algorithm primarily use to organize vertices based on their
distances?
a) Priority Queue
b) Stack
d) Linked List
Question 3:
a) Bellman-Ford Algorithm
b) Floyd-Warshall Algorithm
c) Dijkstra's Algorithm
Question 4:
The time complexity of Dial's Algorithm depends on:
d) The number of vertices and edges, but not the edge weights.
Question 5:
d) The edge weights are small integers and the graph is dense.
Answer: d) The edge weights are small integers and the graph is dense.
MCQ Questions:
Question 1:
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
Answer: b) O(n log n)
Question 2:
a) Queue
b) Stack
c) Heap
d) Linked List
Answer: c) Heap
Question 3:
Question 4:
a) Min-heap
b) Max-heap
Answer: b) Max-heap
Question 5:
a) O(1) (in-place)
b) O(n)
c) O(log n)
d) O(n log n)
MCQ Questions:
Question 1:
In a K-ary Heap, how many children does each non-leaf node have?
a) 2
b) K
c) Variable
Answer: b) K
Question 2:
b) O(k log n)
c) O(n log k)
d) O(n log n)
Question 3:
a) (i - 1) / 2
b) (i - 1) / K
c) (i + 1) / K
d) i / K
Answer: b) (i - 1) / K
Question 4:
What is the primary advantage of a K-ary Heap compared to a Binary Heap (K=2)?
a) Faster insertion
Question 5:
If a K-ary Heap is used as a priority queue, which operation is typically the most frequently
used?
a) Insert
b) ExtractMin
c) DecreaseKey
d) IncreaseKey
Answer: b) ExtractMin
Question 1:
What is the primary goal of the "Recover Binary Search Tree" problem?
Question 2:
Which traversal method is most commonly used to identify the swapped nodes in a BST?
a) Preorder traversal.
b) Postorder traversal.
c) Inorder traversal.
If an inorder traversal of a BST results in the sequence [1, 5, 3, 4, 2, 6], which two nodes were
swapped?
a) 1 and 2.
b) 3 and 2.
c) 5 and 4.
d) 5 and 2.
Answer: d) 5 and 2.
Question 4:
What is the time complexity of the most efficient solution to recover a BST?
a) O(n^2).
b) O(log n).
c) O(n).
Answer: c) O(n).
Question 5:
In the "Recover BST" problem, what indicates that two nodes are swapped in an inorder
traversal?
Question 1:
a) Undirected graphs
d) Weighted graphs
Question 2:
c) To order vertices such that for every directed edge (u, v), vertex u comes before vertex v.
Answer: c) To order vertices such that for every directed edge (u, v), vertex u comes before vertex
v.
Question 3:
Which data structure is typically used in Kahn's algorithm for topological sort?
a) Stack
b) Queue
c) Priority Queue
d) Linked List
Answer: b) Queue
Question 4:
If a directed graph contains a cycle, what will happen when attempting to perform a topological
sort?
b) The algorithm will terminate normally but not produce a valid topological order.
c) The algorithm will detect the cycle and return an error or null.
Answer: c) The algorithm will detect the cycle and return an error or null.
Question 5:
What is the time complexity of Kahn's algorithm for topological sort, given a graph with V
vertices and E edges?
a) O(V + E)
b) O(V log V)
c) O(E log V)
d) O(V * E)
Answer: a) O(V + E)
Question 1:
What data structure is used to store nodes based on their horizontal distance during vertical
order traversal?
a) ArrayList
b) HashMap
c) TreeMap
d) HashSet
Question 2:
Which traversal method is used as the basis for vertical order traversal?
a) Preorder traversal
b) Inorder traversal
d) Postorder traversal
Question 3:
What does the horizontal distance (HD) represent in the context of vertical order traversal?
c) The position of the node relative to the root in the horizontal direction
Answer: c) The position of the node relative to the root in the horizontal direction
Question 4:
What is the time complexity of the vertical order traversal algorithm?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
Question 5:
If two nodes have the same horizontal distance, how are they ordered in the vertical order
traversal output?
MCQ Questions:
Question 1:
Which traversal method is used as the basis for the left and right view algorithms?
a) Preorder traversal
b) Inorder traversal
d) Postorder traversal
Answer: c) Level order traversal (BFS)
Question 2:
What is the primary data structure used in the BFS-based tree view algorithms?
a) Stack
b) Queue
c) Priority Queue
d) Linked List
Answer: b) Queue
Question 3:
In the top view algorithm, what data structure is used to maintain the horizontal distances?
a) ArrayList
b) HashSet
c) TreeMap
d) HashMap
Answer: c) TreeMap
Question 4:
Which node is added to the result in the left view algorithm during each level traversal?
Question 5:
What is the primary purpose of the Pair class used in the top view algorithm?
MCQ Questions:
Question 1:
a) Sorting an array
Question 2:
b) Heap
d) Graph
Question 3:
Question 4:
a) O(n)
b) O(log n)
c) O(n^2)
d) O(1)
Answer: b) O(log n)
Question 5:
When an element in the input array is updated, how is the Winner Tree updated?
c) The path from the updated leaf node to the root is updated.
Answer: c) The path from the updated leaf node to the root is updated.