Prepare for the 241 Computer Science Certification Exam with comprehensive flashcards and multiple choice questions. Enhance knowledge with explanations and hints to excel in your test journey!

Multiple Choice

Name and briefly describe two graph traversal algorithms and their typical use cases.

Depth-first search dives as deep as possible along a branch before backtracking, which makes it ideal for exploring an entire connected component and for tasks that require visiting nodes within a component thoroughly (like detecting cycles or performing a topological sort). Breadth-first search expands outward from the start node level by level, visiting all nodes at distance d before those at distance d+1, so in an unweighted graph it guarantees that the first time a node is reached you’ve found a shortest path from the source. So, use DFS to explore components and BFS to find shortest paths in unweighted graphs.

Depth-first search dives as deep as possible along a branch before backtracking, which makes it ideal for exploring an entire connected component and for tasks that require visiting nodes within a component thoroughly (like detecting cycles or performing a topological sort). Breadth-first search expands outward from the start node level by level, visiting all nodes at distance d before those at distance d+1, so in an unweighted graph it guarantees that the first time a node is reached you’ve found a shortest path from the source. So, use DFS to explore components and BFS to find shortest paths in unweighted graphs.