Q. If a graph has a cycle, which traversal method can detect it?
-
A.
Only BFS
-
B.
Only DFS
-
C.
Both BFS and DFS
-
D.
Neither BFS nor DFS
Solution
DFS can detect cycles in a graph by keeping track of visited nodes and checking for back edges.
Correct Answer:
B
— Only DFS
Learn More →
Q. In DFS, what is the maximum depth of recursion for a graph with V vertices?
-
A.
O(V)
-
B.
O(E)
-
C.
O(V + E)
-
D.
O(log V)
Solution
The maximum depth of recursion in DFS can go up to O(V) in the worst case, where V is the number of vertices.
Correct Answer:
A
— O(V)
Learn More →
Q. In which scenario would DFS be preferred over BFS?
-
A.
Finding the shortest path
-
B.
Exploring all nodes
-
C.
When memory is limited
-
D.
When the graph is dense
Solution
DFS is preferred when memory is limited, as it can use less space than BFS in certain cases.
Correct Answer:
C
— When memory is limited
Learn More →
Q. What is the space complexity of BFS using an adjacency list representation?
-
A.
O(V)
-
B.
O(E)
-
C.
O(V + E)
-
D.
O(1)
Solution
BFS requires space for the queue and visited list, leading to a space complexity of O(V) for the vertices.
Correct Answer:
A
— O(V)
Learn More →
Q. What is the space complexity of DFS using a recursive approach?
-
A.
O(V)
-
B.
O(E)
-
C.
O(V + E)
-
D.
O(1)
Solution
The space complexity of DFS using recursion is O(V) due to the call stack used for recursion.
Correct Answer:
A
— O(V)
Learn More →
Q. What is the worst-case time complexity of DFS for a graph represented as an adjacency matrix?
-
A.
O(V)
-
B.
O(E)
-
C.
O(V^2)
-
D.
O(V + E)
Solution
In the worst case, DFS will check all entries in the adjacency matrix, leading to a time complexity of O(V^2).
Correct Answer:
C
— O(V^2)
Learn More →
Q. Which traversal method is generally faster for large graphs?
-
A.
BFS
-
B.
DFS
-
C.
Both are equal
-
D.
Depends on the graph structure
Solution
The speed of BFS or DFS can depend on the graph structure; for some graphs, one may be faster than the other.
Correct Answer:
D
— Depends on the graph structure
Learn More →
Q. Which traversal method is more memory efficient for a sparse graph?
-
A.
BFS
-
B.
DFS
-
C.
Both are equal
-
D.
Neither
Solution
DFS can be more memory efficient than BFS for sparse graphs because it uses a stack (or recursion) instead of a queue, which can grow larger in BFS.
Correct Answer:
B
— DFS
Learn More →
Showing 1 to 8 of 8 (1 Pages)