Graphs Beyond Traversal

Lesson, slides, and applied problem sets.

View Slides

Lesson

Graph Algorithms Beyond Traversal

Why this module exists

BFS/DFS is table stakes. Real graph interviews often need MSTs, SCCs, and bipartite matching. These are foundational for networking, compilers, and scheduling.


Minimum Spanning Tree (MST)

For a connected, weighted, undirected graph, an MST connects all nodes with minimum total weight.

Two standard algorithms:

  • Kruskal: sort edges, union if they connect two components
  • Prim: grow a tree using a min-heap over edges

Kruskal is great when you already have edges; Prim is natural for dense graphs.


Strongly Connected Components (SCC)

In a directed graph, an SCC is a maximal set of nodes where each reaches every other.

Kosaraju (2-pass):

  1. DFS on original graph to get finish order
  2. DFS on reversed graph in that order

Tarjan does it in one pass using low-link values.


Bipartite Matching

A bipartite graph has left and right partitions. A matching is a set of edges with no shared endpoints.

Key idea: augmenting paths. Each augment increases matching size by 1.

Hopcroft-Karp uses BFS + DFS layers for O(E sqrt V).


What you will build

  • MST total weight with Kruskal.
  • Count SCCs with Kosaraju.
  • Maximum bipartite matching.

Module Items

  • Minimum Spanning Tree Total Weight

    Compute the total weight of a minimum spanning tree.

    medium Sign in to access medium and hard problems
  • Strongly Connected Components Count

    Count SCCs in a directed graph.

    medium Sign in to access medium and hard problems
  • Maximum Bipartite Matching

    Compute the size of a maximum bipartite matching.

    hard Upgrade to Pro to access hard problems
  • Graphs Beyond Traversal Checkpoint

    MSTs, SCCs, and bipartite matching.

    Quiz
Join Discord