Q. In which scenario would you prefer BFS over DFS?
A.
When you need to find a path in a weighted graph
B.
When you need to explore all possible paths
C.
When you need the shortest path in an unweighted graph
D.
When memory usage is a concern
Show solution
Solution
BFS is preferred for finding the shortest path in unweighted graphs because it explores all neighbors at the present depth before moving deeper.
Correct Answer:
C
— When you need the shortest path in an unweighted graph
Learn More →
Q. What data structure is typically used to implement BFS?
A.
Stack
B.
Queue
C.
Linked List
D.
Array
Show solution
Solution
BFS uses a queue to keep track of the vertices that need to be explored next, ensuring that vertices are processed in the order they are discovered.
Correct Answer:
B
— Queue
Learn More →
Q. What is a disadvantage of using BFS?
A.
It can be slower than DFS
B.
It requires more memory than DFS
C.
It cannot be used for cyclic graphs
D.
It is not suitable for unweighted graphs
Show solution
Solution
BFS requires more memory than DFS because it stores all nodes at the current level in a queue, which can grow large in wide graphs.
Correct Answer:
B
— It requires more memory than DFS
Learn More →
Q. What is a key characteristic of DFS when applied to a graph?
A.
It can be implemented using recursion
B.
It always finds the shortest path
C.
It uses a queue for traversal
D.
It visits all nodes in a breadth-first manner
Show solution
Solution
DFS can be implemented using recursion, which allows it to explore as far down a branch as possible before backtracking.
Correct Answer:
A
— It can be implemented using recursion
Learn More →
Q. What is the primary purpose of Breadth-First Search (BFS) in graph traversal?
A.
To find the shortest path in a weighted graph
B.
To explore all vertices at the present depth before moving on to vertices at the next depth level
C.
To sort the vertices of the graph
D.
To find a cycle in the graph
Show solution
Solution
BFS explores all vertices at the present depth level before moving on to the next level, making it suitable for finding the shortest path in unweighted graphs.
Correct Answer:
B
— To explore all vertices at the present depth before moving on to vertices at the next depth level
Learn More →
Q. Which of the following is a common application of Depth-First Search (DFS)?
A.
Finding the shortest path in a graph
B.
Topological sorting of a directed acyclic graph
C.
Finding the minimum spanning tree
D.
Checking for bipartiteness in a graph
Show solution
Solution
DFS is commonly used for topological sorting in directed acyclic graphs, as it can explore all vertices and edges in a depth-first manner.
Correct Answer:
B
— Topological sorting of a directed acyclic graph
Learn More →
Q. Which of the following problems can be solved using BFS?
A.
Finding connected components in a graph
B.
Finding the longest path in a graph
C.
Finding the minimum spanning tree
D.
Finding the maximum flow in a flow network
Show solution
Solution
BFS can be used to find connected components in an unweighted graph by exploring all reachable vertices from a starting vertex.
Correct Answer:
A
— Finding connected components in a graph
Learn More →
Q. Which traversal method is better for finding all paths between two nodes in a graph?
A.
BFS
B.
DFS
C.
Both are equally good
D.
Neither can find all paths
Show solution
Solution
DFS is better for finding all paths between two nodes because it explores all possible paths until it reaches the destination.
Correct Answer:
B
— DFS
Learn More →
Q. Which traversal method is more memory efficient for deep graphs?
A.
BFS
B.
DFS
C.
Both are equally efficient
D.
Neither is efficient
Show solution
Solution
DFS can be more memory efficient for deep graphs because it only needs to store the current path from the root to the leaf, while BFS stores all nodes at the current level.
Correct Answer:
B
— DFS
Learn More →
Showing 1 to 9 of 9 (1 Pages)