Q. In a graph, if you want to check for cycles, which traversal method is more suitable?
-
A.
BFS
-
B.
DFS
-
C.
Both are equally suitable
-
D.
Neither can check for cycles
Solution
DFS is more suitable for cycle detection as it can track back edges effectively.
Correct Answer:
B
— DFS
Learn More →
Q. In which scenario is DFS preferred over BFS?
-
A.
Finding the shortest path
-
B.
Exploring all possible paths
-
C.
Finding connected components
-
D.
Finding the minimum spanning tree
Solution
DFS is preferred for exploring all possible paths, especially in scenarios like backtracking.
Correct Answer:
B
— Exploring all possible paths
Learn More →
Q. What is the main disadvantage of DFS compared to BFS?
-
A.
Higher memory usage
-
B.
Can get stuck in deep paths
-
C.
Slower execution time
-
D.
Does not find all paths
Solution
DFS can get stuck in deep paths, leading to inefficient exploration in some cases.
Correct Answer:
B
— Can get stuck in deep paths
Learn More →
Q. What is the primary application of BFS in real-world scenarios?
-
A.
Web crawling
-
B.
Pathfinding in games
-
C.
Network broadcasting
-
D.
Data serialization
Solution
BFS is commonly used in network broadcasting to explore all nodes at the current level before moving deeper.
Correct Answer:
C
— Network broadcasting
Learn More →
Q. Which of the following is a characteristic of BFS?
-
A.
Uses a stack
-
B.
Uses a queue
-
C.
Can find the longest path
-
D.
Is recursive by nature
Solution
BFS uses a queue to explore nodes level by level.
Correct Answer:
B
— Uses a queue
Learn More →
Q. Which of the following problems can be solved using DFS?
-
A.
Finding a path in a maze
-
B.
Finding the shortest path in a weighted graph
-
C.
Topological sorting
-
D.
All of the above
Solution
DFS can be used for finding paths in a maze and topological sorting, but not for finding the shortest path in a weighted graph.
Correct Answer:
C
— Topological sorting
Learn More →
Q. Which of the following statements about DFS is true?
-
A.
It can be implemented using a queue
-
B.
It is not suitable for large graphs
-
C.
It can be implemented using recursion
-
D.
It always finds the shortest path
Solution
DFS can be implemented using recursion, which is a common approach in many algorithms.
Correct Answer:
C
— It can be implemented using recursion
Learn More →
Showing 1 to 7 of 7 (1 Pages)