Discrete StructureUnit 109 min read
Graph Matching, Coloring, and Advanced Paths
Unit 10 of Discrete Structure explores advanced graph theory concepts—matching (perfect, maximum), graph coloring (chromatic number, greedy algorithms), and advanced path problems (Eulerian/Hamiltonian cycles)—with real-world applications in scheduling, network design, and optimization.
TAKEAWAYS:
- Matching pairs vertices optimally (e.g., assigning tasks to workers), with perfect matchings requiring even-sized graphs.
- Graph coloring minimizes colors for conflict-free assignments (e.g., exam scheduling, frequency allocation).
- Eulerian/Hamiltonian cycles solve route optimization (e.g., postal delivery, circuit design) but require specific degree conditions.
- Greedy algorithms provide fast (but not always optimal) colorings, while backtracking ensures correctness.
- Applications span logistics (Pathao routes), social networks (friend recommendations), and infrastructure (NTC network planning).
1. Graph Matching: Pairing Vertices
Definition: A matching in a graph is a set of edges where no two edges share a vertex. A perfect matching covers every vertex.
Key Concepts
- Maximum Matching: Largest possible matching in .
- Perfect Matching: Every vertex is included (only possible if is even).
- Bipartite Matching: Matching in bipartite graphs (e.g., job assignments).
How It Works
- Greedy Matching: Iteratively add edges, skipping vertices already matched.
- Augmenting Paths: For bipartite graphs, use the Ford-Fulkerson method to find maximum matchings.
Worked Example: Job Assignments
Scenario: A company has 4 workers and 4 tasks. Assign tasks to maximize productivity (edges = compatibility).
graph LR
A["Worker 1"] -- 5 --> B["Task 1"]
A -- 3 --> C["Task 2"]
B -- 4 --> D["Worker 2"]
C -- 6 --> D
D -- 2 --> E["Worker 3"]
E -- 7 --> F["Task 3"]
F -- 1 --> G["Worker 4"]
G -- 8 --> H["Task 4"]Solution:
- Maximum matching: (score = 5 + 6 + 7 + 8 = 26).
- Perfect matching exists since is even.
Real-World Tie-In:
- Pathao Driver Assignments: Match drivers to ride requests (vertices = drivers/requests; edges = distance/time compatibility). A perfect matching ensures all requests are fulfilled without overlap.
2. Graph Coloring: Minimizing Conflicts
Definition: Assign colors to vertices so no adjacent vertices share a color. The chromatic number is the smallest number of colors needed.
Key Concepts
- Greedy Coloring: Assign the lowest available color to each vertex in order.
- Chromatic Number:
- if has no edges.
- if is bipartite.
- (Brooks’ Theorem, where is the maximum degree).
- Planar Graphs: (Four Color Theorem).
Worked Example: Exam Scheduling
Scenario: Schedule 4 exams (A, B, C, D) with conflicts:
graph TD
A["Exam A"] --> B["Exam B"]
A --> C["Exam C"]
B --> D["Exam D"]
C --> DGreedy Coloring (order: A → B → C → D):
- A: Color 1
- B: Adjacent to A → Color 2
- C: Adjacent to A → Color 2 (but conflicts with B’s color). Use Color 3.
- D: Adjacent to B and C → Color 1. Result: 3 colors used ().
Real-World Tie-In:
- NTC Frequency Allocation: Assign radio frequencies to base stations so adjacent towers don’t interfere (color = frequency). Greedy coloring minimizes spectrum waste.
- Khalti Transaction Scheduling: Color transactions by time slots to avoid conflicts in ledger updates.
3. Eulerian and Hamiltonian Cycles
Eulerian Cycle
Definition: A cycle that visits every edge exactly once. Conditions:
- All vertices have even degree.
- Graph is connected.
Worked Example: Postal Delivery Scenario: Deliver mail to 5 houses (vertices) with roads (edges). Can the postman return to the start without retracing?
graph TD
A["House 1"] -- 1 --> B["House 2"]
A -- 1 --> C["House 3"]
B -- 1 --> C
B -- 1 --> D["House 4"]
C -- 1 --> D
D -- 1 --> E["House 5"]
E -- 1 --> AAnalysis:
- Degrees: A(3), B(3), C(3), D(3), E(3). No Eulerian cycle (all degrees odd).
- Solution: Add a duplicate edge (e.g., A–B) to make degrees even. Now an Eulerian cycle exists.
Real-World Tie-In:
- Ncell Network Routing: Optimize signal tower paths for maintenance trucks to minimize backtracking.
Hamiltonian Cycle
Definition: A cycle that visits every vertex exactly once. Conditions: No simple necessary/sufficient conditions (NP-Hard to check). Worked Example: Traveling Salesman Scenario: Visit 4 cities (A, B, C, D) with distances:
graph TD
A -- 10 --> B
A -- 15 --> C
A -- 20 --> D
B -- 35 --> C
B -- 25 --> D
C -- 30 --> DPossible Cycle: A → B → D → C → A (total distance = 10 + 25 + 30 + 15 = 80). Real-World Tie-In:
- Daraz Delivery Routes: Find the shortest cycle to deliver orders to 5 warehouses (Hamiltonian path ≈ TSP).
4. Advanced Applications
| Problem | Graph Model | Real-World Example | Solution Approach |
|---|---|---|---|
| Bipartite Matching | Two disjoint vertex sets | Job applicants → job openings (Khalti) | Ford-Fulkerson algorithm |
| Vertex Coloring | Conflicts as edges | Exam scheduling (TU exams) | Greedy or backtracking |
| Eulerian Path | Even-degree vertices | NTC cable laying | Hierholzer’s algorithm |
| Hamiltonian Path | All vertices visited once | Pathao driver efficiency | Brute-force (small graphs) |
5. Algorithms Summary
| Algorithm | Purpose | Time Complexity | When to Use |
|---|---|---|---|
| Greedy Coloring | Minimize colors | Quick estimates (e.g., exams) | |
| Ford-Fulkerson | Maximum bipartite matching | Job assignments, network flows | |
| Hierholzer’s | Find Eulerian cycle | Postal routes, circuit design | |
| Backtracking | Exact graph coloring/Hamiltonian path | Exponential | Small graphs (e.g., <20 vertices) |
In the Real World
Pathao’s Ride Matching:
- Uses bipartite matching to pair drivers (one set) with ride requests (other set) based on location and time. The algorithm maximizes matches without overlaps, similar to the job assignment example above.
- Key Idea: Maximum bipartite matching ensures no driver is idle while requests pile up.
NTC’s Network Planning:
- Graph coloring assigns frequencies to base stations so adjacent towers (connected by edges) use different colors (frequencies). This avoids interference, directly applying the chromatic number concept.
- Worked Example: If two towers are 10 km apart (edge exists), they must use different frequencies (colors). NTC uses greedy coloring for initial planning and backtracking to refine.
Daraz’s Warehouse Logistics:
- Hamiltonian paths optimize delivery routes between warehouses. While exact solutions are NP-Hard, Daraz uses heuristic algorithms (e.g., nearest-neighbor) to approximate paths, reducing fuel costs.
- Real Scenario: For 5 warehouses in Kathmandu, a Hamiltonian path might visit them in order: Thapathali → Bhotahiti → Kageshwori → Lagankhel → Chabahil → Thapathali, minimizing total distance.
Exam Tip
Matching Questions:
- For perfect matchings, always check if is even.
- For bipartite graphs, use the adjacency matrix and Ford-Fulkerson to find maximum matchings.
- Common Pitfall: Forgetting to verify if a matching is perfect (all vertices included).
Graph Coloring:
- Greedy coloring is easy to implement but may not give the chromatic number. Mention its time complexity.
- For planar graphs, recall the Four Color Theorem () and use it to bound answers.
- Exam Trick: If a graph is bipartite, . Check for odd cycles to confirm.
Eulerian/Hamiltonian:
- Eulerian: Focus on degrees. If all are even, a cycle exists. If two are odd, a path exists.
- Hamiltonian: No shortcut—state conditions (e.g., complete graphs have Hamiltonian cycles) and whether the problem is NP-Hard.
- Worked Example: For the postal delivery problem, always draw the graph and count degrees first.
Applications:
- Link abstract problems to real scenarios (e.g., "This is like Pathao’s driver assignment" or "Like NTC’s frequency planning").
- Use Mermaid diagrams to visualize graphs in answers—examiners reward clarity.
Proofs and Counting:
- For inductive proofs (e.g., Brooks’ Theorem), show the base case and assume for vertices, then prove for .
- For counting matchings, use the adjacency matrix and permanent (though this is advanced). Stick to small examples.
Based on the TU BIM syllabus for Discrete Structure (IT235), unit 10.
Discussion
Loading…