Q. In Depth-First Search (DFS), which data structure is primarily used?
A.
Queue
B.
Stack
C.
Array
D.
Hash Table
Show solution
Solution
DFS uses a stack to keep track of the nodes to be explored, either explicitly or through recursion.
Correct Answer:
B
— Stack
Learn More →
Q. In which scenario would you prefer DFS over BFS?
A.
Finding the shortest path
B.
Exploring all possible paths
C.
Finding the minimum spanning tree
D.
Finding connected components
Show solution
Solution
DFS is preferred when exploring all possible paths, such as in puzzles or games where all solutions need to be considered.
Correct Answer:
B
— Exploring all possible paths
Learn More →
Q. What is a common application of BFS?
A.
Topological Sorting
B.
Cycle Detection
C.
Finding Connected Components
D.
Finding Shortest Path in Weighted Graphs
Show solution
Solution
BFS is commonly used to find connected components in an unweighted graph.
Correct Answer:
C
— Finding Connected Components
Learn More →
Q. What is the primary data structure used in Breadth-First Search (BFS)?
A.
Stack
B.
Queue
C.
Array
D.
Linked List
Show solution
Solution
BFS uses a queue to keep track of the nodes that need to be explored next.
Correct Answer:
B
— Queue
Learn More →
Q. Which of the following statements is true about DFS?
A.
It can be implemented using a queue.
B.
It is not suitable for finding shortest paths.
C.
It always uses less memory than BFS.
D.
It visits nodes in level order.
Show solution
Solution
DFS is not suitable for finding shortest paths in unweighted graphs as it does not explore all neighbors at the current depth before going deeper.
Correct Answer:
B
— It is not suitable for finding shortest paths.
Learn More →
Q. Which traversal method can be more memory efficient in sparse graphs?
A.
BFS
B.
DFS
C.
Both are equal
D.
Neither is efficient
Show solution
Solution
DFS can be more memory efficient in sparse graphs because it does not need to store all the nodes at the current level, unlike BFS.
Correct Answer:
B
— DFS
Learn More →
Q. Which traversal method is guaranteed to find the shortest path in an unweighted graph?
A.
Depth-First Search
B.
Breadth-First Search
C.
Dijkstra's Algorithm
D.
A* Search
Show solution
Solution
BFS is guaranteed to find the shortest path in an unweighted graph because it explores all neighbors at the present depth prior to moving on to nodes at the next depth level.
Correct Answer:
B
— Breadth-First Search
Learn More →
Showing 1 to 7 of 7 (1 Pages)