Skip to main content

Module 3: Graph Algorithms & Network Analysis

Primary text: The Algorithm Design Manual (Skiena) for problem-driven framing
Selective support: Introduction to Algorithms (CLRS) for proofs and depth, Algorithms (Sedgewick) for visual intuition and implementation, Competitive Programming for applied variants, Grokking Algorithms for entry-level reminders

This guide is the primary teacher. You do not need to read the source books front-to-back to complete this module. You do need to become operationally strong at choosing a graph model, picking the right traversal or shortest-path algorithm, and defending each choice with a running-time and correctness argument.


Scope of This Module

This module is not a tour of clever graph tricks. It is where you learn to turn informal "nodes and edges" talk into a precise graph problem, choose an algorithm whose preconditions actually match, and argue for correctness.

What it covers in depth:

  • graphs as mathematical objects (directed/undirected, weighted, simple/multi) and the problem-recognition step
  • adjacency-list and adjacency-matrix representations and their operational tradeoffs
  • BFS as a layered traversal and as the algorithm for unweighted shortest paths
  • DFS, discovery/finish times, and the tree/back/forward/cross edge classification
  • connected and strongly connected components, and DAG-based algorithms via topological sort
  • single-source shortest paths via Dijkstra and Bellman-Ford, all-pairs shortest paths via Floyd-Warshall
  • minimum spanning trees through the cut and cycle properties, realized by Kruskal and Prim
  • maximum flow, the Ford-Fulkerson method, max-flow min-cut duality, and bipartite matching as a flow instance

What it deliberately does not try to finish here:

  • planarity algorithms, graph minors, or graph coloring theory beyond recognition
  • advanced flow algorithms in full (Dinic, push-relabel) beyond conceptual overview
  • approximation algorithms for NP-hard graph problems (that is Semester 4 territory)
  • large-scale graph systems, distributed graph processing, and graph databases

If you can code BFS and Dijkstra but cannot say which shortest-path problem variant you are solving or why, the module is not complete.


Before You Start

Answer these closed-book before starting the main path:

  1. What is the difference between a path, a walk, and a cycle in a graph?
  2. Why do we distinguish directed from undirected edges when talking about reachability?
  3. When you implement BFS from Semester 0 instincts, what data structure holds the frontier and why?
  4. Why does Dijkstra fail on graphs with negative edge weights?
  5. What is the abstract role of a priority queue in the algorithms you already know?

Diagnostic Interpretation

4-5 solid answers

  • You are ready for the full path.

2-3 solid answers

  • Continue, but expect extra time in the traversal and shortest-path clusters.

0-1 solid answers

  • Revisit Module 2 priority queues and Semester 0 queue/stack material first. Graph algorithms reuse those structures heavily.

What This Module Is For

Graphs are the dominant modeling abstraction in computer science. Later work repeatedly asks questions like:

  • which components or services depend on which, and in what order should they be built?
  • what is the cheapest route in a road, compute, or network graph?
  • which users are connected, and how densely?
  • where is the bottleneck in a network, and how much traffic can it carry?
  • which pairs should be matched (tasks to workers, ads to slots, residents to hospitals)?

This module builds the graph reasoning needed for:

  • compilers and build systems (dependency ordering, SCCs, DAG scheduling)
  • routing, networking, and distributed systems (shortest paths, spanning structures, cuts)
  • data-heavy engineering (recommendation, social graphs, knowledge graphs)
  • optimization and operations research (matching, assignment, flow)
  • algorithm interviews and competitive programming fluency

You are learning to see the graph hiding inside an informally stated problem.


Concept Map


How To Use This Module

Work in order. Representations and traversals underlie every later algorithm; skipping them makes the weighted and flow material feel arbitrary.

Cluster 1: Graph Models and Representations

OrderConceptTypeFocus
1What a Graph IsPRIMARYVertices, edges, directed vs undirected, weighted, simple vs multi
2Adjacency List vs Adjacency MatrixPRIMARYSpace/time tradeoffs that govern later algorithm choices
3Representing Special GraphsSUPPORTINGDAGs, trees, bipartite, and planar as modeling vocabulary
4Graph Problem RecognitionPRIMARYTurning real problems into a precise graph instance

Cluster mastery check: Can you state the graph (vertices, edges, directedness, weights) before naming any algorithm?

Cluster 2: Graph Traversals

OrderConceptTypeFocus
5BFS and Unweighted Shortest PathsPRIMARYLevel-by-level exploration and why BFS yields hop-count shortest paths
6DFS and the Edge TaxonomyPRIMARYDiscovery/finish times and tree/back/forward/cross edges
7Connected and Strongly Connected ComponentsPRIMARYKosaraju and Tarjan strategies for SCCs
8Topological Sort and DAG AlgorithmsPRIMARYLinear orderings and DAG-based shortest and longest paths

Cluster mastery check: Can you predict the BFS and DFS trees on a small graph before running them, and explain what each edge type would look like?

Cluster 3: Shortest Paths

OrderConceptTypeFocus
9Shortest Path Problem VariantsPRIMARYSingle-source, all-pairs, single-pair, and negative-edge cases
10Dijkstra's AlgorithmPRIMARYRelaxation, priority queue, and correctness for nonnegative weights
11Bellman-Ford and Negative EdgesPRIMARYEdge-relaxation rounds and negative-cycle detection
12Floyd-Warshall and DP Shortest PathsSUPPORTINGAll-pairs via dynamic programming with intermediate-vertex subsets

Cluster mastery check: Can you pick Dijkstra, Bellman-Ford, BFS, or Floyd-Warshall given a graph's edge weights and the question being asked?

