Command Palette

Search for a command to run...

Lesson 20.4 · Graph Fundamentals

Which Graph Algorithm?

The question decides the algorithm: reachability, fewest steps, ordering, grouping, cheapest path or cheapest network.

8 min

Think of it like this

A toolbox where each tool has a label: you don't need to remember how every tool works to pick the right one, only what job it does.

1.A quick map

Can I reach it / how many groups? DFS or BFS (Modules 21–22), or union-find (Module 25) when edges arrive over time.

Fewest steps, unweighted? BFS (Module 21). Cheapest path, non-negative weights? Dijkstra (Module 26). Negative weights? Bellman-Ford.

Is there a cycle? In what order can tasks run? Cycle detection and topological sort (Modules 23–24).

Connect everything at minimum total cost? Minimum spanning tree (Module 27).

Rendering diagram…

Remember

  • Name the question first, then pick the tool.

Common mistakes

  • Using Dijkstra on an unweighted graph where BFS is simpler and faster.
  • Using BFS on weighted graphs.