Lecture from: 27.02.2025 | Video: Homelab
Recall
Hamiltonian Cycles and Eulerian Tours
Definitions
Let be a graph.
- Eulerian Tour: A closed walk in that traverses every edge exactly once.
- Hamiltonian Cycle: A cycle in that visits every vertex exactly once.
Eulerian Tours: Characterization
Theorem: A connected undirected graph contains an Eulerian tour if and only if the degree of every vertex in is even. Furthermore, such a tour can be found in time.
This theorem provides a simple and efficient way to determine if an Eulerian tour exists and to construct one if it does. The condition on vertex degrees is both necessary and sufficient for the existence of an Eulerian tour in a connected graph.
Hamiltonian Cycles: Definition and Examples
A Hamiltonian cycle is a cycle that visits each vertex of a graph exactly once. Determining if a graph contains a Hamiltonian cycle is a much more complex problem than determining the existence of an Eulerian tour.
The Icosian Game and Sir William Hamilton
The concept of Hamiltonian cycles is historically linked to the “Icosian Game” invented by Sir William Rowan Hamilton. The game involved finding a Hamiltonian cycle on the vertices of a dodecahedron.
Examples
- Icosahedral Graph: The graph derived from the vertices and edges of an icosahedron does contain a Hamiltonian cycle.
- Petersen Graph: The Petersen graph, despite being highly symmetric and having degree 3 for every vertex, does not contain a Hamiltonian cycle. This illustrates that seemingly simple graphs can lack Hamiltonian cycles.
- Grid Graphs: An grid graph contains a Hamiltonian cycle if and only if the product is even (assuming ). This can be proven using a chessboard coloring argument, as a Hamiltonian cycle in a bipartite graph must alternate between the two sets of vertices, requiring them to be of equal size.
Hamiltonian Cycles in Hypercubes: Gray Codes
Hamiltonian cycles have practical applications, for instance, in the design of rotary encoders using Gray codes.
Gray Codes and Hypercubes
An -bit Gray code is a sequence of binary numbers such that each successive number differs in only one bit position. The existence of a Gray code of length is equivalent to the existence of a Hamiltonian cycle in an -dimensional hypercube .
Recursive Construction of Gray Codes
Hamiltonian cycles in hypercubes (and thus Gray codes) can be constructed recursively. For example, to construct a Gray code of dimension , one can use two copies of a Gray code of dimension , prefixing the first half with ‘0’ and the second (reversed) half with ‘1’.
Dirac’s Theorem: Sufficient Condition for Hamiltonian Cycles
Dirac’s Theorem: If a graph with has a minimum degree , then contains a Hamiltonian cycle.
Dirac’s theorem provides a sufficient condition for the existence of a Hamiltonian cycle. It states that if a graph is “dense enough” (in terms of minimum degree), then it is guaranteed to be Hamiltonian.
Lemma for Dirac’s Theorem
Lemma 1: If a graph satisfies Dirac’s condition (), then for any , , either contains a cycle of length at least , or contains a cycle of length at least that includes a given set of vertices.
This lemma is crucial in proving Dirac’s Theorem. It essentially shows that under Dirac’s condition, we can always find long cycles, eventually leading to a Hamiltonian cycle.
Complexity of Hamiltonian Cycle Problem
NP-Completeness
The problem of determining whether a graph contains a Hamiltonian cycle is NP-complete. This implies that it is unlikely to have a polynomial-time algorithm.
Theorem (Karp 1972): The Hamiltonian cycle problem is NP-complete.
Dynamic Programming Approach
While no polynomial-time algorithm is known, Hamiltonian cycles can be found using dynamic programming in time. This is a significant improvement over brute-force methods but is still exponential.
Dynamic Programming Algorithm Idea
The dynamic programming approach is based on computing , which is 1 if there is a path starting at vertex 1, visiting exactly the vertices in set , and ending at vertex , and 0 otherwise. The recursion is defined based on extending paths by considering the last vertex visited before .
Traveling Salesman Problem (TSP)
Definition
The Traveling Salesman Problem (TSP) is an optimization problem where, given a set of cities and the distances between each pair of cities, the goal is to find the shortest possible route that visits each city exactly once and returns to the starting city.
TSP is NP-Complete
The Traveling Salesman Problem is also NP-complete. This can be shown by reducing the Hamiltonian cycle problem to TSP.
Reduction from Hamiltonian Cycle to TSP
Given a graph , we construct a complete graph and define edge lengths:
has a Hamiltonian cycle if and only if the optimal TSP tour in with length function has a total length of 0.
Inapproximability of TSP
Unless P=NP, there is no polynomial-time -approximation algorithm for the general TSP for any constant . This means finding even an approximate solution within a constant factor of the optimal solution is also hard in general.
Metric Traveling Salesperson Problem: A Practical Approximation
While the general Traveling Salesperson Problem (TSP) is notoriously hard to solve optimally (NP-complete and even hard to approximate), a practically relevant special case arises when the distances between cities satisfy the triangle inequality. This special case is known as the Metric TSP, and it admits efficient approximation algorithms.
Triangle Inequality
In the Metric TSP, the distance function is required to satisfy the triangle inequality: for any three cities , the following holds:
This condition is quite natural in many real-world scenarios, such as road networks or Euclidean distances, where the direct path between two points is always no longer than any detour.
2-Approximation Algorithm for Metric TSP
For the Metric TSP, we can efficiently find a tour that is guaranteed to be no more than twice as long as the optimal tour. This is achieved using a clever 2-approximation algorithm based on Minimum Spanning Trees (MST).
Here are the steps of the 2-approximation algorithm:
-
Compute Minimum Spanning Tree (MST): Construct a Minimum Spanning Tree for the complete graph with edge weights given by the distance function . Efficient algorithms like Kruskal’s or Prim’s algorithm can compute an MST in polynomial time.
- Key Property: The total weight of the MST, , provides a lower bound on the length of the optimal TSP tour, . This is because any TSP tour must span all vertices, and removing any edge from a tour yields a spanning path, which is no shorter than a spanning tree. Therefore, .
-
Double the Edges: Create a multigraph by duplicating every edge in the MST . In , for every edge in , there are now two parallel edges connecting the same vertices.
- Why Doubling? Doubling the edges ensures that every vertex in has an even degree. Since is a tree, and we add each edge twice, the degree of each vertex in becomes twice its degree in . If a vertex had degree in , it will have degree in , which is always even.
-
Find an Eulerian Tour: Since every vertex in the multigraph has an even degree and is connected (because is a spanning tree), contains an Eulerian tour . We can find such a tour efficiently using Hierholzer’s algorithm in time proportional to the number of edges in , which is since has edges.
- Eulerian Tour Properties: An Eulerian tour traverses every edge of exactly once. The total length of the Eulerian tour , , is simply twice the length of the MST, , as we have doubled every edge. Therefore, . Combining this with the MST lower bound, we get .
-
Shortcut the Eulerian Tour: Traverse the Eulerian tour . As we traverse, create a new tour (Hamiltonian cycle) by “shortcutting” any vertex that has already been visited. Whenever we are about to visit a vertex that is already in , we skip to the next unvisited vertex in that has not yet been added to .
- Why Shortcutting Works (Triangle Inequality): The triangle inequality guarantees that shortcutting does not increase the tour length. Suppose in the Eulerian tour we have a sequence of vertices … , where and are already in our Hamiltonian cycle , and are vertices already visited in or are vertices we have already visited in this traversal of to construct . Instead of going from to , then to , …, to , we directly jump from to . By the triangle inequality: . Therefore, shortcutting can only decrease or maintain the total tour length.
After shortcutting the Eulerian tour , we obtain a Hamiltonian cycle . The length of this cycle, , will be less than or equal to the length of the Eulerian tour , due to the triangle inequality in the shortcutting step. Since , we have:
This shows that the algorithm provides a 2-approximation for the Metric TSP, meaning the tour we find is at most twice as long as the optimal tour.
Matchings in Graphs: Finding Optimal Pairings
Matchings in graphs are fundamental structures in graph theory with wide applications, such as assignment problems, network flow, and combinatorial optimization. A matching represents a set of edges where no two edges share a vertex, effectively pairing up vertices in the graph.
Definitions: Types of Matchings
Let be a graph.
-
Matching (): A subset of edges such that no two edges in are incident to the same vertex. Formally, for any two distinct edges and , we must have .
-
Vertex Covered by a Matching: A vertex is said to be covered (or matched) by a matching if there exists an edge that is incident to .
-
Perfect Matching: A matching is called a perfect matching if every vertex in is covered by . A perfect matching pairs up all vertices in the graph. For a perfect matching to exist, the graph must have an even number of vertices, and .
-
Inclusion-Maximal Matching: A matching is inclusion-maximal if no more edges can be added to while still maintaining the matching property. In other words, for any edge , is no longer a matching because would share a vertex with an edge already in .
-
Cardinality-Maximal Matching (Maximum Matching): A matching is cardinality-maximal (or simply maximum) if it has the largest possible number of edges among all possible matchings in . There can be multiple maximum matchings in a graph. A maximum matching is always inclusion-maximal, but the converse is not necessarily true.
Greedy Algorithm for Inclusion-Maximal Matching
A simple and efficient way to find an inclusion-maximal matching is using a greedy approach.
GREEDY-MATCHING(G):
- Initialization: Start with an empty matching .
- Iterate While Edges Exist: While there are still edges in the graph : a. Select an Edge: Choose any arbitrary edge . b. Add to Matching: Include the chosen edge in the matching: . c. Remove Conflicting Edges: Remove the edge and all edges in that are incident to either vertex or vertex . This ensures that no vertex is incident to more than one edge in .
- Return Matching: Once no more edges can be added, return the matching .
Time Complexity: The greedy algorithm runs in time. In each iteration of the while
loop, at least one edge is added to and at least one edge is removed from . The operations inside the loop (choosing an edge, adding to , removing incident edges) can be performed efficiently.
Approximation Ratio: While the greedy algorithm finds an inclusion-maximal matching, it is not guaranteed to find a maximum matching. However, it provides a 2-approximation for the size of the maximum matching. Let be the matching found by the greedy algorithm and be a maximum matching in . Then, it is guaranteed that:
Justification: Consider any edge in the maximum matching . If we consider the edges in one by one, for each edge , either is added to or one of its endpoints, or , must have been covered by an edge already in . This is because if neither nor was covered when we considered , the greedy algorithm would have picked (or some edge that covers or at that point). Therefore, for every edge in , at least one of its endpoints is covered by an edge in . Since each edge in can cover at most two endpoints of edges in , we get the 2-approximation ratio.
Augmenting Paths: Towards Maximum Matchings
To find a maximum matching (not just an inclusion-maximal one), we can use the concept of augmenting paths.
Definition of -Augmenting Path
Given a matching in a graph , an -augmenting path is a simple path in with the following properties:
- Alternating Path: The edges of alternately belong to the matching and not to the matching . That is, if we traverse the path, the edges are in the sequence: not in , in , not in , in , … or in , not in , in , not in , …
- Starts and Ends at Unmatched Vertices: Both endpoints of the path are unmatched vertices with respect to . This means neither endpoint is incident to any edge in .
Intuition Behind Augmenting Paths
Imagine you have a matching that is not maximum. This means there’s room to add more edges to the matching to increase its size. An augmenting path provides a systematic way to do this. Think of it as a “bottleneck” in your current matching.
An augmenting path is a path that starts and ends at vertices that are currently unmatched. It then cleverly alternates between edges that are in your current matching and edges that are not in your current matching.
When you find an augmenting path, you can “flip” the status of the edges along the path. Edges that were not in the matching become part of the matching, and edges that were in the matching are removed from the matching. This “flipping” action, known as augmentation, has a crucial effect: it increases the size of the matching by exactly one.
The reason the matching size increases is that an augmenting path always has one more edge outside the original matching than edges inside the original matching. Since it starts and ends with unmatched vertices and alternates edge types, a path of length will have edges not in and edges in .
The Symmetric Difference of Matchings: Visualizing Augmenting Paths
To understand why augmenting paths must exist if a matching is not maximum, consider two matchings: a non-maximum matching and a maximum matching . Let’s examine their symmetric difference, denoted as .
The symmetric difference is the set of edges that are in either or , but not in both. In set notation: .
Consider the subgraph formed by the edges in . Let’s analyze the properties of this subgraph:
-
Vertex Degree: In the subgraph formed by , each vertex has a degree of at most 2. This is because each vertex is incident to at most one edge in and at most one edge in . Therefore, in the symmetric difference, the degree can be at most .
-
Path and Cycle Decomposition: Since each vertex degree is at most 2, the connected components of the subgraph formed by must be either paths or cycles.
-
Alternating Paths and Cycles: Because we are considering the symmetric difference of two matchings, every path and cycle in will have edges that alternate between belonging to and . Imagine traversing a path or cycle; you’ll see an edge from , then one from , then from , and so on.
Now, let’s assume that the size of the maximum matching is strictly greater than the size of the non-maximum matching , i.e., . This means the symmetric difference must contain more edges from than from .
Consider the paths and cycles in the decomposition of . Since there are more edges from than from in total, there must be at least one connected component (either a path or a cycle) that contains more edges from than from .
-
Cycles: Cycles in must have an equal number of edges from and (because they alternate). Therefore, cycles cannot contribute to an imbalance in edge counts between and .
-
Paths: For the total count of edges to exceed the count of edges in , there must exist at least one path component that has more edges from than from . For an alternating path to have more edges, it must start and end with edges from . Since the edges alternate, this means the path must start and end with edges from and therefore start and end at vertices that are matched by but not matched by . But if they are not matched by , and the path starts with an edge, and alternates, it means the start and end vertices of this path must be unmatched by .
Therefore, if , there must exist at least one path in that starts and ends at vertices unmatched by , and whose edges alternate between and , starting and ending with edges from . This path is precisely an -augmenting path.
The symmetric difference provides a conceptual tool. It decomposes into paths and cycles, and by analyzing these components, particularly in the case where , we can logically deduce the existence of an -augmenting path, which is the key to improving the matching .
Berge’s Theorem: Characterizing Maximum Matchings
Berge’s Theorem provides a fundamental characterization of maximum matchings in terms of augmenting paths.
Theorem (Berge, 1957): A matching in a graph is a cardinality-maximal matching (maximum matching) if and only if there is no -augmenting path in .
This theorem is crucial because it gives us a way to check if a matching is maximum and a strategy to increase the size of a non-maximum matching if an augmenting path exists.
Augmenting Path Algorithm for Maximum Matching
Berge’s Theorem leads to a general algorithm for finding a maximum matching:
- Start with Initial Matching: Begin with any matching , for instance, an empty matching or a matching obtained by the greedy algorithm.
- Search for Augmenting Path: Search for an -augmenting path in .
- Check for Existence:
- If no -augmenting path exists: Then, by Berge’s Theorem, the current matching is a maximum matching. Return .
- If an -augmenting path is found: Augment the matching. The operation to augment the matching is to take the symmetric difference of the matching and the edges of the augmenting path : . This effectively “flips” the status of edges along the augmenting path: edges in are removed from the matching, and edges in are added to the matching. This operation increases the size of the matching by exactly one, .
- Repeat: Go back to step 2 with the augmented matching .
This iterative process continues until no more augmenting paths can be found, at which point the matching is guaranteed to be maximum.
Finding Augmenting Paths and Time Complexity
The efficiency of the augmenting path algorithm depends on how efficiently we can search for an augmenting path in step 2.
-
Bipartite Graphs: In bipartite graphs, augmenting paths can be found efficiently using Breadth-First Search (BFS). The time complexity to find an augmenting path in a bipartite graph is . Since the number of augmentations is at most (because the matching size increases by 1 in each augmentation and is bounded by for bipartite graphs), the overall time complexity for finding a maximum matching in a bipartite graph using augmenting paths and BFS is .
-
General Graphs: In general (non-bipartite) graphs, finding augmenting paths is more complex due to the possibility of odd cycles (“blossoms”). Edmonds’ Blossom algorithm is a more sophisticated algorithm to find augmenting paths in general graphs. It has a time complexity of per augmentation, leading to an overall complexity of or with more refined implementations.
Hall’s Marriage Theorem: Existence of Perfect Matchings in Bipartite Graphs
Hall’s Marriage Theorem provides a necessary and sufficient condition for the existence of a matching that covers all vertices on one side of a bipartite graph.
Hall’s Condition
Let be a bipartite graph with bipartition . Hall’s condition states that for every subset of , the size of the neighborhood of , , must be at least as large as the size of :
Theorem Statement
Hall’s Marriage Theorem: Let be a bipartite graph with bipartition . There exists a matching in that saturates (meaning every vertex in is matched by , so ) if and only if Hall’s condition holds:
Hall’s Condition: For every subset of , the size of the neighborhood of , denoted as , must be greater than or equal to the size of :
This theorem is fundamental in matching theory and has numerous applications. The “Marriage” analogy helps to understand the condition: imagine set as a set of men and set as a set of women, and an edge exists if a man and a woman are compatible. Hall’s Theorem tells us when it’s possible to marry off every man in to a compatible woman in , ensuring no woman is married to more than one man.
Proof of Hall’s Marriage Theorem using Induction on
We will prove Hall’s Marriage Theorem using induction on the size of set , denoted by .
Direction (): Necessity of Hall’s Condition
First, we show that if a matching saturating exists, then Hall’s condition must hold. Assume there is a matching that saturates . Consider any subset . Let be the set of edges in that are incident to vertices in . Since saturates , for each vertex , there is a unique edge in incident to it. Let be the set of vertices in that are matched to vertices in by . Since is a matching, . Furthermore, every vertex in is a neighbor of some vertex in , so . Therefore, , which shows that Hall’s condition holds.
Direction (): Sufficiency of Hall’s Condition
Now, we need to prove the converse: if Hall’s condition holds, then there exists a matching that saturates . We will use induction on .
Base Case:
Let . Hall’s condition for requires , which simplifies to . This means vertex must have at least one neighbor in . If is not empty, we can choose any neighbor and form a matching . This matching saturates , and the base case is established.
Inductive Hypothesis:
Assume that Hall’s Marriage Theorem holds for all bipartite graphs where . That is, if and satisfies Hall’s condition with respect to , then contains a matching that saturates .
Inductive Step: Consider
We need to show that if with satisfies Hall’s condition, then contains a matching that saturates . We consider two exhaustive cases that cover all possibilities, based on the “tightness” of Hall’s condition for subsets of .
Continue here: 05 Matchings in Bipartite Graphs