Q. In a binary tree, which traversal method is most similar to DFS?
A.
Level-order traversal
B.
In-order traversal
C.
Breadth-first traversal
D.
Random traversal
Show solution
Solution
In-order traversal is a type of DFS as it explores the left subtree, then the node, and finally the right subtree.
Correct Answer:
B
— In-order traversal
Learn More →
Q. In which scenario would Depth-First Search (DFS) be preferred over Breadth-First Search (BFS)?
A.
Finding the shortest path
B.
Exploring all nodes in a level
C.
When memory is limited
D.
Finding connected components
Show solution
Solution
DFS is more memory efficient than BFS in scenarios where the graph is deep and narrow, as it uses a stack instead of a queue.
Correct Answer:
C
— When memory is limited
Learn More →
Q. What is a common application of BFS in real-world scenarios?
A.
Topological sorting
B.
Finding connected components
C.
Web crawling
D.
Cycle detection
Show solution
Solution
BFS is commonly used in web crawling to explore all links at the current depth before moving deeper.
Correct Answer:
C
— Web crawling
Learn More →
Q. What is the main disadvantage of using BFS compared to DFS?
A.
Higher memory usage
B.
Slower execution
C.
More complex implementation
D.
Less effective for deep graphs
Show solution
Solution
BFS typically requires more memory than DFS because it stores all nodes at the current level in a queue.
Correct Answer:
A
— Higher memory usage
Learn More →
Q. Which algorithm can be used to detect cycles in a directed graph?
A.
BFS
B.
DFS
C.
Dijkstra's Algorithm
D.
Prim's Algorithm
Show solution
Solution
DFS can be used to detect cycles in a directed graph by keeping track of visited nodes and the recursion stack.
Correct Answer:
B
— DFS
Learn More →
Q. Which of the following is NOT a characteristic of Depth-First Search?
A.
Uses a stack
B.
Can be implemented recursively
C.
Finds the shortest path
D.
Explores as far as possible along each branch
Show solution
Solution
DFS does not guarantee the shortest path; it explores as far as possible along each branch before backtracking.
Correct Answer:
C
— Finds the shortest path
Learn More →
Q. Which of the following statements about BFS and DFS is true?
A.
BFS is always faster than DFS
B.
DFS can be more memory efficient than BFS
C.
BFS can be used for topological sorting
D.
DFS is used for finding the shortest path
Show solution
Solution
DFS can be more memory efficient than BFS in certain scenarios, especially in deep graphs.
Correct Answer:
B
— DFS can be more memory efficient than BFS
Learn More →
Q. Which traversal method is typically used 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 used 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 8 of 8 (1 Pages)