Cluster 4: Minimum Spanning Trees and Greedy on Graphs

OrderConceptTypeFocus
13MST, Cut Property, Cycle PropertyPRIMARYThe two structural theorems that justify every MST algorithm
14Kruskal with Union-FindPRIMARYEdge-sorted greedy plus disjoint-set bookkeeping
15Prim with Priority QueuePRIMARYGrowing one tree from a root, mirror of Dijkstra's shape
16MST Variants and ApplicationsSUPPORTINGBottleneck MST, Steiner approximation, network design

Cluster mastery check: Can you justify Kruskal or Prim using the cut property on a worked example rather than quoting the algorithm?

Cluster 5: Network Flow and Matching

OrderConceptTypeFocus
17Max Flow and Ford-FulkersonPRIMARYFlow definition, residual graphs, and augmenting paths
18Edmonds-Karp, Capacity Scaling, Push-RelabelSUPPORTINGConcrete polynomial-time realizations of the method
19Max-Flow Min-Cut DualityPRIMARYThe cut side of flow and where it models real problems
20Bipartite Matching via Max FlowSUPPORTINGReduction to flow and Hopcroft-Karp intuition

Cluster mastery check: Can you take a non-flow-looking problem (task assignment, pixel labeling, project selection) and expose the flow graph hiding inside it?

Then work these practice pages:

OrderPractice pathFocus
1Graph Representation and Traversal LabRepresentations, BFS, DFS, SCCs, topological sort
2Shortest Paths and MST WorkshopDijkstra, Bellman-Ford, Floyd-Warshall, Kruskal, Prim
3Network Flow and Matching ClinicFord-Fulkerson, min cuts, bipartite matching
4Code KatasImplementation drills for every named algorithm

Use Module Quiz after the concept and practice path. Use Reference and Selective Reading and Learning Resources only for targeted reinforcement.


Learning Objectives

By the end of this module you should be able to:

  1. Model a real problem as a graph, stating vertices, edges, directedness, weights, and special structure explicitly.
  2. Choose adjacency list vs matrix with an argument about |V|, |E|, and the operations you need.
  3. Implement BFS and DFS, report their time and space bounds, and classify DFS edges on a directed graph.
  4. Compute connected components and strongly connected components, and produce a topological order on a DAG.
  5. Pick between BFS, Dijkstra, Bellman-Ford, and Floyd-Warshall based on edge weights and question type.
  6. State and apply the cut and cycle properties, and implement Kruskal (with union-find) and Prim (with a heap).
  7. Define flow networks, execute Ford-Fulkerson, explain the max-flow min-cut theorem, and model bipartite matching as flow.
  8. Defend any algorithmic choice with a running-time analysis and a correctness sketch, not by pattern recognition alone.

Outputs

  • a graph-algorithms repository with tested implementations of BFS, DFS, Kosaraju SCC, topological sort, Dijkstra (heap), Bellman-Ford, Floyd-Warshall, Kruskal (union-find), Prim (heap), and Ford-Fulkerson
  • one modeling notebook translating at least 8 informally stated problems into explicit graph instances
  • one algorithm-selection sheet covering at least 10 shortest-path scenarios with justified choices
  • one MST sheet with at least 3 cut-property arguments written in sentence form
  • one flow sheet modeling at least 3 non-flow-looking problems (matching, project selection, image segmentation) as max-flow instances
  • one mistake log naming at least 10 reasoning errors such as ran Dijkstra on negative edges, used matrix on a sparse graph, confused SCC with CC, forgot to reverse the graph in Kosaraju, or missed a residual edge
  • one short memo explaining how the module's tools carry into systems work (dependency graphs, build orders, routing)

Completion Standard

You have completed Module 3 when all of these are true:

  • you state the graph model before you name an algorithm
  • you justify adjacency-list vs matrix by complexity, not by habit
  • you can trace BFS and DFS on paper and explain the resulting trees and edge classes
  • you can run Dijkstra and Bellman-Ford by hand on a 6-8 vertex graph and defend the relax order
  • you can execute Kruskal and Prim by hand and cite the cut property during the argument
  • you can take a real problem (assignment, scheduling, bottleneck) and turn it into a flow or matching instance
  • you can read a new graph problem and decide "this is a DAG topo question" or "this is really min-cut" within seconds

If the algorithm runs but you cannot explain why the answer is correct or why this algorithm fits, the module is not complete.


Reading Policy

  • Concept pages are the main path.
  • Local book chunks are selective reinforcement, not a second syllabus.
  • Read only if stuck means try the concept page, self-check, and drill first.
  • Optional deep dive means additional nuance or exercise volume, not required progression.
  • Because graph algorithms reward implementation experience, the Code Katas are required, not optional.

Suggested Weekly Flow

DayWork
1Concepts 1-4 and a modeling sheet translating 3 informal problems into graphs
2Concepts 5-6, implement BFS and DFS from scratch, and run both on one worked graph
3Concepts 7-8, implement Kosaraju and topological sort
4Concepts 9-10, implement Dijkstra with a binary heap, hand-trace one example
5Concepts 11-12, implement Bellman-Ford and Floyd-Warshall
6Concepts 13-15, implement Kruskal (union-find) and Prim (heap), write a cut-property argument
7Concepts 16-20, Ford-Fulkerson implementation, practice pages, and quiz

Reference

If you need exact links into the local chunked books, use Reference and Selective Reading.


Rich Learning Pages

Worked Examples | Guided Labs | Case Studies | Mistake Clinic | Reading Guide | Capstone Thread