Graph algorithms turn edges into answers about reachability, dependency order, path cost, connectivity, or capacity. The required output comes first. Direction, weight semantics, and input density then narrow the valid choices. Breadth-first search finds a minimum-hop route, while Dijkstra minimizes total weight and becomes invalid as soon as an edge can be negative.

Diagram

flowchart TD
  A[Graph problem] --> B{Need reachability or levels}
  B -->|Yes| C[DFS BFS]
  B -->|No| D{Need minimum path cost}
  D -->|Yes with non negative weights| E{Have a heuristic to the target}
  E -->|Yes| E1[A Star Search]
  E -->|No| E2[Dijkstra]
  D -->|Can have negative edges| F[Bellman Ford]
  D -->|Need all pairs shortest paths| G[Floyd Warshall]
  A --> H{Need structure not distance}
  H -->|Cheapest way to connect every node| I[Minimum Spanning Tree]
  H -->|Mutually reachable groups in a digraph| J[Strongly Connected Components]
  H -->|Single points of failure| K[Articulation Points and Bridges]
  H -->|Clusters in an undirected graph| M[Connected Components]
  H -->|Throughput through a capacitated network| L[Maximum Flow]

Algorithm Selection

Shortest Path

AlgorithmSolvesTimeConstraint
BFSReachability, shortest path by edge countO(V + E)Unweighted graphs
DFSTraversal, cycle detection, finish-order primitivesO(V + E)General graphs. Topological order still requires a DAG
DijkstraSingle-source shortest pathO((V + E) log V)Non-negative weights
A* SearchPoint-to-point shortest pathO((V + E) log E) with a consistent heuristic and lazy heap. Reopenings make runtime re-expansion-dependentNon-negative weights. Consistency permits close-once optimality, while an admissible but inconsistent heuristic requires reopenings
Greedy Best-First SearchFast point-to-point path, not necessarily optimalO((V + E) log E) with a lazy heapHeuristic only. Sacrifices optimality for speed
Bidirectional SearchPoint-to-point shortest pathAbout O(b^(d/2)) rather than O(b^d) in the ideal state-space modelTarget known. Backward search must be available
Bellman-FordSingle-source shortest pathO(V·E)Handles negative edges. Detects reachable negative cycles
Floyd-WarshallAll-pairs shortest pathΘ(V³) time, Θ(V²) spaceSmall or dense graphs. Detects negative cycles

Structure and Connectivity

AlgorithmSolvesTimeConstraint
Minimum Spanning TreeCheapest edge set connecting all verticesO(E log V)Connected, undirected, weighted
Topological SortLinear order respecting dependenciesO(V + E)Directed acyclic graph
Strongly Connected ComponentsMaximal mutually-reachable vertex setsO(V + E)Directed graphs
Connected ComponentsMaximal connected vertex setsO(V + E)Undirected graphs
Articulation Points and BridgesCut vertices and cut edgesO(V + E)Undirected graphs
Maximum FlowMax s–t throughput. Min cutO(V·E²) (Edmonds–Karp)Capacitated network

NOTE

Not every graph problem admits a polynomial-time algorithm. Hamiltonian Cycle asks for a cycle that visits every vertex exactly once and is NP-complete. No polynomial-time algorithm is known. Exact methods take exponential time in the worst case.

References

18 items under this folder.