Discrete Mathematics · Kenneth H. Rosen

Graph Theory

A complete visual guide covering graphs, connectivity, paths, planarity and coloring — built for CSE beginners.

// Chapters 10 · Rosen 8th Edition
Chapter 10.1

Graphs and Graph Models

Graph theory studies pairwise relationships between objects. It powers GPS navigation, social networks, circuit design, scheduling — nearly all of computer science.

Definition · Graph

A graph G = (V, E) consists of a nonempty set V of vertices (nodes) and a set E of edges. Each edge connects one or two vertices, called its endpoints.

Types of Graphs

TypeEdgesMultiple Edges?Loops?
Simple GraphUndirectedNoNo
MultigraphUndirectedYesNo
PseudographUndirectedYesYes
Simple DigraphDirectedNoNo
Directed MultigraphDirectedYesYes
Mixed GraphBothYesYes

Real-World Models

Example · Social Network

Vertices = people. Edges = friendships. Simple undirected graph. Degree = number of friends.

Example · Web Graph

Vertices = webpages. Directed edges = hyperlinks. PageRank algorithm runs on this digraph.

Example · Road Network

Vertices = intersections. Edges = roads (weighted by distance). GPS uses shortest-path algorithms here.

Example · Task Scheduling

Vertices = tasks. Directed edges = dependency (A→B means A must finish before B). Topological sort used.

// Interactive · Click canvas to add nodes · Click two nodes to add edge
Mode: Add Node — click canvas to place vertices
Nodes: 0  |  Edges: 0  |  Type: Undirected Simple Graph
Chapter 10.2

Graph Terminology & Special Graphs

Degree

Definition · Degree

The degree of vertex v, written deg(v), is the number of edges incident to v. A loop counts twice. In a digraph: in-degree = edges coming in; out-degree = edges going out.

Theorem · Handshaking Lemma

For any undirected graph G = (V, E):

v ∈ V deg(v) = 2|E|

Consequence: Every graph has an even number of vertices with odd degree. This is a fundamental counting fact used everywhere.

Special Graph Types

Complete Graph Kₙ

Every pair of vertices connected by exactly one edge. Kₙ has n(n−1)/2 edges. Every vertex has degree n−1.

Cycle Graph Cₙ

n vertices arranged in a ring. Each vertex has degree 2. Minimum n = 3.

Wheel Graph Wₙ

Cₙ plus one central hub connected to all. Hub degree = n; rim vertices degree = 3.

Bipartite Graph

Vertices split into two disjoint sets V₁, V₂. Every edge goes between V₁ and V₂ — never within same set. A graph is bipartite iff it has no odd-length cycle.

Complete Bipartite Kₘ,ₙ

Every vertex in V₁ connected to every vertex in V₂. Has m·n edges.

Hypercube Qₙ

Vertices = n-bit strings. Edge between strings differing in exactly 1 bit. Qₙ has 2ⁿ vertices and n·2ⁿ⁻¹ edges. Used in parallel computing.

// Special Graphs Visualizer
Select a graph above to visualize it.
// Degree Explorer · Hover nodes to see degree · Verify Handshaking Lemma
deg 1
deg 2
deg 3
deg 4+
Sum of degrees =  |  2 × |E| =  |  Handshaking holds:
Chapter 10.3

Representing Graphs & Graph Isomorphism

Adjacency Matrix

Definition

For graph G with vertices v₁…vₙ, the adjacency matrix A is an n×n matrix where A[i][j] = 1 if {vᵢ,vⱼ} is an edge, else 0. For multigraphs, A[i][j] = number of edges between them.

Properties: symmetric for undirected, diagonal all-zeros for simple graph, row sum = degree of vᵢ.

Incidence Matrix

Definition

n×m matrix M where M[i][j] = 1 if vertex vᵢ is incident with edge eⱼ, else 0. Column sum always = 2 (each edge has two endpoints).

Adjacency List

More memory-efficient. For each vertex store list of its neighbors. Total space: O(V + E) vs O(V²) for matrix.

// Graph Representation Demo · Select representation type

Graph Isomorphism

Definition · Isomorphism

Graphs G₁=(V₁,E₁) and G₂=(V₂,E₂) are isomorphic if there exists a bijection f: V₁→V₂ such that {u,v}∈E₁ iff {f(u),f(v)}∈E₂. They are "same graph, different labeling."

Necessary Conditions (Isomorphism Invariants)

Same |V| Same |E| Same degree sequence Same # connected components Same # cycles

