Q. In Depth-First Search (DFS), which data structure is primarily used to keep track of the vertices to be explored?
-
A.
Queue
-
B.
Stack
-
C.
Array
-
D.
Linked List
Solution
DFS uses a stack (either explicitly or via recursion) to keep track of the vertices.
Correct Answer:
B
— Stack
Learn More →
Q. What is the primary disadvantage of using DFS compared to BFS?
-
A.
Higher time complexity
-
B.
Can get stuck in deep paths
-
C.
Requires more memory
-
D.
None of the above
Solution
DFS can get stuck in deep paths, potentially missing shorter paths that BFS would find.
Correct Answer:
B
— Can get stuck in deep paths
Learn More →
Q. What is the time complexity of Breadth-First Search (BFS) in a graph with V vertices and E edges?
-
A.
O(V + E)
-
B.
O(V)
-
C.
O(E)
-
D.
O(V * E)
Solution
BFS explores all vertices and edges, leading to a time complexity of O(V + E).
Correct Answer:
A
— O(V + E)
Learn More →
Q. What is the worst-case time complexity for searching an element in a binary search tree (BST) using DFS?
-
A.
O(log V)
-
B.
O(V)
-
C.
O(E)
-
D.
O(V^2)
Solution
In the worst case, a BST can degenerate into a linked list, leading to a time complexity of O(V).
Correct Answer:
B
— O(V)
Learn More →
Q. Which of the following statements is true regarding the time complexity of DFS?
-
A.
O(V + E)
-
B.
O(V^2)
-
C.
O(E log V)
-
D.
O(V log V)
Solution
The time complexity of DFS is O(V + E) as it visits each vertex and edge once.
Correct Answer:
A
— O(V + E)
Learn More →
Q. Which traversal method can be implemented using recursion?
-
A.
BFS
-
B.
DFS
-
C.
Both BFS and DFS
-
D.
Neither BFS nor DFS
Solution
DFS can be easily implemented using recursion, while BFS typically requires an iterative approach.
Correct Answer:
B
— DFS
Learn More →
Q. Which traversal method, BFS or DFS, is more memory efficient in a sparse graph?
-
A.
BFS
-
B.
DFS
-
C.
Both are equal
-
D.
Depends on the implementation
Solution
DFS is generally more memory efficient in sparse graphs as it can explore deeper paths without storing all neighbors.
Correct Answer:
B
— DFS
Learn More →
Showing 1 to 7 of 7 (1 Pages)