📊 Section 1 — Interactive Simulation
Pick a graph preset (or build your own by adding/removing edges and dragging nodes). Switch modes to find Eulerian circuits, Hamiltonian paths, or proper colorings — each with its own algorithm and animation.
Animation
Graph Preset
Edit Graph
Tap two nodes to toggle edge. Drag nodes to reposition.
Algorithm Parameters
Display Options
Tips
• Königsberg has 4 odd vertices → no Eulerian circuit (Euler's 1736 result).
• K₅ is non-planar; minimum colors needed is 5.
• Petersen graph is famously NOT Hamiltonian — try to find a path!
• Hamiltonian search is NP-complete; expect slow on n>14.
💡 Section 2 — The Idea, Step by Step
From "dots and lines" to three deep algorithmic questions — built up one layer at a time.
Start with something you already know. Draw a few dots on paper and connect some of them with lines: that picture is a graph. The dots are vertices, the lines are edges. Friends linked by friendships, cities linked by roads, web pages linked by hyperlinks — all the same object. Two playful puzzles live inside every such picture. Can you trace every line without lifting your pen and without going over any line twice? And, separately, can you tour every dot exactly once? They sound almost the same, yet they hide a surprising gap in difficulty.
Now name things. The number of lines meeting a vertex is its degree, $\deg(v)$. Here is the one rule that cracks the first puzzle: if you add up the degrees of all the vertices, you count each edge twice — once at each end — so $\sum_v \deg(v) = 2\abs{E}$. This is the handshake lemma. Euler saw that to trace every edge and get back home, you must enter and leave each vertex equally often, which forces every degree to be even. Königsberg's four landmasses had degrees $3,3,3,5$ — all odd — so the famous "cross all seven bridges once and return" walk is simply impossible. That single observation, in 1736, launched graph theory.
A connected graph has an Eulerian circuit $\iff$ every vertex has even degree. And greedy coloring never needs more than $\chi(G) \le \Delta(G)+1$ colors.
The precise versions sharpen all this. Eulerian circuits are local: just check whether every degree is even, then Hierholzer's algorithm builds the circuit in $O(\abs{E})$ time. The Hamiltonian question — visit every vertex once — has no such shortcut; it is NP-complete, which is why the sim runs an exponential backtracking search. Coloring asks for the fewest colors $\chi(G)$ so that no edge joins two same-colored vertices, and the greedy pass guarantees $\chi(G)\le\Delta(G)+1$. In the simulation above, the mode tabs switch between these three problems, the preset dropdown loads classic graphs, and the $n$ and $p$ sliders generate random Erdős–Rényi graphs.
Try this in the sim above: load Königsberg and watch the "odd-degree count" read 4 — Euler mode reports no circuit. Switch the preset to Cycle C₆: now every degree is 2, and an Eulerian circuit appears at once. Finally choose the Petersen graph, run Hamiltonian mode, and watch the search backtrack and fail — it is the smallest 3-regular graph with no Hamiltonian cycle.
📐 Section 3 — Three Theorems
Each problem has a sharp characterization or bound — though their algorithmic difficulty varies wildly.
A connected multigraph $G$ has an Eulerian circuit (closed walk using every edge exactly once) if and only if every vertex has even degree.
Variant: $G$ has an Eulerian trail (open) iff exactly two vertices have odd degree (those become the endpoints).
Dirac (1952): If $G$ is a simple graph with $n \geq 3$ vertices and every vertex has $\deg(v) \geq n/2$, then $G$ has a Hamiltonian cycle (cycle through every vertex).
Ore (1960): If for every pair of non-adjacent $u, v$, $\deg(u) + \deg(v) \geq n$, then $G$ has a Hamiltonian cycle.
No "if and only if" exists: deciding Hamiltonicity is NP-complete (Karp, 1972).
Four Color (Appel–Haken, 1976): Every planar graph is 4-colorable; $\chi(G_{\text{planar}}) \leq 4$.
Brooks (1941): For any connected graph $G$ that is not a complete graph and not an odd cycle, $\chi(G) \leq \Delta(G)$, the maximum degree.
Symbol Table
| Symbol | Meaning | Type |
|---|---|---|
| $G = (V, E)$ | Graph: vertex set $V$ and edge set $E$ | Pair of finite sets |
| $n = \abs{V}$ | Number of vertices (order of $G$) | Positive integer |
| $m = \abs{E}$ | Number of edges (size of $G$) | Non-negative integer, $\leq \binom{n}{2}$ |
| $\deg(v)$ | Degree: number of edges incident to $v$ | Integer in $[0, n-1]$ (simple graph) |
| $\Delta(G)$ | Maximum degree over all vertices | Integer |
| $\chi(G)$ | Chromatic number — minimum colors for proper coloring | Positive integer |
| $K_n$ | Complete graph: every pair of vertices adjacent | $\binom{n}{2}$ edges |
| $C_n$ | Cycle on $n$ vertices | $n$ edges, all degrees 2 |
| $K_{p,q}$ | Complete bipartite: $p+q$ vertices in two parts | $pq$ edges |
Proof — Euler's Theorem (Sufficient Direction)
Simulation ↔ Symbol Mapping
| nodes on canvas | vertex set $V$ |
| edges between nodes | edge set $E$ |
readout |V|, |E| | $n, m$ — order and size |
readout odd-degree count | number of vertices with odd $\deg$ — Euler circuit exists ⇔ this is 0 |
readout χ(G) | chromatic number, computed as result of greedy coloring (upper bound; exact for small $n$) |
mode Euler | runs Hierholzer's algorithm; trail of edges in animation = current circuit being built |
mode Hamilton | DFS backtracking: visit unvisited neighbors; current path highlighted; failed branches fade |
mode Color | greedy coloring with Welsh–Powell ordering; colors assigned in animation order |
Worked Example — Königsberg Bridges
Königsberg's two islands and the riverbanks gave 4 land masses connected by 7 bridges. As a multigraph: $V = \{N, S, E, W\}$ (north bank, south bank, east island, west island), with degrees $\deg(N)=3$, $\deg(S)=3$, $\deg(E)=3$, $\deg(W)=5$.
Sum check: $3+3+3+5 = 14 = 2\abs{E}$ ✓ ($14/2 = 7$ bridges, the famous count).
All four vertices have odd degree. By Euler's theorem, no Eulerian circuit exists — and not even an Eulerian trail (which needs exactly 0 or 2 odd vertices).
Conclusion (Euler 1736): No walk can cross every bridge exactly once and return. The negative answer launched graph theory as a mathematical discipline. $\boxed{\text{Königsberg is not Eulerian.}}$
❓ Section 4 — Frequently Asked Questions
Eulerian existence has a local characterization: just check parities of degrees. Once existence is confirmed, Hierholzer's algorithm constructs a circuit in linear time. Hamiltonian, however, has no such local test — there's no efficient property of vertices and edges that says "yes, a Hamiltonian path exists". You essentially have to search through possible orderings of vertices, and the best known algorithms are exponential (best general bound is $O^*(2^n)$ via Bellman–Held–Karp dynamic programming). NP-complete means: if you could decide Hamiltonicity in polynomial time, you could solve every problem in NP — including SAT, 3-coloring, factoring, and thousands more. So unless P = NP, Hamiltonian is genuinely hard.
Key takeaway: local properties (Eulerian) are easy; global properties (Hamiltonian) are NP-complete because no shortcuts to brute search are known.It maintains a stack and a circuit. Start at any vertex; mark it the "current". While the current vertex has unused edges, push it onto the stack and traverse one of its edges, deleting that edge as we go. When the current vertex has no more unused edges, pop it and append to the output circuit. Repeat until the stack is empty. Each edge is touched exactly twice (push and pop), so the total work is $O(\abs{E})$ — linear in the number of edges. The simulation animates each push/pop step: the orange highlight is the current vertex, the gold path is the partial circuit, and faded edges are already used.
Key takeaway: Hierholzer = stack-based DFS over edges; linear time, very simple to implement, and produces a complete Eulerian circuit.Almost everywhere. Networks: routing in the internet (shortest paths), social network analysis, recommendation systems. Map coloring: scheduling and frequency assignment use coloring to avoid conflicts; the four color theorem guarantees four cellular frequencies suffice for planar territories. Routing: postal-route optimization is the Chinese Postman Problem — find shortest closed walk traversing every edge (an Eulerian relaxation). The Travelling Salesman Problem is the Hamiltonian relaxation with edge weights. Compilers: register allocation is graph coloring on the interference graph of variables. Logistics: vehicle routing, garbage collection routing. Bioinformatics: DNA sequencing assembles overlapping fragments using Eulerian paths in De Bruijn graphs — modern genome assemblers all use this. Linguistics: dependency graphs in NLP. Quantum chemistry: graph isomorphism for molecular structure.
Key takeaway: routing, scheduling, register allocation, DNA assembly, social networks — all rely on graph algorithms.The Petersen graph has 10 vertices, every vertex has degree 3 — it's vertex-transitive, looks symmetric, and "feels" like it should have a Hamiltonian cycle. It doesn't. Sketch: suppose it does. The graph is bipartite-like in structure with an outer pentagon $\{0,1,2,3,4\}$ connected to an inner pentagram $\{5,6,7,8,9\}$. A Hamiltonian cycle uses 10 edges total; counting how many cross between outer and inner — by parity it must be even, and arguments about the pentagram structure force a contradiction. The Petersen graph is the smallest 3-regular graph that is non-Hamiltonian, and the canonical counterexample for many graph-theoretic conjectures. Its non-Hamiltonicity also implies it cannot be "edge-decomposed" into perfect matchings in a particular way.
Key takeaway: high regularity ≠ Hamiltonian. The Petersen graph is the standard example showing global structure matters.For an Erdős–Rényi random graph $G(n, p)$ with constant edge probability $p$, Bollobás (1988) proved $\chi(G(n,p)) \sim \dfrac{n}{2\log_b n}$ where $b = 1/(1-p)$, with high probability. For $p=1/2$: $\chi \sim n/(2\log_2 n)$. For $n=100$ and $p=0.5$, expect $\chi \approx 100/(2\cdot 6.6) \approx 7.5$, so 7 or 8 colors. Greedy coloring (Welsh–Powell) typically uses about twice the optimum for random graphs. Exact $\chi$ is NP-hard to compute, but practical solvers (DSATUR, integer programming) handle hundreds of vertices. The simulation displays the greedy upper bound — exact $\chi$ for the displayed graph is shown only for small instances where exhaustive search is tractable.
Key takeaway: $\chi$ of random graphs is $\sim n/(2\log n)$; computing it exactly is NP-hard but practical for $n \lesssim 200$.Coloring is surprisingly central. Chromatic polynomial $P(G, k)$ counts proper $k$-colorings; it satisfies a deletion-contraction recurrence and has connections to the Tutte polynomial, knot theory (Jones polynomial via Tait colorings), and statistical mechanics (Potts model partition functions). Topological obstructions: the four color theorem is intimately connected to planarity — embeddability in $\R^2$. The Hadwiger conjecture proposes $\chi(G) \le t$ whenever $G$ contains no $K_{t+1}$ minor — a dramatic generalization. Algebraic graph theory: $\chi(G) \leq 1 + \lambda_{\max}(\text{adjacency})$ (Wilf's bound) and $\chi(G) \geq n/(n - \lambda_{\min})$ (Hoffman), tying coloring to spectral graph theory. Probabilistic combinatorics: random colorings via Lovász Local Lemma. Computer science: register allocation, exam scheduling, Sudoku-as-coloring, all NP-hard variants.
Key takeaway: graph coloring connects topology, spectral theory, knot theory, and statistical physics — far more than just "color the map".No — a graph is an abstract combinatorial object: a set $V$ and a set of pairs $E \subseteq \binom{V}{2}$. The drawing is just a visual representation. Two completely different-looking drawings can represent the same graph (graph isomorphism). Whether a graph can be drawn without edge crossings in the plane is a separate property called planarity (Kuratowski's theorem: $G$ is planar iff it contains no $K_5$ or $K_{3,3}$ minor). The simulation lets you drag vertices: you're just moving the drawing — the graph (vertex set, edge set) stays the same. Two graphs are equal iff they have the same vertex set and edge set; isomorphic if there's a relabeling that makes them equal.
Key takeaway: graphs are combinatorial; drawings are just one way to see them. Planarity is about whether some crossing-free drawing exists.