Discrete StructureUnit 108 min read
Special Graph Topics: Matching, Coloring, Flows & Cryptography
Unit 10 of Discrete Structure covers advanced graph theory topics—matching (perfect, maximum), graph coloring (chromatic number, greedy algorithms), network flows (Ford-Fulkerson, max-flow min-cut), and cryptography (RSA, graph-based ciphers)—with real-world applications in scheduling, routing, and secure communication
TAKEAWAYS:
- Matching pairs vertices optimally (e.g., stable marriage problems) and can be solved via augmenting paths in bipartite graphs.
- Graph coloring minimizes colors for vertex/edge coloring (e.g., map coloring, exam scheduling) using greedy or backtracking algorithms.
- Network flows model resource allocation (e.g., traffic, data packets) with max-flow/min-cut theorem as the core principle.
- Cryptography uses modular arithmetic (RSA) and graph theory (e.g., error-correcting codes) to secure digital communications.
- Planar graphs and Euler’s formula () solve real-world layout problems (e.g., circuit boards, city planning).
- Applications span logistics (Pathao’s route optimization), finance (NEPSE’s transaction networks), and tech (Google’s PageRank).
1. Matching in Graphs
Definition: A matching is a set of edges without common vertices. A perfect matching covers all vertices; a maximum matching is the largest possible.
Key Concepts
- Bipartite Graphs: Graphs with two disjoint vertex sets and . Matching here is called bipartite matching.
- Augmenting Path: A path alternating between matched and unmatched edges, used to find larger matchings.
- Hall’s Marriage Theorem: A bipartite graph has a perfect matching iff for every subset , , where is the neighborhood of .
Example: Stable Marriage Problem
Scenario: Match men to women based on preferences (e.g., Daraz’s order-pairing system). Algorithm: Gale-Shapley’s algorithm (propose-reject cycle). Visual:
graph LR
M1["Man 1"] -->|"proposes"| W1["Woman 1"]
M1 -->|"proposes"| W2["Woman 2"]
W2 -->|"rejects"| M1
M1 -->|"proposes"| W3["Woman 3"]
W3 -->|"accepts"| M1Worked Example: Given preferences:
- Men: , , .
- Women: , , . Steps:
- proposes to → matched.
- proposes to → matched.
- proposes to → matched. Result: Perfect matching .
2. Graph Coloring
Definition: Assign colors to vertices/edges so no adjacent vertices/edges share the same color. The chromatic number is the minimum colors needed.
Types
| Type | Definition | Example |
|---|---|---|
| Vertex Coloring | Colors assigned to vertices. | Map coloring (countries). |
| Edge Coloring | Colors assigned to edges. | Scheduling (conflict-free slots). |
| Face Coloring | Colors assigned to regions (planar graphs). | VLSI design. |
Algorithms
- Greedy Coloring: Assign the smallest available color to each vertex in order.
Pseudocode:
def greedy_coloring(G): color = {} for u in sorted(G.vertices): used = {color[v] for v in G.adj[u] if color[v] is not None} color[u] = min(set(range(1, len(G.vertices)+1)) - used) return color - Backtracking: Try all color assignments recursively (used for small graphs).
Real-World Example: Exam Scheduling (TU)
Problem: Schedule exams for 5 courses with 3 time slots, minimizing conflicts. Graph: Vertices = courses, edges = conflicts. Solution: (minimum slots needed). Visual:
graph TD
C1["Course 1"] --> C2["Course 2"]
C1 --> C3["Course 3"]
C2 --> C4["Course 4"]
C3 --> C4
C4 --> C5["Course 5"]Coloring: Assign slots 1, 2, 3 to avoid conflicts.
3. Network Flows
Definition: A flow network is a directed graph with:
- Capacity for each edge .
- Flow satisfying:
- (capacity constraint).
- Flow conservation: for all (source/sink).
Key Theorems
- Max-Flow Min-Cut Theorem: The maximum flow equals the capacity of the minimum cut.
- Ford-Fulkerson Algorithm: Iteratively find augmenting paths to increase flow.
Example: Traffic Routing (NTC)
Scenario: Route data packets from source to sink with limited bandwidth. Graph:
graph LR
s["Source"] -->|"10"| A["Router 1"]
s -->|"5"| B["Router 2"]
A -->|"8"| t["Sink"]
B -->|"6"| t
A -->|"4"| BMax Flow Calculation:
- Path : flow = 8 (bottleneck).
- Path : flow = 5.
- Path : flow = 4 (residual capacity). Total Max Flow: .
4. Cryptography and Graph Theory
Graph-Based Ciphers:
- Error-Correcting Codes: Represented as graphs (e.g., Hamming codes for data transmission).
- RSA Encryption: Relies on modular arithmetic (graph of primes and Euler’s totient function ).
RSA Worked Example
Keys:
- Public: , where (primes), is coprime with .
- Private: .
Encryption: Decryption:
Example:
- , , , .
- Choose (coprime with 40), (since ).
- Encrypt :
- Decrypt:
Visual:
graph TD
M["Plaintext"] -->|"Encrypt"| C["Ciphertext"]
C -->|"Decrypt"| M5. Planar Graphs and Euler’s Formula
Definition: A graph is planar if it can be drawn without edge crossings. Euler’s Formula: For connected planar graphs, where = vertices, = edges, = faces.
Applications
- VLSI Design: Circuit layouts (e.g., NTC’s network topology).
- Map Coloring: Four Color Theorem (every planar graph is 4-colorable).
Example: Wheel Graph
Vertices: 4 outer + 1 center. Edges: 4 outer + 4 spokes. Planarity Check: , , (satisfies ). Spanning Trees: Use Kirchhoff’s theorem (delete one edge, count trees in remaining graph).
In the Real World
Pathao’s Route Optimization:
- Matching: Pairs drivers with passengers using bipartite matching (maximizing rides per hour).
- Graph Coloring: Assigns time slots to drivers to avoid traffic overlaps (vertex coloring).
NEPSE’s Transaction Network:
- Network Flows: Models share trading as flows between buyers/sellers, ensuring max transactions without overloading servers.
Khalti’s Fraud Detection:
- Graph Theory: Builds transaction graphs to detect anomalies (e.g., sudden high-degree vertices = fraudulent activity).
Google’s PageRank:
- Directed Graphs: Web pages as nodes, links as edges. PageRank uses eigenvectors to rank importance (similar to max-flow algorithms).
Exam Tip
Matching:
- For bipartite graphs, always check Hall’s condition before applying algorithms.
- In proofs, draw the graph and highlight augmenting paths.
Graph Coloring:
- Greedy coloring is easy to implement but may not yield the chromatic number. Mention its limitation in exams.
- For planar graphs, cite the Four Color Theorem if asked about coloring maps.
Network Flows:
- Memorize the max-flow min-cut theorem—it’s the core of flow problems.
- In exams, label residual capacities clearly when applying Ford-Fulkerson.
Cryptography:
- RSA: Focus on the modular arithmetic steps (encryption/decryption formulas).
- Graph-based codes: Link to error correction (e.g., "Hamming codes use graph distance to detect errors").
Planar Graphs:
- Euler’s formula is tested often—derive it from a simple planar graph (e.g., a triangle) in proofs.
- For spanning trees, use Kirchhoff’s theorem (delete edges, count trees) but show the matrix method if time permits.
Visual Summary:
mindmap
root((Special Graph Topics))
Matching
Bipartite Graphs
Augmenting Paths
Hall's Theorem
Coloring
Vertex/Edge Coloring
Greedy Algorithm
Chromatic Number
Network Flows
Ford-Fulkerson
Max-Flow Min-Cut
Cryptography
RSA
Graph Codes
Planar Graphs
Euler's Formula
Spanning TreesBased on the TU BITM syllabus for Discrete Structure (IT235), unit 10.
Discussion
Loading…