These are necessary but not sufficient. If any differ → not isomorphic. If all match → might be isomorphic (need explicit bijection to confirm).

// Isomorphism Inspector · Two random graphs · Check invariants
GRAPH G₁
GRAPH G₂
Click a button to generate graph pairs and check invariants.
Chapter 10.4

Connectivity

Paths and Circuits

Definition · Path

A path of length n from u to v is a sequence u=v₀, e₁, v₁, e₂, …, eₙ, vₙ=v of alternating vertices and edges. A simple path visits no vertex more than once.

Definition · Circuit / Cycle

A circuit (closed walk) starts and ends at same vertex. A cycle is a simple circuit — no repeated vertex except start=end.

Connected Graphs

Definition · Connected

An undirected graph is connected if there is a path between every pair of vertices. Otherwise it's disconnected, and each maximal connected subgraph is a connected component.

Definition · Strongly / Weakly Connected (Digraphs)

Strongly connected: path from u to v AND v to u for every pair. Weakly connected: underlying undirected graph is connected.

Cut Vertices and Bridges

Definition

A cut vertex (articulation point): removing it increases connected components. A bridge: removing it disconnects the graph. Critical for network reliability analysis.

Connectivity Numbers

Vertex Connectivity κ(G)

Min vertices to remove to disconnect G (or make trivial). κ(Kₙ) = n−1 (most robust). κ(G) ≤ λ(G) ≤ δ(G).

Edge Connectivity λ(G)

Min edges to remove to disconnect G. Menger's theorem links this to max disjoint paths.

// BFS & DFS Traversal · See how connectivity is explored
Click Run BFS or Run DFS to start traversal from the red node.
Start
Queue/Stack
Visited
Unvisited
Visited order:
// Cut Vertex & Bridge Detector · Hover nodes/edges to highlight
Cut Vertex
Bridge Edge
Normal
Click Find Cut Vertices or Find Bridges
Chapter 10.5

Euler and Hamiltonian Graphs

Euler Paths and Circuits

Definition · Euler Circuit

A circuit that visits every edge exactly once (may revisit vertices). Named after Leonhard Euler who solved the Königsberg Bridge Problem in 1736 — birth of graph theory.

Definition · Euler Path

A path (not circuit) that uses every edge exactly once. Starts and ends at different vertices.

Theorem · Euler's Conditions

Euler Circuit exists iff G is connected AND every vertex has even degree.
Euler Path exists iff G is connected AND exactly two vertices have odd degree (those are the endpoints).

Historical · Königsberg Bridges

Seven bridges over the Pregel River connecting 4 land masses. Euler proved no walk crossing each bridge exactly once exists — all 4 vertices had odd degree. This proof founded graph theory.

Hamiltonian Paths and Circuits

Definition · Hamiltonian Circuit

A circuit that visits every vertex exactly once (may skip edges). Named after William Rowan Hamilton.

Theorem · Dirac's Condition (Sufficient)

If G is simple, n ≥ 3, and every vertex has deg(v) ≥ n/2, then G has a Hamiltonian circuit.

Theorem · Ore's Condition (Sufficient)

If for every pair of non-adjacent vertices u,v: deg(u)+deg(v) ≥ n, then Hamiltonian circuit exists.

Key distinction: Euler = traverse all edges; Hamilton = visit all vertices. Euler conditions are easy to check; Hamilton is NP-complete in general.

EulerHamiltonian
What is traversed?Every edge onceEvery vertex once
CharacterizationDegree conditions (easy)No simple characterization (NP-hard)
AlgorithmFleury's / Hierholzer's O(E)No poly-time known
ApplicationRoute planning, circuit boardsTSP, DNA sequencing
// Euler & Hamiltonian Path Simulator · Fleury's Algorithm animated
Select a graph and click Check Euler
Degrees:
Chapter 10.6

Shortest-Path Problems

Given a weighted graph, find the path from source to destination with minimum total weight. Real applications: GPS, network routing (OSPF), airline connections.

Dijkstra's Algorithm

Algorithm · Dijkstra (1959)

Finds shortest paths from a single source to all vertices in a weighted graph with non-negative weights. Greedy approach using priority queue.

Time: O((V + E) log V) with binary heap  |  O(V²) with array

Algorithm Steps:

  1. Set dist[source] = 0, dist[all others] = ∞
  2. Add all vertices to priority queue keyed by dist
  3. Extract vertex u with min dist
  4. For each neighbor v of u: if dist[u] + w(u,v) < dist[v], update dist[v] (relaxation)
  5. Repeat until queue empty

