Behind the Scenes: Math for Introductory CS - Graph Theory
Tom Crawford's Failed Attempts
The host, Tom Crawford, attempts to solve the Königsberg bridge problem by physically tracing routes, but finds himself repeatedly stuck, unable to cross all bridges exactly once, highlighting the problem's inherent difficulty and the need for a systematic approach.
Graph Theory Translation: Vertices and Edges
To solve the Königsberg problem, graph theory translates the city's landmasses into vertices (points) and bridges into edges (lines connecting vertices), simplifying the problem into a visualizable structure.
Oiler's Theorem: The Key to Traversability
Leonard Euler's theorem states that a graph is traversable (all edges crossed exactly once) if either all vertices have an even degree (Eulerian cycle) or exactly two vertices have an odd degree (Eulerian trail, starting and ending at the odd-degree vertices).
The Verdict on Königsberg's Seven Bridges
The original seven-bridge problem of Königsberg is impossible to solve because its graph representation has four vertices with odd degrees, violating Euler's theorem's conditions of zero or exactly two odd-degree vertices.
Walks vs. Paths
A walk in a graph is a sequence of vertices where edges can be repeated, while a path is a walk where no vertices are repeated. This distinction is fundamental to understanding graph traversal.
Cycles and Hamiltonian Cycles
A cycle is a closed walk where vertices are not repeated, except for the start and end vertex. A Hamiltonian cycle is a special type of cycle that visits every vertex in the graph exactly once.
Trails and Eulerian Paths/Cycles
A trail is a walk where no edges are repeated. An Eulerian trail visits every edge exactly once and starts and ends at different vertices, while an Eulerian cycle visits every edge exactly once and starts and ends at the same vertex.
The Three Utilities Problem
The three utilities problem asks if it's possible to connect three houses to three utilities (water, gas, electricity) without any pipe crossings. This is equivalent to asking if a specific graph is planar.
The Non-Planar K33 Graph
The problem of connecting three utilities to three houses, often visualized as a graph, is a classic example of a non-planar graph known as K33, meaning it cannot be drawn on a flat plane without edges crossing. This impossibility highlights fundamental constraints in graph theory.
The Traveling Salesman Problem: A Route Optimization Challenge
The Traveling Salesman Problem (TSP) asks for the shortest possible route that visits a set of cities and returns to the origin city. While seemingly simple, finding the optimal solution becomes computationally intractable as the number of cities increases, demonstrating the challenges of combinatorial optimization.
Computational Complexity: The Factorial Explosion
The number of possible routes in the Traveling Salesman Problem grows factorially (n!) with the number of cities (n). This factorial growth leads to an explosion in computation time, making it impossible for even powerful computers to find optimal solutions for a large number of cities within a reasonable timeframe.
P vs. NP: The Million-Dollar Question
The P vs. NP problem, a major unsolved question in computer science, asks whether every problem whose solution can be quickly verified (NP) can also be quickly solved (P). The Traveling Salesman Problem serves as a prime example: verifying a proposed route is fast, but finding the optimal route is computationally expensive.
Heuristics: Shortcuts for Complex Problems
While finding the absolute optimal solution to problems like TSP is often infeasible, practical 'shortcuts' or heuristics, such as the nearest neighbor algorithm, can provide good-enough solutions quickly. These algorithms don't guarantee optimality but offer efficient approximations for real-world applications.
Nearest Neighbor Algorithm: A Greedy Approach
The nearest neighbor algorithm is a greedy heuristic that, starting from a given city, repeatedly moves to the nearest unvisited city. While simple and fast, it does not guarantee the shortest overall route, as demonstrated by its application to a parallelogram graph where it produced a suboptimal path.
Recursive Nearest Neighbor and Starting Point Influence
To improve the nearest neighbor algorithm, one can apply it from every possible starting city and select the best result. However, even this recursive approach does not guarantee the globally optimal solution, underscoring the inherent difficulty of the Traveling Salesman Problem.
The Hydra Game: A Graph Theory Puzzle
The Hydra game, inspired by Hercules' battle with the Lernaean Hydra, is a graph theory puzzle where removing a 'head' (node) can cause two new heads to appear. This game serves as an engaging, albeit metaphorical, introduction to concepts of graph manipulation and state changes.
Tom Crawford: The Hydra Game's Mathematical Makeover
The original Hydra game, where removing one head results in two more, is impossible to win. However, by translating the myth into graph theory and modifying the rules so that new heads appear one layer lower, the problem becomes solvable. The graph represents heads as vertices and connections as edges, with the body as the base layer.
The Solvability Condition: Layered Growth
The key to solving the mathematical Hydra game lies in the rule that new heads grow one layer lower when a head is removed. This prevents infinite growth because eventually, heads will attempt to grow from the body (layer zero), where no lower layer exists, thus ending the process. This mechanism ensures the game is finite.
Exploring Hydra Game Variations: Changing the Rules
Beyond the standard two-heads-per-removal rule, the Hydra game can be modified. The number of heads that reappear can change at each step, and it doesn't have to be two. For instance, removing head 'k' could result in 'k' new heads appearing a layer lower. This opens up a vast landscape for mathematical exploration.


























