Names of Graph Traversal Algorithms
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Graph traversal algorithms are methods for visiting vertices and edges in a controlled order. They are foundational in search, connectivity analysis, shortest-path problems, dependency processing, and many interview questions. The two core traversal families are depth-first search and breadth-first search, but several named algorithms build on those ideas for different goals.
The Two Basic Traversals
The two names every programmer should know are:
- Depth-First Search, usually shortened to DFS.
- Breadth-First Search, usually shortened to BFS.
These are true traversal algorithms in the direct sense of “visit the graph.”
Depth-First Search
DFS explores one branch as deeply as possible before backtracking. It can be implemented recursively or with an explicit stack.
DFS is useful for:
- Topological-style explorations.
- Connected-component searches.
- Cycle detection.
- Backtracking problems.
Breadth-First Search
BFS explores the graph level by level using a queue.
BFS is especially useful for:
- Shortest path in unweighted graphs.
- Layered exploration.
- Reachability with minimum edge count.
Other Commonly Named Traversal-Related Algorithms
People often ask for “names of graph traversal algorithms” and receive a broader list that includes algorithms based on traversal rather than pure traversal primitives.
Common names include:
- DFS
- BFS
- Iterative Deepening DFS
- Dijkstra’s algorithm
- A star search
- Topological sort
Strictly speaking, Dijkstra and A star are shortest-path search algorithms, not just raw traversals. They still belong in the conversation because they visit graph nodes systematically.
Iterative Deepening DFS
Iterative deepening repeats DFS with increasing depth limits. It combines DFS-like memory usage with BFS-like shallow-solution discovery in some search spaces.
This is common in game search and puzzle search discussions.
Traversal Choice Depends on the Problem
Use DFS when:
- You need backtracking.
- You want a memory-light traversal on deep structures.
- You are checking connectivity, cycles, or components.
Use BFS when:
- You need the shortest unweighted path.
- Level order matters.
- Distance by edge count matters.
Do not choose an algorithm by name alone; choose it by the property you need from the visit order.
Directed Versus Undirected Graphs
The same traversal names apply to both directed and undirected graphs, but interpretation changes slightly:
- In directed graphs, edges have one-way reachability.
- In undirected graphs, traversal explores mutual connections.
For DFS and BFS, visited-node tracking is essential in both cases to avoid infinite revisits on cyclic graphs.
Common Pitfalls
- Treating Dijkstra or A star as the same thing as BFS or DFS. Fix by separating basic traversals from weighted-search algorithms.
- Forgetting a visited set in cyclic graphs. Fix by marking visited nodes explicitly.
- Using BFS when memory growth will be too large for the frontier. Fix by evaluating graph shape and problem constraints first.
- Using DFS when the goal is the shortest path in an unweighted graph. Fix by choosing BFS for minimum-edge path problems.
- Asking only for algorithm names without defining the task. Fix by mapping the problem requirement to the traversal property you need.
Summary
- The two primary graph traversal algorithms are DFS and BFS.
- DFS explores deeply before backtracking, while BFS explores level by level.
- Iterative deepening, Dijkstra, and A star are often discussed alongside traversal algorithms.
- The right choice depends on whether you need depth, breadth, or shortest-path behavior.
- Graph traversal names are useful only when tied to the problem you are actually solving.