Floyd-Warshall Algorithm

Algorithm · Floyd-Warshall

Finds shortest paths between all pairs of vertices. Works with negative weights (not negative cycles). Dynamic programming approach.

D[i][j][k] = min(D[i][j][k−1], D[i][k][k−1] + D[k][j][k−1])  |  O(V³)
// Dijkstra's Algorithm · Click start node then run
Click a node to set source, then Step or Run All
Source
In Queue
Finalized
Shortest Path
Distances:
Chapter 10.7

Planar Graphs

Definition · Planar Graph

A graph that can be drawn in the plane with no edge crossings. The drawing itself (without crossings) is called a planar embedding.

Euler's Formula for Planar Graphs

Theorem · Euler's Planar Formula

For a connected planar graph with V vertices, E edges, and F faces (regions, including unbounded outer face):

V − E + F = 2

This is the planar graph version of Euler's characteristic. Works for any planar embedding!

Example

Cube graph: V=8, E=12, F=6 → 8−12+6 = 2 ✓    Triangle: V=3, E=3, F=2 → 3−3+2 = 2 ✓

Inequalities for Planar Graphs

Corollary

For simple connected planar graph with V ≥ 3:

E ≤ 3V − 6     (in general)         E ≤ 2V − 4     (if no triangles)

Use to prove non-planarity: if E > 3V−6, graph is NOT planar.

Kuratowski's Theorem

Theorem · Kuratowski (1930)

A graph is planar iff it contains no subgraph that is a subdivision of K₅ or K₃,₃. (A subdivision replaces edges with paths.)

K₅ Check

V=5, E=10. Check: E ≤ 3V−6 → 10 ≤ 9. FALSE → K₅ not planar.

K₃,₃ Check

V=6, E=9, bipartite so no triangles. Check: E ≤ 2V−4 → 9 ≤ 8. FALSE → K₃,₃ not planar.

// Planar Graph Demo · Drag nodes to redraw without crossings
Drag nodes to rearrange the graph
V= E= F= | V−E+F= | Status:
Chapter 10.8

Graph Coloring

Definition · Graph Coloring

Assignment of colors to vertices so that no two adjacent vertices share the same color. The minimum number of colors needed is the chromatic number χ(G).

The Four Color Theorem

Theorem · Four Color Theorem (Appel & Haken, 1976)

Every planar graph can be colored with at most 4 colors. First major theorem proved with computer assistance (checking 1,936 reducible configurations).

Chromatic Numbers of Special Graphs

Graphχ(G)Reason
Bipartite (non-trivial)22-colorable (proven by BFS 2-coloring)
Odd Cycle C₂ₖ₊₁3Need 3rd color for the "closing" vertex
Even Cycle C₂ₖ2Bipartite
Complete KₙnAll pairs adjacent
Tree2Always bipartite
Planar Graph≤ 4Four Color Theorem
Petersen Graph3Not bipartite, not complete

Greedy Coloring Algorithm

Assign colors in order: give each vertex the smallest color not used by its already-colored neighbors. Produces at most Δ(G)+1 colors where Δ is max degree. NOT always optimal.

Brook's Theorem

χ(G) ≤ Δ(G) unless G is a complete graph or odd cycle, in which case χ(G) = Δ(G)+1.

Applications of Coloring

Exam Scheduling

Vertices = exams. Edge if same student takes both. Color = time slot. χ(G) = minimum slots needed.

Register Allocation

In compilers, variables that are "live" at same time can't share a register. Coloring = register assignment.

Map Coloring

Countries sharing border need different colors. Dual graph of map = planar graph → 4 colors always enough.

Sudoku

Sudoku is a graph coloring problem on a 81-vertex graph where edges connect cells in same row/col/box. χ = 9.

// Graph Coloring Simulator · Greedy coloring animated
Select a graph and click Step or Auto Color
Colors used: 0  |  χ(G) = ?  |  Order:
// Try It Yourself · Click a color then click a vertex to color it
Select a color then click vertices to color them
GRAPH THEORY COMPLETE REFERENCE
Based on: Kenneth H. Rosen, Discrete Mathematics and Its Applications, 8th Ed., Chapter 10
Topics: Graph Models · Terminology · Representation · Isomorphism · Connectivity · Euler & Hamilton · Shortest Paths · Planarity · Coloring