Q. In a depth-first search, what happens when a node is visited?
-
A.
It is added to the queue.
-
B.
It is marked as visited and all its adjacent nodes are explored.
-
C.
It is removed from the graph.
-
D.
It is added to the stack.
Solution
In DFS, when a node is visited, it is marked as visited and all its adjacent nodes are explored.
Correct Answer:
B
— It is marked as visited and all its adjacent nodes are explored.
Learn More →
Q. In which scenario is BFS preferred over DFS?
-
A.
When the graph is very deep and solutions are rare.
-
B.
When you need to find the shortest path in an unweighted graph.
-
C.
When memory usage is a concern.
-
D.
When the graph is sparse.
Solution
BFS is preferred when you need to find the shortest path in an unweighted graph.
Correct Answer:
B
— When you need to find the shortest path in an unweighted graph.
Learn More →
Q. What is a common application of DFS?
-
A.
Finding the shortest path in a weighted graph.
-
B.
Topological sorting of a directed acyclic graph.
-
C.
Finding the minimum spanning tree.
-
D.
Finding connected components in a graph.
Solution
DFS is commonly used for topological sorting of a directed acyclic graph.
Correct Answer:
B
— Topological sorting of a directed acyclic graph.
Learn More →
Q. What is a disadvantage of using DFS compared to BFS?
-
A.
DFS uses more memory than BFS.
-
B.
DFS may not find the shortest path.
-
C.
DFS is slower than BFS.
-
D.
DFS cannot be implemented using recursion.
Solution
A disadvantage of DFS is that it may not find the shortest path in an unweighted graph.
Correct Answer:
B
— DFS may not find the shortest path.
Learn More →
Q. What is the primary difference between BFS and DFS in graph traversal?
-
A.
BFS uses a stack, while DFS uses a queue.
-
B.
BFS explores all neighbors at the present depth before moving on, while DFS explores as far as possible along a branch.
-
C.
BFS is faster than DFS in all cases.
-
D.
DFS is used for finding the shortest path, while BFS is not.
Solution
BFS explores all neighbors at the present depth before moving on, while DFS explores as far as possible along a branch.
Correct Answer:
B
— BFS explores all neighbors at the present depth before moving on, while DFS explores as far as possible along a branch.
Learn More →
Q. Which algorithm is typically used for finding connected components in a graph?
-
A.
Dijkstra's Algorithm
-
B.
Prim's Algorithm
-
C.
BFS or DFS
-
D.
Kruskal's Algorithm
Solution
BFS or DFS is typically used for finding connected components in a graph.
Correct Answer:
C
— BFS or DFS
Learn More →
Q. Which data structure is used to implement BFS?
-
A.
Stack
-
B.
Queue
-
C.
Linked List
-
D.
Array
Solution
BFS is implemented using a queue to keep track of the nodes to be explored.
Correct Answer:
B
— Queue
Learn More →
Q. Which of the following statements about BFS is true?
-
A.
BFS can be implemented recursively.
-
B.
BFS is not suitable for large graphs.
-
C.
BFS guarantees the shortest path in weighted graphs.
-
D.
BFS explores nodes level by level.
Solution
BFS explores nodes level by level, ensuring that all nodes at the present depth are explored before moving deeper.
Correct Answer:
D
— BFS explores nodes level by level.
Learn More →
Q. Which traversal method would you use to check if a graph is bipartite?
-
A.
DFS
-
B.
BFS
-
C.
Both DFS and BFS
-
D.
Neither DFS nor BFS
Solution
BFS is commonly used to check if a graph is bipartite by coloring the graph using two colors.
Correct Answer:
B
— BFS
Learn More →
Showing 1 to 9 of 9 (1 Pages)