This action might not be possible to undo. Are you sure you want to continue?

BooksAudiobooksComicsSheet Music### Categories

### Categories

### Categories

### Publishers

Scribd Selects Books

Hand-picked favorites from

our editors

our editors

Scribd Selects Audiobooks

Hand-picked favorites from

our editors

our editors

Scribd Selects Comics

Hand-picked favorites from

our editors

our editors

Scribd Selects Sheet Music

Hand-picked favorites from

our editors

our editors

Top Books

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Audiobooks

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Comics

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Sheet Music

What's trending, bestsellers,

award-winners & more

award-winners & more

P. 1

Graph Theory & Algorithms - M. Ashraf Iqbal|Views: 6,293|Likes: 54

Published by Abdul Rehman Naeem

Graph Theory & Algorithms - M. Ashraf Iqbal

Graph Theory & Algorithms - M. Ashraf Iqbal

See more

See less

https://www.scribd.com/doc/55797032/Graph-Theory-Algorithms-M-Ashraf-Iqbal

10/11/2013

text

original

- Introduction
- 1.1 Why a new book?
- 1.2 What do we emphasize?
- 1.3 How the book is organized?
- 1.4 How is the book designed?
- 1.5 Some salient features of the book
- 1.6 What tools do we use?
- 1.7 A Possible Sequence
- 3.1 Introduction
- 3.2 Reducing One Problem into Another
- 3.3 The Satisﬁability Problem in Logic Cir-
- 3.3.1 Reducing a 3-SAT Problem into an Independent
- 3.3.2 Reducing the 3-CNF Satisﬁability Problem into
- the 3-DNF Satisﬁability Problem
- 3.3.3 Reducing the 3-CNF Satisﬁability Problem into
- 3.3.4 Reducing the 2-CNF Satisﬁability Problem into
- 3.4 An Activity Scheduling Problem
- 3.5 A Dual Machine Serial Processing Envi-
- 3.7 Discussion & Problems
- Basics of Graph Theory
- 4.1 Introduction
- 4.2 A Mutual Friendship Graph
- 4.3 Representation of a Graph
- 4.4 Complement of a Graph
- 4.5 Equal Graphs & Isomorphic Graphs
- 4.6 The Degree Sequence
- 4.7 Walks, Trails, & Paths
- 4.8 Multi-graphs and Pseudo-graphs
- 4.9 Broad Categories of Graphs & some Spe-
- 4.9.1 Tree Graphs
- 4.9.2 Bipartite Graphs
- 4.9.3 Special Graphs
- 4.11 Self Complementing Graphs
- 4.11.1 Regular Self Complementing graphs
- 4.11.2 Non Regular Self Complementing graphs
- 4.11.3 Constructing Self Complementary Graphs
- into another SC graph with 4k vertices
- 4.11.5 Transforming a SC graph with 4k vertices into
- another SC graph with 4k + 1 vertices
- 4.11.6 The Self Complementary problem and Graph
- 4.11.7 A SC graph has diameter 2 or 3 - not less than
- 4.11.8 Bipartite self complementary graphs
- 4.11.9 Decomposition of a SC graph G
- Basics of Graph Algorithms
- 5.1 Design of Algorithms
- 5.1.1 What is Design?
- 5.1.2 The Moore Method
- 5.2 The Bucket Algorithm
- 5.2.1 Understanding the Bucket Algorithm
- 5.2.2 How does it Work?
- 5.2.3 Playing with the Algorithm
- 5.2.4 Solving Other Problems
- 5.2.5 The Right Provocation
- 5.3 Finding if a Graph is Connected
- 5.3.1 The Number of Connected Components
- 5.3.2 Finding a Bridge in a Graph
- 5.4 Finding if a Graph is a Tree
- 5.4.1 Every Edge in a Tree is a Bridge
- 5.4.2 The Number of Edges in a Graph
- 5.4.3 The Spanning Tree of a Tree
- 5.4.4 A Comparison
- 5.5 Finding a Spanning Tree of a Graph
- 5.5.1 Cutting Edges
- 5.5.2 Growing Edges
- 5.5.3 Selecting Edges
- 5.5.4 Integrating Concepts and Discovering Algorithms
- 5.6.1 Cutting or Growing Edges: A Krushkal’s like
- 5.6.2 Selecting Edges: A Prim’s like greedy Algorithm
- 5.6.3 A Panoramic Picture of various MST Finding
- 5.6.4 The Maximum Spanning Tree Problem
- 5.7 Finding a Path in a Graph
- 5.7.1 Cutting Edges
- 5.7.2 Selecting Edges
- 5.8 The Shortest Path Problem
- 5.8.1 Dijkstra’s (like) Algorithm
- 5.8.2 Discussion on Dijkstra’s (like) Algorithm
- edge Shortest Path Problem
- 5.8.4 The k-edge Longest Path Problem
- 5.8.5 The Shortest Path Problem in Undirected Graphs
- We consider the shortest path problem in undirected graphs with negative
- 5.9 Graph Traversal Techniques
- 5.9.1 Traditional Techniques & the Bucket-Algorithm
- 5.9.2 The Underlying Data Structure
- 5.10 Some Graph Theoretic Claims
- 5.11 Shortest Path Algorithms
- 5.11.2 Single Source Shortest Path Algorithms for Di-
- 5.11.3 Single Source Shortest Path Algorithms for di-
- rected graphs with negative edge weights
- 5.11.4 All Pair Shortest Path Algorithms
- The Slow All Pair shortest Path Algorithm
- 5.11.5 Johnson’s all Pair Shortest Path Algorithm
- 5.12 Discussion
- 6.1 Introduction
- 6.2 Deﬁnitions & Prior Knowledge
- 6.4 Menger’s Theorem
- 6.4.1 Maximum Edge-Disjoint Paths in Directed Graphs
- 6.4.2 The Concept of a Minimum Cut in Directed Graphs
- 6.4.3 A Proof of Menger’s Theorem and Finding the
- Minimum Cut in Directed Graphs
- 6.4.4 Finding Maximum Vertex-Disjoint Paths & Min-
- imum Vertex Cut in Directed Graphs
- 6.4.5 Menger’s Theorem for Undirected Graphs
- 6.4.6 Edge Connectivity and Vertex Connectivity for
- Undirected Graphs
- 6.6 Network Flows
- 6.6.1 Finding Maximum Edge-Disjoint Paths in Multi-
- 6.6.2 The Maximum Flow & the Minimum Cut
- 6.6.3 Algorithmic Issues & Complexity Calculations
- 6.6.4 Lower Bounds on Edge Flows and the Max-Cut
- 6.7 The Matching Problem in Bipartite Graphs
- matching in un-weighted bipartite graphs and weighted maximum match-
- 6.7.1 Maximum Matching in Un-weighted bipartite graphs
- 6.7.2 Maximum Matching in Complete (Binary) Weighted
- Bipartite Graphs
- The Max-Flow Min-Cost Problem 345
- 6.8 The Max-Flow Min-Cost Problem
- 6.8.1 Introduction
- The Max-Flow Min-Cost Problem
- 6.8.2 Finding a Maximum Flow or Finding a Shortest
- 6.8.3 Category 3 network ﬂow Problems
- 6.8.4 Category 2 (and 1) network ﬂow Problems
- 6.8.5 A Panoramic Picture of Similar Problems & So-
- 6.9.1 Prior knowledge:
- 6.9.2 New concepts
- 6.9.3 New Problems
- 6.9.4 Finding a feasible ﬂow in a Circulation graph
- 6.9.5 Finding a feasible ﬂow in a network ﬂow graph
- 6.9.6 When upper bound is higher than a non zero
- 6.9.7 Is it possible to solve the Circulation Problem
- 7.1 A Special Class of Graphs
- 7.2 Eulerian Circuits and Graphs
- 7.3 Eulerian Trails and Related Problems
- Eulerian Walk and the Chinese Postman Problem 397
- 7.4 Eulerian Walk and the Chinese Postman
- Hamiltonian Graphs
- 8.1 Introduction
- 8.2 Prior Knowledge
- 8.2.1 Necessary Conditions for a Connected Graph
- 8.2.2 Necessary Conditions for a Hamiltonian Graph
- 8.2.3 A Loose Suﬃcient Condition for a Hamiltonian
- 8.2.4 Suﬃcient Condition for a Connected Graph
- 8.2.5 A Concept Map
- 428 Hamiltonian Graphs
- 8.3 Hamiltonian Graphs
- 8.3.1 A Puzzle:
- 8.3.2 Actually Finding a Hamiltonian Cycle in the Puz-
- 8.3.3 Basic Intuition
- 8.3.4 Bondy & Chvatal’s Theorem:
- 8.3.5 Summary
- 8.3.6 Closure of a Graph:
- 8.3.7 Ore’s Theorem:
- 8.4 Bipartite Hamiltonian Graphs
- Some Theoretical Claims 447
- 8.5 Some Theoretical Claims
- 8.6 A Categorization of Hamiltonian Graphs
- 9.1 Concepts, Properties & Actions
- 9.3 Directed Acyclic Graphs (DAG’s)
- Strongly Connected Components 485
- 9.4 Strongly Connected Components
- 9.5 Tournaments
- 9.5.1 A Panoramic Picture and a Concept Map
- 9.5.2 A Hamiltonian Path in a Tournament
- 9.5.3 A Hamiltonian Cycle in a Strong Tournament
- Unilaterally Connected Directed Graphs: 511
- 9.6 Unilaterally Connected Directed Graphs:
- unilaterally connected directed graphs
- 9.6.1 Unilaterally orient-able Un-directed Graphs

Graph Theory and Algorithms

M. Ashraf Iqbal

ii

Copyright c 2010 by M Ashraf Iqbal

All rights reserved.

ISBN . . .

. . . Publications

To my grand daughter Nariman

iv

Contents

1 Introduction 1.1 1.2 1.3 1.4 1.5 1.6 1.7 Why a new book? . . . . . . . . . . . . . . . . . . . . . . . . . What do we emphasize? . . . . . . . . . . . . . . . . . . . . . How the book is organized? . . . . . . . . . . . . . . . . . . . How is the book designed? . . . . . . . . . . . . . . . . . . . . Some salient features of the book . . . . . . . . . . . . . . . . 1 2 3 6 9 9

What tools do we use? . . . . . . . . . . . . . . . . . . . . . . 10 A Possible Sequence . . . . . . . . . . . . . . . . . . . . . . . 10 19 31

2 Basic Deﬁnitions in Graph Theory and Algorithms 3 Problems, Models & Graphs: Why Study Graph Theory? 3.1 3.2 3.3

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Reducing One Problem into Another . . . . . . . . . . . . . . 32 The Satisﬁability Problem in Logic Circuits . . . . . . . . . . 34 3.3.1 3.3.2 3.3.3 Reducing a 3-SAT Problem into an Independent Set Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Reducing the 3-CNF Satisﬁability Problem into the 3DNF Satisﬁability Problem . . . . . . . . . . . . . . . 39 Reducing the 3-CNF Satisﬁability Problem into another graph Problem . . . . . . . . . . . . . . . . . . . 41

vi 3.3.4 3.4 3.5 3.6 3.7

Contents Reducing the 2-CNF Satisﬁability Problem into a Graph Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 41

An Activity Scheduling Problem . . . . . . . . . . . . . . . . . 47 A Dual Machine Serial Processing Environment . . . . . . . . 48 Sequencing by Hybridization in Computational Biology . . . . 57 Discussion & Problems . . . . . . . . . . . . . . . . . . . . . . 62 77

4 Basics of Graph Theory 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 A Mutual Friendship Graph . . . . . . . . . . . . . . . . . . . 78 Representation of a Graph . . . . . . . . . . . . . . . . . . . . 79 Complement of a Graph . . . . . . . . . . . . . . . . . . . . . 82 Equal Graphs & Isomorphic Graphs . . . . . . . . . . . . . . . 83 The Degree Sequence . . . . . . . . . . . . . . . . . . . . . . . 86 Walks, Trails, & Paths . . . . . . . . . . . . . . . . . . . . . . 100 Multi-graphs and Pseudo-graphs . . . . . . . . . . . . . . . . . 102 Broad Categories of Graphs & some Special Graphs . . . . . . 102 4.9.1 4.9.2 4.9.3 Tree Graphs . . . . . . . . . . . . . . . . . . . . . . . . 104 Bipartite Graphs . . . . . . . . . . . . . . . . . . . . . 104 Special Graphs . . . . . . . . . . . . . . . . . . . . . . 104

4.10 Integration of Concepts, Properties, and Action Items . . . . . 112 4.11 Self Complementing Graphs . . . . . . . . . . . . . . . . . . . 114 4.11.1 Regular Self Complementing graphs . . . . . . . . . . . 114 4.11.2 Non Regular Self Complementing graphs . . . . . . . . 119 4.11.3 Constructing Self Complementary Graphs . . . . . . . 121 4.11.4 Transforming a SC graph with 4k + 1 vertices into another SC graph with 4k vertices . . . . . . . . . . . . . 124

Contents

vii

4.11.5 Transforming a SC graph with 4k vertices into another SC graph with 4k + 1 vertices . . . . . . . . . . . . . . 129 4.11.6 The Self Complementary problem and Graph Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 4.11.7 A SC graph has diameter 2 or 3 - not less than 2 and not more than 3? . . . . . . . . . . . . . . . . . . . . . 132 4.11.8 Bipartite self complementary graphs . . . . . . . . . . 136 4.11.9 Decomposition of a SC graph G . . . . . . . . . . . . . 140 4.11.10 Permutation, Isomorphism, automorphism & Self Complementing Graphs . . . . . . . . . . . . . . . . . . . . 142 5 Basics of Graph Algorithms 5.1 153

Design of Algorithms . . . . . . . . . . . . . . . . . . . . . . . 156 5.1.1 5.1.2 What is Design? . . . . . . . . . . . . . . . . . . . . . 157 The Moore Method . . . . . . . . . . . . . . . . . . . . 157

5.2

The Bucket Algorithm . . . . . . . . . . . . . . . . . . . . . . 157 5.2.1 5.2.2 5.2.3 5.2.4 5.2.5 Understanding the Bucket Algorithm . . . . . . . . . . 159 How does it Work? . . . . . . . . . . . . . . . . . . . . 160 Playing with the Algorithm . . . . . . . . . . . . . . . 161 Solving Other Problems . . . . . . . . . . . . . . . . . 161 The Right Provocation . . . . . . . . . . . . . . . . . . 161

5.3

Finding if a Graph is Connected . . . . . . . . . . . . . . . . . 162 5.3.1 5.3.2 The Number of Connected Components . . . . . . . . 163

Finding a Bridge in a Graph . . . . . . . . . . . . . . . 163

5.4

Finding if a Graph is a Tree . . . . . . . . . . . . . . . . . . . 164 5.4.1 5.4.2 5.4.3 Every Edge in a Tree is a Bridge . . . . . . . . . . . . 164 The Number of Edges in a Graph . . . . . . . . . . . . 165 The Spanning Tree of a Tree . . . . . . . . . . . . . . . 165

viii 5.4.4 5.5

Contents A Comparison . . . . . . . . . . . . . . . . . . . . . . . 165

Finding a Spanning Tree of a Graph . . . . . . . . . . . . . . 166 5.5.1 5.5.2 5.5.3 5.5.4 Cutting Edges . . . . . . . . . . . . . . . . . . . . . . . 166 Growing Edges . . . . . . . . . . . . . . . . . . . . . . 166 Selecting Edges . . . . . . . . . . . . . . . . . . . . . . 166 Integrating Concepts and Discovering Algorithms . . . 167

5.6

Finding a Minimum Spanning Tree of a Weighted Graph . . . 167 5.6.1 5.6.2 5.6.3 5.6.4 Cutting or Growing Edges: A Krushkal’s like greedy algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 167 Selecting Edges: A Prim’s like greedy Algorithm . . . . 171 A Panoramic Picture of various MST Finding Techniques173 The Maximum Spanning Tree Problem . . . . . . . . . 176

5.7

Finding a Path in a Graph . . . . . . . . . . . . . . . . . . . . 177 5.7.1 5.7.2 Cutting Edges . . . . . . . . . . . . . . . . . . . . . . . 177 Selecting Edges . . . . . . . . . . . . . . . . . . . . . . 179

5.8

The Shortest Path Problem . . . . . . . . . . . . . . . . . . . 179 5.8.1 5.8.2 5.8.3 5.8.4 5.8.5 Dijkstra’s (like) Algorithm . . . . . . . . . . . . . . . . 181 Discussion on Dijkstra’s (like) Algorithm . . . . . . . . 181 The Shortest Path Problem Redeﬁned: The k-edge Shortest Path Problem . . . . . . . . . . . . . . . . . . 187 The k-edge Longest Path Problem . . . . . . . . . . . . 190 The Shortest Path Problem in Undirected Graphs with Negative Weights . . . . . . . . . . . . . . . . . . . . . 192

5.9

Graph Traversal Techniques . . . . . . . . . . . . . . . . . . . 195 5.9.1 5.9.2 Traditional Techniques & the Bucket-Algorithm . . . . 196 The Underlying Data Structure . . . . . . . . . . . . . 196

5.10 Some Graph Theoretic Claims . . . . . . . . . . . . . . . . . . 198 5.11 Shortest Path Algorithms . . . . . . . . . . . . . . . . . . . . 204

Contents

ix

5.11.1 Single Source Shortest Path Algorithms with positive edge weights . . . . . . . . . . . . . . . . . . . . . . . . 205 5.11.2 Single Source Shortest Path Algorithms for Directed Acyclic Graphs . . . . . . . . . . . . . . . . . . . . . . 210 5.11.3 Single Source Shortest Path Algorithms for directed graphs with negative edge weights . . . . . . . . . . . . 218 5.11.4 All Pair Shortest Path Algorithms . . . . . . . . . . . . 227 5.11.5 Johnson’s all Pair Shortest Path Algorithm . . . . . . . 233 5.12 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 6 Network Flows, Connectivity and Matching Problems 6.1 6.2 6.3 6.4 249

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Deﬁnitions & Prior Knowledge . . . . . . . . . . . . . . . . . . 250 Konig’s Theorem, Menger’s Theorem & Hall’s (Marriage) Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Menger’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . 264 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 Maximum Edge-Disjoint Paths in Directed Graphs . . 264 The Concept of a Minimum Cut in Directed Graphs . . 271 A Proof of Menger’s Theorem and Finding the Minimum Cut in Directed Graphs . . . . . . . . . . . . . . 275 Finding Maximum Vertex-Disjoint Paths & Minimum Vertex Cut in Directed Graphs . . . . . . . . . . . . . 279 Menger’s Theorem for Undirected Graphs . . . . . . . 282 Edge Connectivity and Vertex Connectivity for Undirected Graphs . . . . . . . . . . . . . . . . . . . . . . . 285

6.5 6.6

Konig’s Theorem, Menger’s Theorem & Hall’s (Marriage) Theorem Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Network Flows . . . . . . . . . . . . . . . . . . . . . . . . . . 306 6.6.1 6.6.2 Finding Maximum Edge-Disjoint Paths in Multi-Graphs306 The Maximum Flow & the Minimum Cut . . . . . . . 310

. 363 6. . . 350 A Panoramic Picture of Similar Problems & Solutions (once again) . .1 6. . . . . . . 345 Finding a Maximum Flow or Finding a Shortest Path? 345 Category 3 network ﬂow Problems . . . 366 Finding a feasible ﬂow in a Circulation graph with one special edge . . .9. . .8 The Max-Flow Min-Cost Problem . . . . . 311 Lower Bounds on Edge Flows and the Max-Cut . . . . .3 6. . . . . . . . . . . . . . . . . . . . 364 6. . . 377 381 7 Eulerian Graphs & the Chinese Postman Problem . . . . . . . . 312 The Matching Problem in Bipartite Graphs .4 6. . . . . . . . . . .7. . . . 345 6. .2 6.3 6. . . . . . . . . . .1 6. . . . .3 Maximum Matching in Un-weighted bipartite graphs . . . . . . . . . . . . . . . .8. . .7. . . . . . . . 328 Maximum Weighted Matching in Complete Weighted Bipartite Graphs . . . . . .1 6. . . . . . .5 6. .9. . . . . . . . .4 6. . . . . 365 New Problems . . . . . . . . .2 6.9. . .9.x 6. .6. . 370 When upper bound is higher than a non zero lower bound372 Is it possible to solve the Circulation Problem for undirected graphs? . . . . . . . . . . . . . 325 Maximum Matching in Complete (Binary) Weighted Bipartite Graphs . . . . . . . . . . .8. 369 Finding a feasible ﬂow in a network ﬂow graph with one special edge . . . . . . . . . . . . . . . .2 6. . . .9. . . . . . .7. . . . . . . . .8. . . . .7 Prior knowledge: . .9. 324 6. . . .9 Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem . . . . . . . . . .6 6. . . . . .9.8.4 6.6. . . . . . . . 348 Category 2 (and 1) network ﬂow Problems . .5 Introduction . . . . . . . . . . . . . . . . . . . . . . . . .3 6. . 332 6. . . . . . . . . . .7 Contents Algorithmic Issues & Complexity Calculations . . . . . . . . . . . . . . . . . 364 New concepts .8. . . . . . . . .

. 428 8. . . . . . . . . . . . . . . . . .2. . . . . . . . 424 Necessary Conditions for a Hamiltonian Graph . . . . . 438 Ore’s Theorem: . .3. . . . . . . .1 8. . 436 Summary . . . . . . . . . .1 8.2 8. . . . . . .3 Hamiltonian Graphs . . . . . . . .3. . . . . . . . . 425 8. . . . . . . . . . . . . . . . . Properties & Actions . . 464 . . . . . . . . . . . . .2. . . . 382 Eulerian Circuits and Graphs .5 xi A Special Class of Graphs . .4 7.4 8. . . . . . . . 425 A Concept Map . . . . . 410 423 8 Hamiltonian Graphs 8. . . . . . . . . . . . . . . 397 The Chinese Postman Problem for Directed Graphs .3 7. . 429 Actually Finding a Hamiltonian Cycle in the Puzzle: . . . . . . 436 Bondy & Chvatal’s Theorem: . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . . .4 8.6 Bipartite Hamiltonian Graphs . . . . . . . . 429 Basic Intuition . . . . . . . . . . . . . 394 Eulerian Walk and the Chinese Postman Problem . .1 8. . . . .3. .2 8. . . .1 7. . . . . . . . . . . . . . .2. . . . . .3.4 8. . . .5 Necessary Conditions for a Connected Graph . . . . . .1 Concepts. . . .3 8. . . . .3. . . . . . . 438 Closure of a Graph: . . . . . . . . . . .3 8. . . . . . . . . . 424 A Loose Suﬃcient Condition for a Hamiltonian Graph 425 Suﬃcient Condition for a Connected Graph . . . . . . . . . 439 8. . . .5 8. . . . . . .6 8. . . . . . .Contents 7. . . . . . . . . . . . .7 A Puzzle: . . .2 7. . . . . 456 463 9 Strongly Connected Directed Graphs and Tournaments 9. . . . . . . . . . . . . . . . . . . . . . . 424 Prior Knowledge . . . . . . 446 Some Theoretical Claims . . . .5 8. .3. . . .2. . . .2. . . . 447 A Categorization of Hamiltonian Graphs . . . . . . .2 Introduction . . . . . . . . . . 424 8. . 388 Eulerian Trails and Related Problems . . . . .

. . . .xii 9. . . . . . 498 9. . .1 9. . . . 498 A Hamiltonian Path in a Tournament .6.5. . . . . . . .3 9. 476 Strongly Connected Components . . . . . . 485 Tournaments . . 518 . . 471 Directed Acyclic Graphs (DAG’s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . 503 Unilaterally Connected Directed Graphs: .2 9. . . . .5 Contents Strongly Connected Directed Graphs . . . . . . . . 498 A Hamiltonian Cycle in a Strong Tournament .1 Unilaterally orient-able Un-directed Graphs . . . .2 9.5. . . . .4 9. . . . . 511 9. . . . . . . . . . .6 A Panoramic Picture and a Concept Map . . .3 9. . . . . . . . . . .

2 1.5 1.6 1.3 1.1 1.4 1.7 Why a new book? What do we emphasize? How the book is organized? How is the book designed? Some salient features of the book What tools do we use? A Possible Sequence .Chapter 1 Introduction 1.

Implications & theorems (connections between concepts) 3. bridge edge. path. We shall discuss here why there was a need for another book designed with a diﬀerent pedagogical structure and suitable for students and practitioners working in diverse ﬁelds who intend to use graph theory in their respective ﬁelds of study. In fact we try our best to design constructive proofs which not only prove a connection but also provide an algorithm to ﬁnd something useful.2 Introduction 1. An implication connects two or more concepts. thus reinforcing understanding at various levels. For example if every edge is a bridge edge in a connected graph G then the graph G is a tree. edge-disjoint paths. Before we start making comparison between diﬀerent pedagogical approaches and talk about the merit of our approach we shall ﬁrst describe the basic structure of the said course. connected graph. Many books tilting towards graph theory do not emphasize graph algorithms. For example graph. Similarly a number of graph algorithm books ignore the theory part of this course namely graph theorems and their proofs. & edge cut are all concepts. tree.1 Why a new book? There are a number of excellent books available on topics covering an introductory course on Graph Theory & Graph Algorithms . Algorithms (actions which transform an input into an output) Let us start with a few concepts used in our subject. Menger’s theorem connects maximum edge-disjoint paths to the minimum edge cut in a graph. and a learner needs to become familiar with these concepts. We need to prove a theorem like this one in a formal but convincing manner. Unlike these books we operate on all the three layers. He or she should be able to feel. and connect these concepts.almost each with a diﬀerent approach. Deﬁnitions (concepts) 2. For example we use constructive techniques to ﬁnd as well as prove that the maximum number of edge-disjoint paths are equal to the size of the minimum cut in a graph. edge. vertex. . edge weight. There are basically three layers on which such a course operates: 1. For example an algorithm is to be designed to ﬁnd maximum edge-disjoint paths as well as the minimum edge cut in a given input graph. visualize. An algorithm converts an input into a useful output.

We thus encourage our readers to transform one algorithm (Prim’s algorithm) into another (Dijksta’s algorithm). . 1. For example Prim’s algorithm can ﬁnd a minimum spanning tree or a maximum spanning tree (after a minor modiﬁcation) and can handle positive or negative edge weights while Dijkstra’s algorithm is unable to do so. Similarly Prim designed a greedy algorithm to ﬁnd a minimum spanning tree in a weighted graph. For example Dijkstra designed a greedy algorithm to ﬁnd shortest path between two vertices in a weighted graph. For example we encourage our readers to transform the techniques used to prove that Dijkstra’s algorithm really ﬁnds shortest paths into techniques to prove that Prim’s algorithm really ﬁnds a minimum spanning tree in a weighted graph. We think of this course on graph theory & algorithms as a course on (intelligent) transformations. We think it is important from a learning perspective to integrate as well as diﬀerentiate concepts and techniques especially the ones which solve nearly identical problems.2. it is possible and desirable to transform one proof into another. (see Fig. We provide platforms where a learner is provoked to transform one proof technique (or an algorithm) into another proof technique (or an algorithm). 1. Transforming one concept into another and transforming one graph into another is the driving force behind this exercise (see Fig.What do we emphasize? 3 Most of the other textbooks use a historical perspective of how and when a graph algorithm was discovered. We expect our readers to ﬁrst think of a non graph problem in terms of a graph. Similarly we encourage them to transform one theorem into another theorem. We also encourage them to transform a graph problem into another graph problem. We then encourage our readers to transform that non-graph problem into a graph problem. We think that not only the similarities but also the diﬀerences should be highlighted between two almost similar concepts or algorithms.2).1).2 What do we emphasize? The single most prominent feature which distinguishes this book from other books in this ﬁeld is an emphasis on transformations (or reductions). Similarly. 1.2. The historical perspective encourages one to teach these two algorithms in isolation without making any connections between the two algorithms.

(http://www.2.1: World Cup 2010 round of 16 is represented by a graph.ﬁfa.html) .com/worldcup/matches/index.4 Introduction Figure 1.

w(a.2: A visual depiction of how an algorithm transforms a graph into another graph while trying to ﬁnd the shortest paths (Chapter 5).What do we emphasize? 5 j 3 g 2 3 f 2 1 e 3 a 2 d 3 1 2 b e 4 h 6 9 i 3 k 3 c f 2 d 1 3 3 5 g 2 4 j 3 i 6 9 a 2 2 3 1 b e 4 3 k 3 c f 2 d 1 3 6 3 5 g 4 2 j 3 i 6 9 a 2 2 3 1 b 4 3 k 3 c h h ut sb ce s tan path d i s e st st rte ort h o e sh s he of th dt fin rack We se t lo j 3 g 2 6 a f 2 d 1 e 5 3 1 3 5 2 4 h 3 6 7 i 3 w(a.k).k) = min{w(a.k)} j 3 g k 3 2 6 a f 2 d 1 e 5 3 1 3 5 2 2 b e 4 h 3 c 6 7 3 4 c f 2 d 1 5 3 1 i 3 k 3 6 3 5 a 2 2 b g 2 4 h 6 7 3 4 c j 3 i 3 k 4 2 b Figure 1. j)+w(j. .2.

1). Here we eﬀectively start using our emphasis on transformations. The ﬁfth chapter handles some important graph algorithms.3. We show . molecular biology. We also provide other tools like a colorful visual puzzle which diﬀerentiates between and integrates various shortest path algorithms (see Fig. 1. Chapter 6 is the longest chapter in the book. This chapter consists of multiple & diverse topics as described before but a conscious eﬀort has been made to make sure that the number of important milestones or bottlenecks in learning remains very small. matching problems. The non-graph problems come from diverse ﬁelds like operations research. In Chapter 7 we discuss necessary and suﬃcient conditions for Eulerian graphs and the Chinese Postman problem. We purposely do not use a historical perspective and avoid describing an algorithm in its published (or polished) form. civil engineering. The third chapter describes how a (non-graph) problem is transformed into a graph problem and encourages the readers to think in graph theoretic terms. The second chapter provides standard deﬁnitions. We also show how one problem (and its solution). and the circulation problem. all the above mentioned topics depend upon one central and crucial idea. For example. distributed computing. Instead we encourage our learners to devise cruder versions of an algorithm which are relatively easy to discover and appreciate intuitively. The fourth chapter focuses on basics of graph theory with an introduction to several concepts and properties related to graphs. minimum cost ﬂows. 1. the circulation problem is transformed into another problem like the minimum cost-maximum ﬂow problem.3 How the book is organized? The book is organized into eight chapters other than this introduction (see Fig. for example. and computer science.6 Introduction 1.2). if we need to ﬁnd multiple edge-disjoint paths in a graph then we should reverse the direction of an already found path before ﬁnding another edge-disjoint path.3. We start with a stupid algorithm known as the Bucket Algorithm which provides us with a platform where we encourage our learners to modify and mould the Bucket Algorithm to design various useful graph algorithms. network ﬂows. digital logic. All the proofs used here are constructive . that is.we not only prove that an Eulerian Circuit exists in a graph with even degree but we also ﬁnd that circuit using an algorithm. We actively demonstrate how a theorem (and its corresponding proof) like Menger’s theorem is transformed into Hall’s theorem or the Konig’s theorem. We discuss concepts related to graph connectivity.

3. The directed acyclic graph illustrates a possible teaching strategy.How the book is organized? 7 Figure 1. .1: Organization of our book consisting of nine chapters.

3. Both problems and their respective solutions in fact converge into a single problem and a single technique to solve it. We discuss suﬃcient conditions for an undirected as well as a directed graph to be Hamiltonian. Hamiltonian directed graphs are discussed again in Chapter 8. we transform one problem into another and the corresponding algorithm is also transformed in the process.8 Introduction that the Circulation problem (already discussed in Chapter 6) was in fact the Chinese Postman problem in its general form. and tournaments in this chapter as well. We address strongly connected graphs and components. We describe Hamiltonian graphs in Chapter 7. Figure 1. In case of tournament graphs we come back to the problem of ﬁnding a Hamiltonian path and a Hamiltonian .2: In shortest path algorithms (described in Chapter 5) we transform one algorithm into another solving the same problem. unilaterally connected graphs. In Chapter 6.

Remove the bottleneck by introducing a number of bridging concepts and by drawing suitable number of colored diagrams taking advantage of the role of visualization in learning graph theory. algorithms. 2. 2. its usefulness and limitations 4. Emphasis on prior knowledge. 3. 9 1. An integrated approach where concepts. Identify its nature using theories of learning & pedagogy (this is done through a statistical analysis of student feedback obtained in the last six years of teaching this course at LUMS. Some text is added where needed in order to supplement diagrams unlike other books where diagrams supplement text. Starting with simple and easy to use building blocks which are used by a learner to construct more sophisticated concepts. A number of research projects undertaken by students registered in a course titled “Problems of Learning & Teaching ” highlighting various problems of learning in the ﬁeld of graph theory & algorithms have immensely helped us in the design of various sections). and theorems reinforce learning and understanding 5.5 Some salient features of the book 1. algorithms or elaborate proofs .4 How is the book designed? We have followed a three step design strategy while writing each section and sub-section of this book: 1. Lahore. Identify a potential bottleneck in learning a speciﬁc concept. Pakistan). Discovery based learning is practised by ﬁrst asking provoking questions before actually describing an algorithm or a theorem. Instead of describing a concept in its ﬁnished & sophisticated form we ﬁrst describe its cruder version which is easy to discover and appreciate 3. Several hundred colored diagrams play a central role in the design of the book. 1.How is the book designed? cycle provided the tournament is strongly connected.

com.7 A Possible Sequence A possible sequence of lectures covering this book is given below in a typical 3-credit course in a semester system at a higher under-graduate or early graduate level. concept maps.10 Introduction 6. 10. e. The book has been used several times to teach a graduate level course on Graph Theory & Algorithms at LUMS. We then encourage our learners to appreciate by themselves the repercussions of that error and in the process ﬁnd an alternate path to solve the problem correctly. Komal Syed and I tried to discuss and debate various issues concerning graph theory & algorithms using this book (see Fig. 1. 9. Some of the VU lectures along with Power Point slides are available on Synote.6. At the VU. Complexity of learning under our control because of a conscious eﬀort to keep it under limits. A lot of technology tools are nowadays available for synchronizing class room video with multimedia slides and lecture notes (synchronizing annotations for educational multimedia).6 What tools do we use? We occasionally use concept map as a tool for better learning which enable a learner to explicitly make connections between concepts as shown in Fig. We sometimes encourage our readers to make errors as we think that making an error is a step towards meaningful learning. Constructive proofs with the help of algorithms 8.. It has also been used to teach a similar course at the Virtual University of Pakistan. we have used a 3-person drama format instead of a single person monologue.6.synote. Yasser Hashmi.1. . and can be viewed after getting an account on www. algorithms as well as theorems 7.3). 1. 1. 1.g. We use a number of tools from the science of learning. We always make comparisons highlighting similarities as well as diﬀerences between concepts.

6.2.A Possible Sequence 11 Figure 1. 1. .6. We use several visualization tools in order to enable the learner to visualize the working and the subsequent time complexity of an algorithm as shown in Fig.1: A concept map showing a number of relevant concepts and a number of theorems which relate diﬀerent concepts (taken from Chapter 6).

This helps a learner to visualize the time complexity of an algorithm. .2: Visualizing how an algorithm changes a graph and what price is paid in terms of number steps performed. Each edge in the pink graph exactly corresponds to one step in the algorithm.12 Introduction Figure 1.6.

A Possible Sequence 13 Figure 1. .3: A 3-person drama format for teaching Graph Theory & Algorithms at the Virtual University of Pakistan.6.

.6.4: Virtual University video lectures along with Power Point slides are available on www.synote. A learner has the facility of expressing and sharing his or her feedback regarding the understanding of a concept in this software platform.com.14 Introduction Figure 1.

Menger’s Theorem. Single source & all pair shortest paths. Matching Problems & Network Flows Deﬁnitions. Finding a Path in a Graph. Graph Traversal Techniques.A Possible Sequence Chapter 3 (1 Lectures) Problems. Menger’s Theorem. Chapter 6 (9 Lectures) Connectivity. the Shortest Path Problem. Equal Graphs & Isomorphic Graphs. & Hall’s (Marriage) Theorem. Finding if a Graph is a Tree. Prior Knowledge. Lower Bounds on Edge Flows: Min-Flow & the Max-Cut. Sequencing by Hybridization (in Computational Biology). Properties. Lower as well as Upper Bounds on Edge Flows. Algorithmic Issues & Complexity Calculations. An Activity Scheduling Problem (in Civil Works). Integration of Concepts. Walks. the Maximum Flow & the Minimum Cut. the Bucket Algorithm. the Matching Problem in Bi- . Konig’s Theorem. the Satisﬁability Problem (in Logic Circuits). Konig’s Theorem. Finding Maximum Edge-Disjoint Paths. a Proof of Menger’s Theorem & Finding the Min-Cut. & Hall’s (Marriage) Theorem Re-visited. the Degree Sequence. discussion & problems (from Operations Research) Chapter 4 (3 Lectures) Basics of Graph Theory A Mutual Friendship Graph. & Warm-up Exercises. Finding a minimum (maximum) spanning (MST) tree. Complement of a Graph. Finding a Spanning Tree of a Graph. Finding Maximum Vertex-Disjoint Paths. Menger’s Theorem. Edge Connectivity & Vertex Connectivity. (3 Lectures) Network Flows: Finding Maximum Edge-Disjoint Paths in Multi-Graphs. Models & Graphs: Why Study Graph Theory 15 Reducing one Problem into another. Multi-graphs and Pseudo-graphs. some Graph Theoretic Claims. Trails & Paths. and Action Items Chapter 5 (4 Lectures) Basics of Graph Algorithms Design of Algorithms. Representation of a Graph. Menger’s Theorem for Un-directed Graphs. The Concept of a Minimum Cut. a Dual Machine Serial Processing Environment (from Distributed Computing). Finding if a Graph is Connected. Broad Categories of Graphs.

Eulerian Trails & Related Problems. Problems & Claims. Maximum Matching in Unweighted Bipartite graphs. Directed Acyclic Graphs (DAG’s). Tournaments. (3 Lectures) Chapter 7 (3 Lectures) Eulerian Graphs & the Chinese Postman Problem A Special Class of Graphs. Strongly Connected Directed Graphs. (3 Lectures) The Max Flow Min Cost Problem: Finding a Maximum Flow or Finding a Shortest Path? A Panoramic Picture of Similar Problems & Solutions. the Circulation Problem. Bipartite Hamiltonian Graphs. Connecting the Network Flow Problem with the Circulation Problem. Properties. a Panoramic Picture of Similar Problems & Solutions (once again). & Actions. Hamiltonian Graphs. ﬁnding a Feasible Flow Under Lower & Upper Bounds. Finding Maximum Flow at Minimum Cost (Category 1). Eulerian Circuits & Graphs. Eulerian Walk & the Chinese Postman Problem. Finding a Minimum Cost Feasible Flow.16 Introduction partite Graphs. Unilaterally Connected Directed Graphs. The Chinese Postman Problem for Directed Graphs Chapter 8 (4 Lectures) Hamiltonian Graphs Prior Knowledge. Maximum Weighted Matching in Complete Weighted Bipartite Graphs. Strongly Connected Components. . discussion & Conclusions Chapter 9 (5 Lectures) Strongly Connected Directed Graphs and Tournaments Concepts. Negative Weight Cycles & Improvement in Cost of Flow. Maximum Matching in Complete (Binary) Weighted Bipartite Graphs.

& Network ﬂows Chinese Postman Problem & Eulerian Graphs Hamiltonian Graphs Strongly Connected Graphs & Tournaments 17 Chapter Chapter Chapter Chapter Chapter Chapter Chapter Chapter Chapter Chapter No 1 2 3 4 5 6 7 8 9 Hours 0 0 2 6 8 18 6 8 10 . & Graphs Basics of Graph Theory Basics of Graph Algorithms Connectivity. Matching Problems.A Possible Sequence A Possible Program of Study in one semester Topic Introduction Deﬁnitions Problems. Models.

2003. Arlington. (iNEER). Arlington. Vol. Ed. (iNEER). and Res. ”Problems of Learning & Teaching. 2005.” proceedings of the Third International Conference on the Teaching of Mathematics at the undergraduate level. ”Bridging over Problems of Learning in Finding Strongly Connected Components.2. SummerFall 2003. Yasser Hashmi. ”Should We Teach Algorithms?” IJECE.” proceedings of the IADIS International Conference on Cognition and Exploratory Learning in Digital Age (CELDA 2005). Int. 5. pp. The Magic of Dynamic Programming. 2005 2. 409-418. Innovations 2004: World Innovations in Engineering Education and Research. 409-418. VA. The Magic of Dynamic Programming. Arlington. 134-140. . Nooman Nadeem. ”Teaching Science and Mathematics: Discovery Based Learning”. and Res.” proceedings of the Second International Conference on Pedagogies and Learning -2005. and Res. 6. Turkey. Sara Tahir. 3. 7. Network for Eng. Istanbul. Int. pp. Alvi Atif. Alvi Atif. Innovations 2005: World Innovations in Engineering Education and Research.18 Acknowledgements Introduction 1. pages 78 to 87. 2006. ”Meaningful Learning of Graph Algorithms. Ed. (iNEER). Proceedings of the International Conference on Engineering Education. 2004. Australia. Network for Eng. Int. No. VA. VA. Network for Eng. 4. Yasser Hashmi. pp.2. Harika Masood. Ed. Valencia Spain.

Chapter 2 Basic Deﬁnitions in Graph Theory and Algorithms .

(Please see Chapter 4 and 5 for more details) Multi Graphs We assume that multiple edges (known as parallel edges) between the same two vertices are not allowed in a graph. In M ultiGraphs we allow parallel edges as well as self loops. (Please see Chapter 4 for more details) Adjacent Vertices A vertex u is said to be adjacent to vertex v if there is an edge {u. Thus a graph consists of vertices and edges. A weighted graph is one where there may be a weight associated with each edge of the graph. Please note that the set E is a set of pairs of connected vertices.20 Basic Deﬁnitions in Graph Theory and Algorithms Graph A graph G is made up of a (non empty) set of objects called vertices or nodes .some of the pair of vertices may be connected by directed or un-directed links which are known as edges. Usually the size of the vertex set V is represented by p while the size of the edge set E is represented by q. It is a set of ordered pairs in case of a directed graph and a set of un-ordered pairs in case of an un − directed graph. Similarly an edge coming out of a vertex and terminating at the same vertex (known as a self loop) is not allowed. (Please see Chapter 4 for more details) Regular graph An un-directed graph G is regular if the degree of each vertex is the same. (Please see Chapter 4 for more details) . (Please see Chapter 4 for more details) Degree of a vertex Number of edges connected to a vertex x is known as the degree of vertex x in an un-directed graph G. v} in graph G. We may represent the set of vertices by V (G) and the set of edges may be represented by E(G).

(Please see Chapter 4 for more details) Complete Graph An un-directed graph G is complete if there is an edge between every pair of vertices of graph G. It is known as a star graph because it looks like a star with rays of lighy coming out? (Please see Chapter 4 for more details) Chain or Cycle graph A connected graph G such that the degree of each vertex is exactly 2. (Please see Chapter 4 for more details) Isomorphic Graphs Two graphs G and H are isomorphic if graph G becomes equal to graph H by some relabeling of vertices of graph H.(Please see Chapter 4 for more details) Bipartite Graph A graph G is bipartite if the vertex set V (G) can be divided into two subsets (or partites) A and B such that every edge in G connects a vertex in partite A and a vertex in partite B. Please note that two equal graphs are always isomorphic but two isomorphic graphs may not be equal.21 Star graph A graph of p vertices in which one vertex has degree equal to p−1 while every other vertex has a degree equal to 1. v} in graph H and vice versa then the two graphs G and H are equal. (Please see Chapter 4 for more details) . (Please see Chapter 4 for more details) Equal Graphs If for every edge {u. v} in a graph G there is an edge {u.

v} in G. (Please see Chapter 9 for more details) Self Complementing graph G A graph G is self complementing (SC) if graph G and its complement are isomorphic to each other.22 Basic Deﬁnitions in Graph Theory and Algorithms Complement c(G) of an un-directed graph G The complement c(G) of graph G is a graph with as many vertices as in G and an edge {u. (Please see Chapter 4 for more details) Walk You can walk on the edges of graph G edges starting from vertex u and ending at vertex v traversing diﬀerent edges and vertices. The identity permutation is always an automorphism . In a walk you .it is known as a trivial permutation. (Please see Chapter 4 for more details) Transpose of a directed graph G T ranspose T (G) of a directed graph G is obtained by reversing the direction of each edge in the directed graph G. We may be more interested in the non trivial permutations of graph G? It may be possible for a certain category of graphs that the only automorphism is the trivial (identity) permutation? Please note that if p is an automorphism of graph G then the permutation p2 is always an automorphism of graph G. (Please see Chapter 4 for more details) Automorphism If a permutation p of a graph G creates a graph H which is equal to graph G then that permutation is known as an automorphism of graph G. v} in c(G) if and only if there is no edge {u. (Please see Chapter 4 for more details) Complementing Permutation If a permutation p of vertices of graph G creates a graph H which is the complement of graph G and at the same time H is isomorhic to G then the permutation p is known as the complementing permutation of graph G and graph G will be a self complementary graph.

that is the direction of that edge. (Please see Chapter 4 and 5 for more details) Shortest path Among all paths between vertex u and vertex v. (Please see Chapter 4 and 7 for more details) Path If neither an edge nor a vertex is repeated in a walk starting from a vertex u and ending at vertex v then the walk is known as a path. In a weighted graph G the minimum length is measured in terms of sum of weights of all edges in the u − v path. Thus a trail is always a walk but it is not the other way round. A closed trail . A walk is open if vertex u and v are diﬀerent. (Please see Chapter 4 for more details) Cycle If a path is closed that means you come back to the vertex from where you have started then that path is known as a cycle. A cycle is a circuit but a circuit may not be a cycle as no vertex should be repeated in a cycle.23 can traverse an edge more than once. Please note that in an un-directed graph you can traverse an edge in both directions but in a directed graph you can traverse an edge in only one direction . It is a closed walk if vertex u and v are the same.that is when vertex u and v are the same then it is known as a circuit. A path is always a trail (or a walk) but it is not the other way round. It is known as a u − v path. (Please see Chapter 4 and 7 for more details) Trail and Circuit If no edge is repeated in a walk from a vertex u to a vertex v then the walk is known as a trail. the one with minimum length is known as the shortest path between vertex u and vertex v. Please note that it is possible to traverse a vertex more than once but an edge should not be traversed more than once in a trail or in a circuit. (Please see Chapter 4 and 5 for more details) . In an unweighted graph G the minimum length is measured in terms of number of edges encountered in the u − v path.

In other words there are no cycles in a . (Please see Chapter 4 and 8 for more details) A Strongly Connected Directed Graph A directed graph D is strongly connected if there is a directed path from vertex u to vertex v and a path from vertex v to u for every pair (u.24 Basic Deﬁnitions in Graph Theory and Algorithms A Connected Graph An un-directed graph G is connected if there is a path between every pair of vertices of that graph. The Reachable Relation matrix of an undirected connected graph will contain all 1’s. (Please see Chapter 4 and 5 for more details) Reachable relation or Transitive closure of a graph The Reachable Relation (or the transitive closure) of a directed graph D is another directed graph in which there is an edge from vertex u to vertex v provided v is reachable from u in D. (Please see Chapter 9 for more details) Directed Acylic Graph A directed graph D is directedacyclic (or a DAG) if there is directed path from vertex u to vertex v then there is no path from vertex v to u for every pair (u. v) in directed graph D. (Please see Chapter 9 for more details) A Unilaterally Connected Directed Graph A directed graph D is unilaterally connected if there is directed path from vertex u to vertex v or a path from vertex v to u for every pair (u. The Reachable Relation graph of D can be represented by an adjacency matrix A in which A(u. and it is zero otherwise. v) in directed graph D. (Please see Chapter 9 for more details) Square of a directed graph The square of a graph D is another graph (known as) D2 in which there is an edge from vertex u to vertex v provided there is a two edge path from u to v or there is an edge (that is a one edge path) from u to v in D. v) = 1 provided there is a directed path from u to v in D. v) in directed graph D.

(Please see Chapter 4 and 5 for more details) Cyclic graph G A graph G is cyclic if it contains one or more cycles.25 directed acyclic graph. (Please see Chapter 4. (Please see Chapter 4 and 5 for more details) . Please note that a tree is a connected graph with no cycles while a forest may be a disconnected graph. 5 and 9 for more details) A Forest A (disconnected)graph G with no cycles. In other words a connected graph G is a tree if every edge of G is a bridge edge. 5 and 9 for more details) Acyclic graph or a Tree An un-directed graph G is acyclic if it does not contain a cycle. It is also known as a tree graph provided graph G is connected. It is known as a tournament graph as some (actual) tournaments (like f ootball league are played in the form of a tournament graph? (Please see Chapter 9 for more details) Disconnected graph An un-directed graph is disconnected if for any pair of vertices u and v there is no u − v path. In other words if we put directions on edges in a completely connected un-directed graph G then the un-directed graph G transforms into a tournament (directed) graph D. (Please see Chapter 4. v} is a bridge edge if its removal disconnects an un-directed graph G. (Please see Chapter 4 and 5 for more details) Bridge edge or Cut edge An edge {u. (Please see Chapter 5 and 9 for more details) A Tournament Graph A directed graph D is a tournament if there is a directed edge from vertex u to vertex v exclusive OR a directed edge from vertex v to u for every pair (u. v) in directed graph D.

In other words if you remove all non bridge edges in graph G then you get a spanning tree of G. A graph which contains a Hamiltonian cycle is known as a Hamiltonian graph.26 Basic Deﬁnitions in Graph Theory and Algorithms Spanning tree of a graph G A spanning tree (known as ST ) of a connected graph G contains all vertices of G and some edges of G. (Please see Chapter 7 for more details) Set Cover Given a set of subsets S of the U niversal Set U . (Please see Chapter 6 for more details) . (Please see Chapter 4 for more details) Hamiltonian Cycle It is a cycle in a graph G which traverses each vertex of G exactly once. A graph which contains a Eulerian circuit is known as a Eulerian graph. (Please see Chapter 5 for more details) A Binary Tree A binary tree is a tree such that the degree of each vertex is not more than three. and it is a tree. (Please see Chapter 4 for more details) A Path graph A path graph is a tree provided it has two vertices with degree one while all other vertices has degree exactly equal to two. what is the smallest subset T of S such that the union of all these sub sets in T covers all elements of U . (Please see Chapter 8 for more details) Eulerian Circuit A circuit in a graph G such that every edge of graph G is traversed exactly once. We have already witnessed the subset sum problem (in previous courses) in which we have to select integers (out of a set of integers) such that the sum of the selected integers is equal to a given constant.

In other words a matching is a set of non-adjacent edges in a graph G. no two edges in the subset share a common vertex. (Please see Chapter 4. It may be possible to increase the size of the matching by ﬁrst discarding the initial matching edges. What is the smallest subset of vertices of the graph that covers all edges? (Please see Chapter 6 for more details) Independent (Vertex) Set It is the largest subset S of vertices of a graph such that no pair of vertices in S has an edge in between.Thus it is a matching of maximum size.27 Vertex Cover The Universal set U is the set of all edges in a graph. 5 and 6 for more details) Edge Cover The Universal set is the set of all vertices in a graph. (Please see Chapter 6 for more details) Maximal Matching This is a matching in which more edges cannot be added in the existing matching to increase the size of this matching. as compared to the number of vertices in a graph? (Please see Chapter 6 for more details) . Is there a connection between the vertex cover and the independent set? (Please see Chapter 3 and 6 for more details) Matching (Independent Edge Set) It is a subset of edges in graph G such that no two edges in the subset has a common vertex in G. Then the edge cover is the smallest subset of edges. that is. The edges in this subset are also known as independent edges. (Please see Chapter 6 for more details) Maximum Matching This is a matching in a graph with as many edges as possible? Please note that maximum matching is always maximal. which covers all vertices? How small (or big) can the size of the edge cover become.

(Please see Chapter 4. In some literature. (Please see Chapter 6 for more details) Minimum Edge-Cut or MinCut A set of (minimum number of) edges which if removed will disconnect a special vertex s from another special vertex t in a graph G.28 Basic Deﬁnitions in Graph Theory and Algorithms Perfect Matching A P erf ect Matching is a matching which covers all vertices of the graph. That is. the term complete matching is used for it. v} is a bridge edge if its removal disconnects an un-directed graph G. (Please see Chapter 6 for more details) . (Please see Chapter 6 for more details) Minimum Vertex-Cut A set of (minimum number) of vertices which if removed will disconnect a special vertex s from another special vertex t in a graph G. 5 and 6 for more details) Cut vertex A vertex u is a cut vertex if its removal disconnects an un-directed graph G. (Please see Chapter 6 for more details) Vertex Connectivity It is the minimum number of vertices which if removed will disconnect an un-directed connected graph G. (Please see Chapter 6 for more details) Bridge edge or Cut edge An edge {u. every vertex of the graph is incident to exactly one edge of the matching. (Please see Chapter 6 for more details) Edge Connectivity It is the minimum number of edges which if removed will disconnect an undirected connected graph G. Every perfect matching is both maximum and hence maximal.

29

**Network Flow problems in a Network Flow graph D
**

It is a directed graph D with two special vertices. One is a source vertex s and the other is a sink vertex t. The source vertex may produce ﬂow while the sink vertex sinks ﬂow. Every edge may have an associated lower bound on ﬂow, an upper bound on ﬂow, and a cost function associated with ﬂow. We may like to ﬁnd a f easible ﬂow from vertex s to vertex t. We may like to ﬁnd the maximum or minimum feasible ﬂow or maximum f low at minimum cost.

**Feasible Flow in a network Flow Graph
**

A f easible ﬂow in a network ﬂow graph from a source vertex s to a sink vertex t is one in which ﬂow through every vertex (other than the source and the sink vertices) is conserved (that is inﬂow is equal to out ﬂow) and ﬂow through every edge is within the prescribed upper as well as lower bounds. (Please see Chapter 6 for more details)

**The Circulation Problem
**

We consider a network ﬂow graph in which the incoming ﬂow in every vertex should be equal to the outgoing ﬂow in every vertex. The lower bound on ﬂow through every edge is exactly 1. There is a uniform cost of ﬂow through every edge. We need to ﬁnd a minimum cost f easible f low in the network ﬂow graph (also known as the circulation graph). The problem is solvable in polynomial time for directed graphs. We assume that the Circulation graph is connected if it is un-directed and strongly connected if it is directed. (Please see Chapter 6 and 7 for more details)

**The Chinese Postman Problem
**

We are given a graph D which is strongly connected if directed and connected if un-directed. We need to ﬁnd a closed walk in this graph such that the total distance covered is minimum in terms of the number of edges of the graph. The problem is solvable in polynomial time for directed as well as un-directed graphs. Please note that the Chinese Postman Problem transforms into the Circulation Problem (and vice versa) for directed graphs. (Please see Chapter 6 for more details)

30

Basic Deﬁnitions in Graph Theory and Algorithms

Chapter 3 Problems, Models & Graphs: Why Study Graph Theory?

3.1 3.2 3.3 3.4 3.5 3.6 3.7

Introduction Reducing One Problem into Another The Satisﬁability Problem in Logic Circuits An Activity Scheduling Problem A Dual Machine Serial Processing Environment Sequencing by Hybridization in Computational Biology Discussion & Problems

32

Problems, Models & Graphs: Why Study Graph Theory?

3.1

Introduction

When we face a real life problem then one possibility is to solve it right from scratch. A more desirable option is to better understand the problem in terms of reducing it into one of the known problems in computer science. There may be good chances that you are able to transform (or reduce) your unknown problem into one of the solvable problems in graph theory. Even if you end up reducing your problem into one of the hard (or unsolvable) problems – you certainly get a better insight. We shall discuss a number of diverse problems in this chapter; the problems are taken from digital logic, civil works, distributed computing, molecular biology, and the ﬁeld of operations research. Almost all these problems do not seem to have a any relationship with graphs, yet each of them is transformed into a graph problem. As demonstrated in this chapter, it is very much possible (and in fact desirable) to reduce an unknown problem into multiple known problems instead of just one known graph problem. It may happen that out of these multiple known problems, one of the problems may be relatively simple to solve while the other known problem may be a hard one. Once your problem is transformed into a known problem, the complexity of solving your unknown problem will depend upon the complexity of your transformation as well as that of solving the known problem (see Fig. 3.1.1). The real challenge is thus to ﬁnd an intelligent transformation into a simpler problem.

3.2

Reducing One Problem into Another

A reduction is a transformation of one problem into another problem. Sometimes we reduce a known hard problem into the new problem; thus showing that the new problem is as hard as some of the known hard problems. Usually reductions are used in such a negative context especially in the ﬁeld of complexity theory. It is, however, possible to make reductions play a positive role: In such cases we transform a problem into one of the solvable problems, thus showing that a new problem is indeed solvable. Transforming one problem into another requires that each instance of the new problem should be transformed into instances of the old problem; we then solve the old problem using a known algorithm and then again transform its results to obtain the ﬁnal solution of the new problem. We show such a transformation in Fig. 3.1.1. It is important to note the total time complexity of solving

**Reducing One Problem into Another
**

Inputs

33

Outputs

A Known Algorithm for an Old Problem

Algorithm B Algorithm A

Inputs Outputs

A New Problem

Figure 3.1.1: Reducing a new problem into an old problem. The inputs for the new problem should be transformed into the inputs of the old problem. Similarly the outputs should also be transformed. a new problem by reducing it into an old problem will be time complexity of the known algorithm (needed to solve the old problem) plus the time complexities of Algorithm A and that of Algorithm B. We shall categorize a reduction into the following four categories: 1. Reduction of a hard problem (a problem for which) a polynomial time algorithm is not yet designed) into another hard problem. In complexity theory such problems are known as NP-complete problems; 2. Reduction of a problem (with an existing) polynomial time algorithm into another such problem. In complexity theory such problems are known as P problem; 3. Reduction of a P problem into an NP-complete problem; Does it mean that a P problem has become an NP-complete problem? 4. Reduction of an NP-complete problem into a P problem: Does it mean that an NP-complete problem has become a P problem? Why?

34

Problems, Models & Graphs: Why Study Graph Theory?

We shall provide (or discuss) at least one example from each category in this chapter.

3.3

The Satisﬁability Problem in Logic Circuits

Satisﬁability in logic circuits is the problem of ﬁnding if we can assign 0 or 1 to the input variables so as to make the output of the logic circuit equal to 1. If no assignment of input variables can make the output 1 then we claim that the logic formula (or the circuit) is not satisﬁable. In the 3CNF Satisﬁability problem (or the 3-SAT Problem), we are given a boolean expression in 3-conjunctive normal form; in simple words it is the AND output of clauses of OR gates with exactly three inputs (see Fig. 3.3.1). Given such an expression, the 3-Satisﬁability problem is to ﬁnd if it is possible to assign binary values (0 or 1) to its inputs that will make the output equal to 1. In the 3-DNF Satisﬁability Problem, we are given a Boolean expression in disjunctive normal form (DNF); in terms of logic circuits it is the OR output of clauses of AND gates with exactly 3 inputs (see Fig. 3.3.2). Again we need to assign input variable such that the output of the circuit is 1.

a

b c

a b c

a b c

a b c

Figure 3.3.1: A logic circuit consisting of OR gates (each with 3 inputs) and one AND gate. The output is 1 for the selected inputs shown in orange color. A lot many of you might have played with logic circuits; have explored assignments of inputs for which the output of the logic circuit is 1 – but many

The Satisﬁability Problem in Logic Circuits

35

of you may not have realized (or truly appreciated) that the 3-CNF problem is one of the NP-complete problems while the 3-DNF is a solvable problem (in polynomial time). Remember in the 3-CNF problem one has to select inputs such that the output of each OR gate is high so as to satisfy the output. In case of 3-DNF problem the output of the circuit will be high provided the output of any AND gate is high. Surprisingly applying DeMorgans laws it is possible to convert a 3-CNF Boolean expression in terms of a 3-DNF – giving a false impression that we can reduce an NP-complete problem into a P problem. We shall discuss this issue (in detail) in the coming paragraphs.

OutPut

a

b

c

a

b c

a b c

a b c

Figure 3.3.2: A logic circuit consisting of AND gates (each with 3 inputs) and one OR gate. The output is 1 for the selected inputs shown in orange color. Problem Set 3.1. Problem 3.1.1. Design an eﬃcient algorithm to solve the 3-DNF Satisﬁability problem. Show that it is indeed possible to solve this problem in polynomial time (in fact in linear time). A 3-DNF circuit is shown in Fig. 3.3.2. Problem 3.1.2. Try to use a similar technique to solve the 3-CNF Satisﬁability problem. It will not work. The purpose of this problem is to appreciate the inherent hardness of this problem. A 3-CNF circuit is shown in Fig. 3.3.1.

3.3.1

Reducing a 3-SAT Problem into an Independent Set Problem

Let us start with an example from Category 1. We shall reduce the 3-SAT problem into the Independent Set Problem in graphs. Thus in Fig. 3.3.3, the

36

Problems, Models & Graphs: Why Study Graph Theory?

New Problem is the 3-CNF Satisﬁability problem: we are given a Boolean expression in 3-conjunctive normal form; in simple words it is the AND output of clauses of OR gates with exactly three inputs (see Fig. 3.3.1). Given such an expression, the 3-Satisﬁability problem is to ﬁnd if it is possible to assign 0 and 1 to its inputs that will make the output equal to 1. The ﬁgure also shows a combination of inputs (shown in orange color) for which the output of this logic circuit is 1. Please note that at least one input from each OR gate should be 1 in order to pass the test for Satisﬁability.

Inputs

Old Problem The Independent Set Problem in a Triangular Graph

Outputs

Algorithm B Algorithm A

Inputs Outputs

New Problem The 3-Satisfiability Problem

Figure 3.3.3: Reducing the 3-Satisﬁability problem into Independent Set problem in a graph. The old problem in Fig. 3.3.3 is the Independent Set problem in a special graph consisting of k triangles with edges connecting certain vertices within diﬀerent triangles as shown in Fig. 3.3.4. The problem is to ﬁnd if it is possible to select one vertex from each triangle such that no two selected vertices have an edge in common (they should not be adjacent). In other words we need to ﬁnd if the size of the Independent Set (a set of vertices with no common edges) in this graph is equal to the number of triangles in the graph. It is obvious that for the size of the Independent Set to be equal to k we have to select exactly one vertex from each triangle such that no two selected vertices are adjacent.

The Satisﬁability Problem in Logic Circuits

37

Figure 3.3.4: A graph consisting of k triangles where some vertices from diﬀerent triangles are adjacent. We need to ﬁnd if the size of the independent Set is equal to k.

Algorithm 1: The 3-SAT Problem: Find for what inputs, the output is high for the given logic circuit? Input : A Boolean formula (or circuit) in 3-CNF. Output: Yes or No; If Yes then a combination of inputs for which the output is high. 1. We consider this as a new problem: You need to transform it into a known problem in graph theory?

Algorithm 2: The Independent Set Problem: Find if the size of the independent set in a given graph is k. Input : A graph consisting of k triangles. Output: Yes/No; If Yes then select a vertex from each triangle such that no two selected vertices is adjacent. 1. We consider this as a known problem in graph theory

38

Problems, Models & Graphs: Why Study Graph Theory?

OutPut AND

a ¬b c

a b ¬c

¬a ¬b c

¬a ¬b ¬c

c a

¬c

c

¬c

¬b

a

b

¬a

¬b

¬a

¬b

Figure 3.3.5: The 3-Satisﬁability problem (top) is reduced into the Independent Set problem in the graph shown in the bottom. Orange vertices in the bottom graph provides a solution to the Independent Set problem in the bottom graph while their orange counterparts (input variables to the logic circuit) provides a satisﬁable solution to the 3-SAT problem in the top circuit.

The Satisﬁability Problem in Logic Circuits

39

It is obvious that a possible solution of the Independent Set problem in the graph provides a combination of inputs for which the output will be high in the logic circuit. Thus if the size of the Independent Set in the graph is equal to the number of OR gates in the logic circuit then it is possible to ﬁnd a combinations of inputs which will make the output high. In fact the reduction goes in both directions; the solution of any one problem implies a possible solution for the other. Unfortunately both these problems belong to the class known as NP-Complete problems. In the next section we shall talk about a Category 2 reduction. Problem Set 3.2. Problem 3.2.1. We have already talked about the 3-Sat problem and its reduction to independent set problem as modeled in Fig. 3.3.3, and depicted in Fig. 3.3.5. Please design Algorithm A and Algorithm B as shown in Fig. 3.3.3. Problem 3.2.2. Try to use a similar reduction to reduce the 2-SAT problem into the independent set problem in a graph. Discuss why this may or may not be possible. Problem 3.2.3. Try to use a similar reduction to reduce the 3-DNF problem into the independent set problem in a graph. Discuss why this may or may not be possible.

3.3.2

Reducing the 3-CNF Satisﬁability Problem into the 3-DNF Satisﬁability Problem

We know that it is possible to convert a 3-CNF Boolean formula into a 3DNF formula. Such a conversion is done after drawing the truth table or the K-Map of the 3-CNF expression as shown in Fig. 3.3.6. We also know that the 3-CNF Satisﬁability problem is NP-Complete while it is possible to solve the 3-DNF Satisﬁability problem in polynomial time. Is there a contradiction somewhere? Design the corresponding conversion algorithms (Algorithm No. 1 & 2 of Fig. 3.1.1) and you will be able to resolve this contradiction your self.

40

Problems, Models & Graphs: Why Study Graph Theory?

OutPut AND

Dr aw

K

Ma p

OR

OR

OR

OR

ab

a ¬b c a b ¬c OutPut OR ¬a ¬b c ¬a ¬b ¬c

c

0 1

0 0

1

0

00 01 11 10

1

0

1

1

AND

AND

AND

AND

aw Dr

it rc u Ci

a ¬b ¬c

a ¬b c

¬a ¬b ¬c

¬a b c

Figure 3.3.6: The 3-CNF Satisﬁability problem (top) is reduced into the 3DNF-Satisﬁability Problem as shown in the bottom. The truth table, also shown on the right, helps us in this reduction.

The Satisﬁability Problem in Logic Circuits

41

3.3.3

Reducing the 3-CNF Satisﬁability Problem into another graph Problem

Here we intend to discuss a reduction of the 3-SAT problem into the Clique problem in graphs. It is left as an exciting exercise for the reader?

3.3.4

Reducing the 2-CNF Satisﬁability Problem into a Graph Problem

We have already talked about reducing a 2-CNF Satisﬁability problem into an Independent Set problem in graphs. In fact this problem can be reduced to another graph problem which is solvable in polynomial time. We shall describe this Category 2 reduction brieﬂy in this section. We shall partially justify this reduction and leave the rest of the details as an interesting problem for the reader. The 2-SAT problem is similar to the 3-SAT problem except that now each of the OR gates have two inputs rather than three. We still need to ﬁnd a combination of inputs for which the output of the circuit is 1. The corresponding graph problem deals with directed graphs; we need to ﬁnd if any two given vertices, x and y, belong to a single strongly connected component; in other words we need to check if there is a directed path from vertex x to vertex y and from vertex y back to vertex x. This problem and its possible solutions are discussed in detail in Chapter 9. Path ﬁnding algorithms are described in Chapter 5. Given the Boolean expression or the logic circuit, we construct a directed graph D according to the following rules: 1. For every variable x in the Boolean expression we create two vertices with labels x and ¬x in the directed graph D. 2. For every OR gate in the Boolean expression with inputs x and y, we add two directed edges: One directed edge from vertex ¬x to vertex y and another directed edge from vertex ¬y to vertex x. Once we have a constructed directed graph D, we claim that the given Boolean expression (or the logic circuit) is not satisﬁable (that means for any combination of input variables) if and only if any vertex x and its complement vertex ¬x in graph D belongs to the same strongly connected component.

42

Problems, Models & Graphs: Why Study Graph Theory?

¬a b ¬a ¬b c

OR

¬c

OR AND OR

Convert

a

b

a

¬c

¬b

¬a

a

OR

c

Figure 3.3.7: The 2-CNF Satisﬁability problem is reduced into a graph problem. If any vertex x and its complement in the graph (shown in the right diagram) belongs to the same strongly connected component then the Boolean expression corresponding to the circuit (shown in the left diagram) is not satisﬁable. We apply Algorithm 3 for every vertex x (and its complement ¬x) in graph D, and if the answer comes out to be NO in each case then the given Boolean expression is satisﬁable otherwise not. If the Boolean expression is satisﬁable then we have to ﬁnd a combination of input variables for which the output of the logic circuit is 1. This requires a deeper understanding and appreciation of diﬀerent concepts involved in this reduction. We shall provide some hints in this regard and leave the rest as a problem for imagination of the reader. Algorithm 3: Find if two given vertices belong to the same strongly connected component in a directed graph D. Input : A directed graph D, and two vertices x and y. Output: Yes/No; 1. Check if there is a path from vertex x to y and from y to x in the directed graph D. If yes then vertices x and y belong to the same strongly connected component otherwise not.

A 2-CNF expression consisting of a single OR/AND combination is shown in the left diagram of Fig. 3.3.8. It is transformed into a directed graph shown

The Satisﬁability Problem in Logic Circuits

43

a

0

Tr Lo uth gi Ta c C ble irc o ui f t

a→ b ¬a OR b ¬b → b ¬a

0 1 1 0 1 1 1 0 1 1 1 0

Im Trut pli h T ca a tio ble n Gr of ap h

0 1 1

¬a b

AND OR

For what values of input the output is 1

a

¬b

b

¬a

If a = 1 then b=1 for Output to be 1

Figure 3.3.8: A 2-CNF expression with only one OR/AND gate is reduced into a directed graph. The directed graph is in fact an implication graph with a truth table shown at the top. Note that the implication graph tells us that if a = 1 then b should also be 1 otherwise the output of the logic circuit will be zero.

If a = 0 then Output =1

¬a b

OR AND

For what values of input the output is 1

a

b

¬a ¬b

OR

If a = 1 then b=1 then ¬a =1

¬b

¬a

Figure 3.3.9: The 2-CNF Satisﬁability problem is reduced into a graph problem. Note that if a = 1 then we face a contradiction in the implication graph. On the other hand if a = 0 then there is no such contradiction and the output of the logic circuit will be 1 for any value of b.

3. Please note that in the bottom diagram of Fig. This makes sense because if both inputs of the OR gate are 0 then the expression will not be satisﬁable. 3. If it is possible to select one vertex from each adjacent pair such that no two selected vertices are adjacent then we claim that the logic circuit is satisﬁable. it is also possible to reach from vertex ¬a to a as shown by the closed path shown in red color. The implication graph for a Boolean expression consisting of two OR gates are shown in Fig. The implication tells us that in order to make the output 1 we shall make b = 1 if a = 1. The Satisﬁability problem in this logic circuit is transformed into a graph problem in the Implication graph shown in the bottom diagram.3. We show the same 2-CNF logic circuit in Fig. This transformation works both ways: if the circuit is satisﬁable then we can select an independent set . 3. If a = 1 then b should be 1 so that the output of the top OR gate becomes 1.9. 3. and in case it is then what inputs should be applied so that the output is 1 for each logic circuit shown in this ﬁgure.3. Again the implication graph is telling us how it is possible to make the Boolean expression satisﬁable.44 Problems. A directed edge in this graph from vertex x to vertex y implies that if the vertex x (or meaningfully) variable x is 1 then y is 1. But if a = 0 then the implication does not dictate any thing – it means that the Boolean expression is satisﬁable for any value of b. It will be interesting to ﬁnd if the circuit is satisﬁable (as we add more OR gates). This implies that the logic circuit is not satisﬁable. Models & Graphs: Why Study Graph Theory? in the right diagram of this ﬁgure.10.11. It should now be possible to design an eﬃcient graph algorithm which operates on the implication graph but which ﬁnds the input combination for which the logic circuit output is 1. it is possible to reach from vertex a to vertex ¬a.3. The Satisﬁability problem is also transformed into an independent set problem where each OR gate in the logic diagram now corresponds to two adjacent vertices (known as an adjacent pair) instead of a triangular graph. 3. But if b = 1 then according to the implication ¬a should be 1 so as to make the output of the second OR gate 1 – but that is a contradiction. The truth table of this implication is exactly the same as that of the Boolean expression as shown in this ﬁgure.10. As you should appreciate this directed graph is not just a directed graph – this is in fact an implication graph. We show various 2-CNF logic circuits for varying number of OR gates and the corresponding implication graphs in Fig.

vertex a and ¬a do not belong to the same strongly connected component – it means the output of the corresponding logic circuits is satisﬁable. In the top three graphs (shown on the right side). In the bottom diagram this is not possible.3.10: The 2-CNF Satisﬁability problem is reduced into a graph problem.The Satisﬁability Problem in Logic Circuits 45 a ¬a b AND OR Convert b ¬b ¬a ¬a b OR AND Convert a b ¬a ¬b ¬a b OR ¬b ¬c ¬a OR a AND Convert b ¬a ¬b c OR ¬b ¬a a ¬a b ¬a ¬b c OR c OR ¬c OR AND OR a b a ¬c ¬b ¬a a OR Convert c Figure 3. .

46 Problems. an sf o Tr an sf or m rm .11: The 2-CNF Satisﬁability problem is reduced into an independent set problem shown in the top diagram. Models & Graphs: Why Study Graph Theory? with size equal to the number of OR gates in the logic circuit. This implies that the independent set problem (in some special graphs) can be reduced into an implication graph problem. Given a general graph how can you determine that this graph in fact represents a 2-CNF logic circuit? If it does represent such a logic circuit then we can solve this problem after reducing it into an implication graph? ¬a b ¬a ¬b c OR Transform ¬a b OR AND ¬a ¬b a ¬c OR a c a OR a ¬c Tr ¬c a b ¬b ¬a c Figure 3. Describe an eﬃcient algorithm which ﬁnds an independent set in such a graph using an Implication graph.3. It is now obvious that the independent set problem in the graph (which was derived from a 2-CNF logic circuit) can be transformed into a path ﬁnding problem in an Implication graph. The same problem is reduced into a graph problem in an implication graph shown in the bottom diagram.

Then we add a special vertex s and connect it to all such vertices that have no incoming edges (i.4 An Activity Scheduling Problem The problem of activity scheduling is described in simple words. The problem is then transformed into a graph problem as shown in Fig. How will you model this problem in graph theoretic terms and then solve it? We start with an example of constructing a house as deﬁned in Table 3.4. In the table below.4. For each task vertex v. we have described a number of tasks. . with the duration of the activity as a weight on the vertex. we assign all the incoming edges to x the same weight as the weight of vertex x in Fig.waa-inc.1. 3. 3. We need to ﬁnd out the minimum possible time to complete a house according to the activities described in the table above.2. A longest path in this graph (Fig. 3. Then there are activities which can run in parallel while some are strictly sequential.3) corresponds to minimum amount of time needed to build the house? Why? The underlying assumption is that we should be able to schedule as many activities in parallel as possible by the pre-requisite relationships.4. the tasks they represent have no pre-requisites) as shown in Fig. On the other hand there are certain activities which if delayed do not necessarily increase the total completion time.4.e.htm).1. So that is an upper limit on time to complete the job. the lower limit will be the length of the longest path in the graph. We also need to identify those activities which are critical: that means increasing the time duration of these activities will certainly increase the total completion time. their IDs. their duration (in days) and what tasks must be completed before they can begin (prerequisites) (http://www.2.com/projex/PERT/aoa. 3.4. 3. Now for each vertex x in Fig. If we are unable to schedule any activity in parallel then the total time needed to construct the house will be the sum total of (the duration of) all activities.An Activity Scheduling Problem 47 3. We represent each activity in the table using a vertex.1. we add a directed edge to all the vertices such that the task they represent are dependent on the completion of task represented by v.

their IDs. Algorithm 4: Find Minimum Time to Complete the Job. In such applications each packet or frame of data may be processed through various transforms in a ﬁxed sequence. Models & Graphs: Why Study Graph Theory? Task Description Clear land Lay foundations Build walls Electrical wiring Plastering Landscaping Gardening Interior work Roof Handover Duration 14 28 42 21 21 20 10 35 50 00 Prerequisites none 1 2 3 4.1: We have tabulated a number of tasks. A new problem: You need to transform it into a known problem in graph theory? The challenge is to transform one problem (Algorithm 4) into a text book problem (Algorithm 5) 3. their duration (in days) and what tasks must be completed before they can begin (prerequisites).5. Output: Minimum Time to complete the job.48 Task ID 1 2 3 4 5 6 7 8 9 10 Problems. 9 2 6 5. Duration. 9 3 7.5 A Dual Machine Serial Processing Environment Chain like program graphs is common in many digital signal processing applications.1. 3. Each program module in the chain structure may have a very diﬀerent computation requirement.1). and Pre-requisites (Table 3. This kind of computing has a typical serial or chain like structure as shown in Fig. 1. Input : Tasks. 8 Table 3. one module may run faster on one processor while the same module may take much longer time on a diﬀerent machine in a typical distributed .

A text book problem.4.A Dual Machine Serial Processing Environment 49 Algorithm 5: Find Longest Path between two given vertices in a directed acyclic graph D Input : A weighted directed acyclic graph D and two vertices Output: The Longest Path between two given vertices in D 1. see Chapter 5 6 20 7 10 1 14 2 28 42 3 4 21 50 9 21 5 8 35 10 00 Figure 3.4.2: Transformation to a new graph .1: Graph representing a speciﬁc instance of the activity scheduling problem 10 6 20 21 21 35 00 7 00 14 1 28 2 42 3 4 5 8 10 50 9 21 35 Figure 3.

5. the total time of computation is the sum of total execution times plus the total communication times. The communication cost between module 2 and 3 is 50 provided the two modules are placed on diﬀerent machines. Models & Graphs: Why Study Graph Theory? 10 6 20 21 21 35 00 7 00 14 1 28 2 42 3 4 5 8 10 50 9 21 35 Figure 3.1. 3. The execution cost of each module on either processor is indicated below each module. For example the execution cost of module 2 on processor A is 20 while it is 90 on processor B.50 Problems. A straight forward greedy solution would be to assign a module on a processor where it is least costly but then if two modules with a lot of communication traﬃc in between are assigned to diﬀerent machines then it will again degrade the over all performance.4. Let us concentrate on a sub-problem in order to appreciate the intricacies of the problem.3: Finding the longest path corresponds to the optimal scheduling of activities heterogeneous computing environment consisting of two processors as shown in the bottom diagram of Fig. . In such a distributed heterogeneous computing environment we should somehow take advantage of the diverse and special characteristics of each machine as assigning all modules of the program to one machine may not be an optimal solution. The top diagram of the same ﬁgure shows a chain structured modular program consisting of four modules. it is zero if the two modules are assigned to the same machine. A module can be processed on either processor A or on processor B but only one processor is active at any time.

2. while there will be no cost of communication as the two modules are executed on the same machine. Module 1 as well as 2 is processed on processor A: Then Cost of Execution will be 70+20 = 90.5. Module 1 is executed on machine A while module 2 is processed on . 3. Module 1 as well as 2 is processed on processor B: Then Cost of Execution will be 50+90 = 140.1: (Bottom) Processor A and processor B connected with a high speed communication link. For example the execution cost of module 2 on processor A is 20 while it is 90 on processor B. (Top) A chain structured modular program consisting of four modules (or nodes). There are basically four possibilities for the ﬁrst pair of adjacent modules to be assigned onto the dual processor system: 1. while there will be no Cost of Communication as the two modules are executed on the same machine.A Dual Machine Serial Processing Environment 51 Communication Costs 10 Execution Costs Processor B 50 Processor A 70 90 20 50 30 40 20 0 20 80 Processor Processor Figure 3. The two machines have diﬀerent capabilities. The communication cost between module 2 and 3 is 50 provided the two modules are placed on diﬀerent machines. it is zero if the two modules are assigned to the same machine. The execution cost of each module on either processor is indicated below each module.

3. it is not a distributed assignment. Problem 3. How about if instead of a chain structure. we design Algorithm 2. .4.3.8. Problem 3. Models & Graphs: Why Study Graph Theory? B. and 3.1. Total Cost = 80.3.6. Problem 3.2. Problem 3. Find the total cost if all modules are assigned to machine B.3. The challenge is to ﬁnd the optimal solution for the entire problem eﬃciently (without enumerating all possibilities as we did for the sub-problem). 4. This is also sequential processing but this time on machine B. Problem Set 3. Cost of Execution will be 50 + 20 = 70. The last option provides the optimal solution in terms of minimum completion time for the sub-problem. while there will be a Communication Cost = 10. Find the total cost if all modules are assigned to machine A. and so on. How to model this problem in graph theoretic terms? Problem 3. Please note that the cost consists of two parts. 2. module 2 on processor A. while there will be a Communication Cost = 10. Now calculate the Total Cost of this assignment after taking into account the communication costs. Problem 3. Module 1 is executed on machine B while module 2 is processed on A.3. Cost of Execution will be 70 + 90 = 160. For example assign module 1 on processor B. and the cost of communication between two adjacent modules provided the two modules are assigned to diﬀerent machines.52 Problems. There is no communication cost if the two (adjacent) modules are assigned to the same machine.3.3. Total Cost = 170. Hints are provided in the following ﬁgures. How about if we (initially) ignore communication costs and assign a module on a machine where it is least costly. The total time of computation is the sum of total execution times plus the total communication times. Find the Optimal Assignment by hit and trial (the size of this problem is small enough)? It should be less than (or equal to) the ones found in 1.5.6 and Algorithm 2.3. cost of execution of a module on a processor. This is standard sequential processing on machine A.

2: (top) We show the possibility of all modules assigned to either processor A or to processor B. This is equivalent to traversing a path which passes though the top vertices or the bottom vertices in a graph with two dummy vertices.5.A Dual Machine Serial Processing Environment 53 90 50 30 20 0 u4 00 Path B: All Modules on Machine B 70 Path A: All Modules on Machine A 00 0 20 40 80 90 50 10+90 30 50+30 20 0 u4 00 20+20 70 10+20 50+40 20+80 00 0 20 40 80 Figure 3. (Bottom) The possibility of some modules assigned to processor A while other modules to processor B is shown with a zigzag path between the two dummy vertices. . A shortest path corresponds to an optimal assignment.

3: (top) Path B corresponds to all modules assigned to processor B while path A corresponds to all modules assigned to processor B.54 Problems. .5. (bottom) The module assignment corresponding to path X in the top diagram. Path X corresponds to some modules assigned to processor A while others are assigned to processor B. Models & Graphs: Why Study Graph Theory? 90 50 10+90 30 50+30 20 0 u4 00 20+20 70 10+20 50+40 20+80 00 0 20 40 80 50 70 10 90 20 50 30 0 40 20 20 0 80 Figure 3.

Cut X corresponds to the module assignment as shown in the bottom diagram.4: (top) A cut in this graph (which disconnects vertex A from vertex B) corresponds to an assignment of modules. .5. Cut A corresponds to all modules assigned to processor A.A Dual Machine Serial Processing Environment 55 50 B 70 10 90 50 30 0 20 40 20 0 80 A 20 B B 50 10 70 20 90 50 B 30 0 40 20 20 0 80 A CUT A 70 20 40 80 50 70 10 90 20 50 30 40 20 20 0 80 Cut X 50 90 30 20 CUT B Figure 3. Cut B corresponds to all modules assigned to processor B.

A text book problem.56 Problems. 1. A new problem: You need to transform it into another known problem in graph theory? Algorithm 9: Find Minimum Cut which disconnects vertex s from vertex t in a graph G Input : An un-directed graph G and two vertices (s and t) Output: A Minimum Cut (which disconnect s from t) 1. A text book problem. see Chapter 6 . Models & Graphs: Why Study Graph Theory? Algorithm 6: Find Minimum Cost Assignment Input : Execution & Communication costs of each module on Processors A & B Output: Minimum Time to complete the job & the corresponding module assignment. A new problem: You need to transform it into a known problem in graph theory? Algorithm 7: Find Shortest Path between two given vertices in a directed acyclic graph Input : A directed acyclic graph D and two given vertices Output: A Shortest Path between two given vertices in D 1. 1. See Chapter 5 Algorithm 8: Find Minimum Cost Assignment Input : Execution & Communication Costs of each module on Processor A & B Output: Minimum Time to complete the job & the corresponding module assignment.

The following ﬁgures will provide hints to make multiple transformations. T GA. CAAC. The challenge is to tranform this problem into a know problem in graph algorithms. and Fig. 3. . ACAT. CACA. it does not provide us about the order of the strings or their position in the DNA fragment. Then we can ﬁnd a sequence s as shown in Fig. AGT }. Another challenge is to design Algorithm 8 and then use the text book Algorithm 9 in order to solve the Minimum Cost Assugnment Problem. given its spectrum. The sequencing by hybridization problem in molecular biology (or simply the spectrum problem) can be transformed either into a Hamiltonian path problem or an Euler path problem in directed graphs depending upon whether we map every element of the spectrum into a node or an edge of a directed graph respectively.6. T ACA. an array (also known as the Gene Chip) tells us about all sub-strings of a ﬁxed length that the DNA sequence contains. ACAG. Fig. 3. Assume that Spectrum(s. ACAA. 3)) will be equal to {CAT.1.6. ACAC. AACA}.Sequencing by Hybridization in Computational Biology 57 The challenge is to design Algorithm 6 and then use the text book Algorithm 7 in order to solve the Minimum Cost Assignment Problem. & T ).6 Sequencing by Hybridization in Computational Biology The Sequencing by Hybridization technique depends on the hybridization of target DNA fragment against a very large array of relatively short probes. 4) = {AT AC. With a given unknown DNA sequence (of four letters A. C. G.3. 3. CAT A. The elements in the spectrum may not appear in the same order and the challenge is to ﬁnd the string s. For example if the (unknown) sequence s = CAT GAGT then a set of all substrings of length 3 that s contains (known as Spectrum(s. AT G.6. 3.2. GAG. In fact there are multiple strings possible (s1 = ACACAACAT ACAG & s2 = ACAT ACAACACAG) with the same spectrum as illustrated in these diagrams.

l) Input : Spectrum(s. see Chapter 8 Algorithm 12: Find an Euler Trail in G Input : A graph G Output: An Euler path in G 1. A text book problem.58 Problems. Models & Graphs: Why Study Graph Theory? Algorithm 10: Find a (Correct) Sequence s given its Spectrum(s. see Chapter 7 Transform the sequencing problem into Hamiltonian path and then into an Eulerian path problems (see the ﬁgures below) . 1. Output: Sequence s. A text book problem. A new problem: You need to transform it into a known problem in graph theory? Algorithm 11: Find a Hamiltonian Path in G Input : A graph G Output: A Hamiltonian Path in G 1. l) of an unknown s.

CAAC. A directed edge exists from one vertex to another provided the last three letters of the ﬁrst vertex match with the ﬁrst three letters of the second vertex. CACA.1: We start with a Spectrum(s. AACA} and show a directed graph in which every element of the spectrum was mapped onto a vertex. ACAG and ACAT .Sequencing by Hybridization in Computational Biology 59 Spectrum(s. TACA. ACAT. T ACA. CAT A. ACAA. ACAG. CAAC. ACAG. ACAC.4) = {ATAC. . 4) = {AT AC. AACA} ACAC ATAC ATAC CATA ACAT ACAG TACA CACA ATAC TACA ATAC TACA CATA TACA ACAG ACAA ACAT CAAC AACA ATAC CATA ACAT ACAG TACA Figure 3.6. ACAC. That is why there are four directed edges emanating from the vertex T ACA. CATA. CACA. the edges are going to vertices labeled with ACAA. ACAA. ACAC. ACAT.

1. 3.6. Both these diagrams show various stages in the reconstruction of a sequence. .6.2: (Left) A Hamiltonian path is shown in bold in the graph of Fig. (Right) Another Hamiltonian path is shown in the same graph. this Hamiltonian path corresponds to a sequence s2 = ACAT ACAACACAG. Models & Graphs: Why Study Graph Theory? Start ACAC ATAC ACAC ACACA CACA ACATAC ATAC ACAC CACA ACATA CATA TACA ACAG ACAA ACACAA CATA TACA ACATACA ACAG ACAA ACAT ACACAACAT ACAT CAAC AACA ACACAAC ACAT Start CAAC AACA ACACAACA Figure 3.60 Problems. this Hamiltonian path corresponds to the sequence s1 = ACACAACAT ACAG.

AACA} ? ? ? ATAC ? ACAG ACAC ACA CACA ACAT AACA ACAA CAC CATA ? ? CAG ACAT TACA TAC AAC CAAC CAA CAT ATA ATAC TAC ACA ACAT CAT ATAC CATA CAT CATA ATA TAC CAT CATA ATA ACA ACAT ATAC ATA Figure 3. ACAG.6. . TACA.3: We start with the same Spectrum(s. 4) = {AT AC. the start vertex carries the ﬁrst three letters of the edge while the end vertex is labeled with the last three letters of the edge. T ACA.4) = {ATAC. ACAC. For example the directed edge AACA emanates from CAAC and terminates at AACA. CATA. An edge also speciﬁes its end vertices. ACAT. CAAC. ACAT. ACAA. AACA} and this time we map every element of the spectrum into an edge of a directed graph. ACAA. CAT A. ACAC. CACA. ACAG. CAAC. CACA.Sequencing by Hybridization in Computational Biology 61 Spectrum(s.

Please note that in both the Euler paths shown in this diagram there is a vertex which is repeated several times while every edge is traversed exactly once. We shall provide you below a certain sequence of questions to guide your search towards a suitable transformation. Experience can help you a lot in moving forward. Does your problem have an inherent graphical structure? If yes then the transformation may be a lot simple. Models & Graphs: Why Study Graph Theory? AACA ACA ACAC CAC CACA ACA ACAA CAA CAAC AAC ACA ACAT ACAG TACA ATAC CATA CAG ACA TAC ATA CAT ACA ACAT CAT CATA ATA ATAC TAC TACA ACA ACAA CAA CAAC CAG ACAG ACA CACA CAC ACAC ACA AACA AAC Figure 3. 3. 3. 1.7 Discussion & Problems How can we exploit graph theory in order to solve an unknown problem? In other words how can we reduce the unknown problem into a graph problem? Finding the right reduction or transformation is not easy. (Bottom) Another Euler path is shown in the same graph.4: (Top) A Euler path in the graph of Fig.6. It is certainly not possible to design an exact algorithm to do this transformation. For example in the ﬁrst example . this Euler path corresponds to the sequence s1 = ACACAACAT ACAG.1. you should also try to ﬁnd why or why not. this Euler path corresponds to the sequence s2 = ACAT ACAACACAG. we can only rely on heuristics.62 Problems. Note that most of these questions may not have a black and white answer.6.

l) is given. it is much easier to make a special case reduction. 2. 4. Sometimes it is diﬃcult to make a general transformation.4. 3. The last example has an implicit directed structure. In the second example we need to minimize the sum total of execution and communication costs of a modular program. 3. Strangely this is equivalent to ﬁnding a longest path in a directed acyclic graph as shown in Fig. in its ﬁrst transformation it is transformed into a directed graph. The activities have weights. Do you map each element of your unknown problem into a vertex or an edge of a graph? Example 3 is a good illustration of this decision.Discussion & Problems 63 we have activities and a pre-requisite relationship among themselves. Do components of your problem have a sequence (or an order) which can be transformed into a directed graph? The ﬁrst example certainly implies a directed graph. these weights can be shifted to vertices if each vertex corresponds to an activity in your graph. it is also reduced into a graph problem applicable to an un-directed graph. In the ﬁrst example we need to minimize the total completion time of building a house. Thus this example is also reduced to a directed graph problem.1. we need to ﬁnd an unknown sequence s for which the Spectrum(s. only a certain sequence (or order) of letters can correspond to a correct sequence s. it is rather impossible to capture its essence without directions. The last example is not an optimization problem. If you decide to map each element of the Spectrum onto a vertex then an edge in this graph would represent what (and on what basis)? Will this be a directed edge or undirected? 5. Is your unknown problem an optimization problem or otherwise? If it is an optimization problem where you need to maximize (or minimize) some parameter then you need to search for a graph optimization problem. The second example is perhaps more interesting. this naturally leads to a directed graph. This problem is reduced to ﬁnding a shortest path in a directed graph. This problem is reduced to a decision problem (not an optimization problem) in graph theory whereby we decide if it is possible to ﬁnd a Hamiltonian Path (or an Euler trail) in a directed graph. For example in the second example it is much easier to visualize the special case (in terms of a .

It is a special graph in the sense that an edge between two vertices belonging to the same part (men or women) is not allowed. One is shown in Fig.5. The quantitative aspects of this problem will be discussed in the coming problems.) This problem can be modeled by a graph consisting of each man and woman as a vertex. Please note that the reduction (which ever is correct) not only tells you if a . In the second reduction the problem is reduced to ﬁnding maximum vertex-disjoint paths between the same two vertices in the graph G. The problem is to ﬁnd out if it is possible to marry each woman to a man she likes or knows. This reduction depends upon the hypothesis that each vertex-disjoint path between vertex s and t in graph G corresponds to a matching edge in the bipartite graph. we assume that we have a collection of men and an equal number of women. each women knows (or likes) some of the men. A liking between a man and a woman is represented by an edge between the two corresponding vertices.4.64 Problems.2. and a B part consisting of women.7. and the other is shown in Fig. Problem 3. In the ﬁrst reduction. Models & Graphs: Why Study Graph Theory? graph problem) when all modules are assigned either to processor A or processor B as shown in the top diagram of Fig. Please note that the graph consists of two parts – an A part consisting of men. This special case more or less resembles the activity scheduling problem discussed in the ﬁrst example.7. If it is not possible to ﬁnd such a Perfect Matching then we should perhaps maximize the number of women each of whom is married to man whom she knows. 3.2. 3. We show two reductions of this problem.4. we reduce the Marriage Problem into a problem of ﬁnding maximum edge-disjoint paths between vertex s and vertex t in a graph G. Problem Set 3. The graph is shown below. (Please note that here we have not accounted for the amount of liking between a man and a woman – we just claim that a certain woman knows or likes or does not like a certain man. The Marriage Problem is a well-known problem in mathematics as well as in any middle class conservative society.1. Such a graph is known as a bipartite graph. The problem is to ﬁnd out which reduction is correct and which one is false. This reduction depends upon the hypothesis that each edge-disjoint path between vertex s and t in graph G corresponds to a matching edge in the bipartite graph.1. 3. In one case you have to design an informal proof and in the other case you have to design a counter example.

7.1: We add vertex s and vertex t to a bipartite graph and then try to reduce a maximum bipartite matching problem into another problem where we maximize edge-disjoint paths between vertex s and vertex t.Discussion & Problems 65 a1 a2 A a3 a4 b1 b2 B b3 b4 A Matched Edge a1 a2 A a3 a4 b1 b2 B b3 b4 Bipartite Graph C Corresponds Transforms Maximum Matching in Graph C Transforms Graph G with nodes s & t A Path from s to t Maximum Edge-Disjoint Paths in Graph G a1 a2 b1 b2 B b3 b4 a1 a2 a3 a4 b1 b2 s A a3 a4 t Find Max EdgeDisjoint Paths s A t b3 b4 Figure 3. .

2: We add vertex s and vertex t to a bipartite graph and then try to reduce a maximum bipartite matching problem into another problem where we maximize vertex-disjoint paths between vertex s and vertex t.7. Models & Graphs: Why Study Graph Theory? a1 a2 A a3 a4 b1 b2 B b3 b4 A Matched Edge Corresponds a1 a2 A a3 a4 b1 b2 B b3 b4 Bipartite Graph C Transforms Maximum Matching in Graph C Transforms Graph G with nodes s & t A Path from s to t Maximum Vertex-Disjoint Paths in Graph G a1 a2 b1 b2 B b3 b4 a1 a2 a3 a4 b1 b2 s A a3 a4 t Find Max NodeDisjoint Paths s A t b3 b4 Figure 3. .66 Problems.

We also need to identify which woman is marrying whom. the problem is how to ﬁnd one? Assume that the only operation that we can perform is to ﬁnd a Permanent of the matrix after or before removing an edge of the bipartite graph. Thus if P er(C) is zero then no perfect matching exists.Discussion & Problems 67 perfect matching is possible. We consider the same Marriage Problem as described before. The said edge will be part of a perfect matching if and only if P er(Cyz) is non zero. If a perfect matching does not exist then we need to maximize the number of marriages as before. Here we start with the adjacency matrix C of the bipartite graph C.7. The problem of ﬁnding a perfect matching is thus reduced to ﬁnding the permanent of a matrix.4. An alternate way of ﬁnding a perfect matching in a bipartite graph is demonstrated in Fig.2. In case a perfect matching is not possible. z) is part of a perfect matching in the bipartite graph. We need to ﬁnd if a Perfect Matching exists in a given bipartite graph C. 2. 3. 1.4. Problem 3. For example the P er(C) of the matrix shown in the ﬁgure below will be computed as follows: P er(C) = a11 a22 a33 + a11 a23 a32 + a12 a21 a33 + a12 a23 a31 + a13 a22 a31 + a13 a21 a32 P er(C) = 0 + 1 + 0 + 1 + 1 + 0 = 3 As you can see each individual term in the expression for Permanent is a permutation – there is a one to one correspondence between each non zero term in this expression and a perfect matching in the bipartite graph. The permanent P er(C) of a matrix C is computed like the determinant of C except that the signs of all permutations are positive. On the other hand if it is non zero then there will be as many perfect matchings as the value of P er(C). Once we know that a perfect matching exists in the given bipartite graph C. the reduction maximizes the number of marriages taking place. it also tells us which woman to marry whom. On the . How can you ﬁnd a Perfect Matching in this graph? Discuss brieﬂy. We reduce the problem into ﬁnding the permanent of the matrix C. We need to ﬁnd if an edge (y.

Models & Graphs: Why Study Graph Theory? 1 1 2 2 3 3 Pe r fe ct M at ch in g if Pe r(C )n ot ze ro Figure 3.68 Problems.7. . We take the permanent of the adjacency matrix and claim that a perfect matching in the bipartite graph exists if and only if the value of the permanent is non zero.3: We show a bipartite graph and its adjacency matrix shown in the top diagrams.

4: If a perfect matching exists in a bipartite graph then it is possible to ﬁnd if an edge is part of that perfect matching. Find Pe M ct rfe atc hin g .7.Discussion & Problems 69 Does this edge part of Perfect Matching? 1 0 1 Pa Ed 1 1 1 1 1 0 Adjacency Matrix of C a1 Bipartite Graph C b1 b2 B b3 ge 1 0 1 1 1 1 1 1 0 rt of a2 A a3 0 1 1 1 Pe rf e ct M at c hi ng Ex is ts Find Permanent of C not zero If Permanent is not zero Figure 3.

70

Problems, Models & Graphs: Why Study Graph Theory? basis of this observation, design an eﬃcient algorithm to ﬁnd all edges belonging to the perfect matching.

3. It is much more complex to ﬁnd the permanent of a matrix as compared to ﬁnding the determinant of a matrix – thus we are tempted to check if the determinant is as helpful as the permanent of a bipartite graph? How about if we ﬁnd that the determinant of an adjacency matrix of a bipartite graph is non zero? Under such conditions, can we make a claim that a perfect matching exists in the graph? How about if the determinant is zero – can we claim that a perfect matching does not exist in the bipartite graph? Remember that the determinant of a completely connected bipartite graph is zero in spite of the fact that every permutation of the vertices of the bipartite graph is a perfect matching.

4. We know that the determinant of a completely connected bipartite graph is zero, why? How about if we put random weight on each edge of the bipartite graph? The probability of the value of the determinant becoming zero will depend upon the randomness of the weights assigned to the edges of the bipartite graph. So hopefully the determinant of a bipartite graph will not be zero unless there is not a single perfect matching in the bipartite graph. How to ﬁnd the edges of a perfect matching in this graph? How about using the previous technique?

Problem 3.4.3. Consider the (minimum weight) assignment problem. We are given a complete balanced weighted bipartite graph, and we need to ﬁnd a minimum weight perfect matching in this graph – that means a perfect matching in which the sum of weights of all (matched) edges is minimum. For the time being assume that the minimum weight perfect matching is unique. We shall try to relax this condition later.We use the same reduction in this problem as was used in the last problem with one slight modiﬁcation. All edge weights in the adjacency matrix C are raised to the power of 2, and then we take the permanent of matrix C. The highest power of 2 which divides the value of the permanent is the weight of the minimum weight perfect matching.

Discussion & Problems

71

P er(C) = 28+1+8 + 28+8+8 + 28+8+8 + 28+8+2 + 23+1+2 + 23+8+8 = 217 + 224 + 224 + 218 + 26 + 219 = 26 (1 + 217 + 224 + 224 + 218 + 219 ) Raising all weights to a power of two and then ﬁnding the permanent of the weighted matrix gives us a powerful reduction in which each individual term in the permanent is in fact the weight of a perfect matching raised to power of 2. The value of the permanent will be divisible (with remainder equal to zero) by the weight of minimum weight perfect matching raised to the power of 2 provided we have a unique minimum weight perfect matching in the bipartite graph. 1. Design an eﬃcient algorithm to ﬁnd edges belonging to the minimum weight perfect matching. The only reduction that you can use is to ﬁnd permanent of a matrix. Of course you can raise a number to the power of 2 or any other number of your choice. 2. What complications can arise in ﬁnding the value of minimum weight perfect matching provided such a matching is not unique? 3. Assume that now there is a possibility that the minimum weight perfect matching is not unique. You need not ﬁnd the value of the minimum weight perfect matching – just make an eﬃcient check if it is unique or not?

72

Problems, Models & Graphs: Why Study Graph Theory?

All other edge weights are 8

a1

3 2 1

b1 b2 B b3

8 8

8 8 8 8

8 2 8 2 2 2

8 2 1 2 8 2

3 2 8 2 8 2

a2 A a3

Transforms

Weighted Bipartite Graph C

**Weighted Adjacency Matrix of C
**

Find

a1

3 2 1

b1 b2 B b3

The weight of minimum weight perfect matching

The highest power of 2 which divides the permanent will be

a2 A a3

1+2+3=6

6

217 + 224+ 224+ 218+ 26 + 219

Figure 3.7.5: A minimum weight assignment problem is reduced to evaluating the permanent of a matrix. Problem 3.4.4. Consider the assignment problem in which we have a complete weighted bipartite graph and we need to ﬁnd a minimum weight perfect matching. In Chapter 5 we shall reduce this problem into a well known shortest path ﬁnding problem in any directed or un-directed graph. Shortest path ﬁnding algorithms are relatively simple and are discussed in Chapter 4. Here in this problem we shall discuss a (bizarre) reduction in which we reduce the shortest path problem into the assignment problem. We start with a black box which accepts a complete weighted bipartite graph as input and outputs the minimum weight perfect matching. The output also includes edges (or vertices) belonging to minimum weight perfect matching. We show a weighted graph G in Fig. 3.7.6 where we need to ﬁnd a shortest path from vertex a to vertex d. The weighted adjacency matrix of this graph is also shown in the top right diagram of this ﬁgure. Using this pp matrix we

Discussion & Problems

73

a

8

2 4

b

a a b c

0 2 5 8

b

2 0 3 4

c

5 3 0 6

d

8 4 6 0

3 5

d

6

c

d

Given a weighted graph G find a shortest path between a to d

Adjacency Matrix of weighted graph G

a

5

2

b

3

0

b

3

b a b c

Transform

Transforms

c

5 3 0

d

8 4 6

2 0 3

c

6

0 4

c

8

d

Figure 3.7.6: A weighted graph G is shown in the top left diagram. We need to ﬁnd a shortest path between vertex a and vertex d. The adjacency matrix of a weighted graph G is shown in the top right diagram. The shortest path problem is converted into a minimum weight perfect matching problem as shown in the bottom diagrams.

74

Problems, Models & Graphs: Why Study Graph Theory?

generate a weighted (complete) bipartite graph of size (p−1)(p−1) by deleting the column corresponding to vertex a and the row corresponding vertex d as shown in the bottom left diagram. We claim that a minimum weight perfect matching in this bipartite graph gives us a shortest path between vertex a and vertex d as shown in Fig. 3.7.7.

a

8 5 2 4 3

b

0 2 5

2 0 3 4

5 3 0 6

8 4 6 0

Transforms

2 0 3

5 3 0

8 4 6

d

Given a weighted graph G find a shortest path from a to d

Adjacency Matrix of Graph G

a a

8 5 2 4 3

Transform

2 5

a

5

Transform

6

c

8

2

b b

0 3

b

3

Transform

b

3

0

b

3

c c

6

d

0 4

c

8

c

6

0 4

c

8

6

A Shortest Path from vertex a to d

d

Find a Minimum Weight Perfect Matching

d

A Complete Weighted Bipartite graph

Figure 3.7.7: The shortest path problem is converted into a minimum weight perfect matching problem as shown in the top diagrams. We ﬁnd a minimum weight perfect matching in the complete bipartite graph shown in the bottom right diagram. The minimum weight perfect matching (shown in the bottom middle diagram) provides a shortest path between vertex a and vertex d as shown in the bottom left diagram. Consider Fig. 3.1.1, here the New Problem is ﬁnding shortest path between two vertices in a graph G while the Old Problem is the minimum weight

Discussion & Problems assignment problem.

75

1. Design an eﬃcient algorithm to transform this problem (of ﬁnding a shortest path between two vertices in a weighted graph) into a complete bipartite graph as shown in Fig. 3.7.7. In terms of Fig. 3.1.1, design Algorithm No. 1. 2. Design an eﬃcient algorithm to transform the minimum weight perfect matching into a shortest path between the two given vertices; in terms of Fig. 3.1.1, you will be designing Algorithm No. 2.

76

Problems, Models & Graphs: Why Study Graph Theory?

Chapter 4 Basics of Graph Theory

4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9

Introduction A Mutual Friendship Graph Representation of a Graph Complement of a Graph Equal Graphs & Isomorphic Graphs The Degree Sequence Walks, Trails, & Paths Multi-graphs and Pseudo-graphs Broad Categories of Graphs & some Special Graphs

4.10 Integration of Concepts, Properties, and Action Items 4.11 Self Complementing Graphs

78

Basics of Graph Theory

4.1

Introduction

We shall discuss a number of basic deﬁnitions in this chapter. We will be solving a couple of puzzles; hopefully the students will realize that in such problems a stage comes when common sense alone is not suﬃcient to solve the puzzle; we need tools and techniques of graph theory. We shall discuss some necessary conditions for a degree sequence to be graphical. We shall then talk about graph isomorphism and then come back to a discussion of necessary and suﬃcient conditions for a degree sequence to be graphical. The concept of graph connectedness will also be provided; we shall deﬁne a walk, a trail and a path in a connected graph. We shall also talk about some special graphs at the end of this chapter.

4.2

A Mutual Friendship Graph

Assume that we have 5 persons in a hall. Let us name these people as A, B, C, D, & E. Some of these people are friendly with each other while others are not; we assume that their friendship is symmetric; that means if person x knows y then it means that y knows x (for every pair (x, y)). We ask each person with whom he or she is friendly with and we get an answer like A is friendly with B only while B is friendly with A, D, and C. This so called mutual friendship is represented by the top left diagram in Figure 4.2.1. Please note that the double sided arrows emphasize the mutual friendship between two persons; as discussed before we are talking about a symmetric relationship. With each person in this diagram we show the number of people with whom he (or she) is friendly with; thus A is friendly with just one person while B is friendly with three persons. This number in fact represents the amount of popularity a person enjoys; Persons B and D are the most popular persons while persons A and E are the least popular. If we note down this popularity number, and then sort this sequence we get the so called friendship sequence; this sequence is also shown in the top left diagram. The top left diagram in Fig. 4.2.1 is transformed into a graph shown in the top right corner of the same ﬁgure. Here each person is represented by a node or a vertex; a double arrow edge is represented by an un-directed edge; the relationship of friendship in the top left diagram is now transformed into an adjacency relationship in the graph shown in the top right diagram. Now instead of a friendship sequence we have a degree sequence; this sequence is

Representation of a Graph

79

exactly the same as the friendship sequence and is shown in the top right corner as well.

Figure 4.2.1: We show ﬁve persons with a symmetric friendship relationship indicated by lines with double sided arrows in the top left diagram. The relationship is transformed into an un-directed graph as shown in the top right diagram. The friendship sequence as well as the degree sequence is also indicated along with the respective diagrams. The adjacency matrix representing the graph is shown in the bottom diagram.

4.3

Representation of a Graph

The graph shown in the top right corner in Fig. 4.2.1 is modeled by an adjacency matrix data structure as shown in the bottom diagram of Fig. 4.2.1. In this adjacency matrix a 1 represents an adjacency relationship while a

C says 2 and D says 1. Is the husband telling the truth assuming the guests told the truth? How about if he answers 3 (he showed no discrimination).1. for example the degree of vertex A is 1 while the degree of vertex B is 3. Why? 2. 4. Aslam shook hands with some of the guests. In a group of ﬁve persons (as shown in Fig. In addition to these we have other interesting limitations as discussed below. . the smallest number can not be less than zero. Obviously Salma was curious about whom Aslam shook hands and with whom he did not.1. Why? Problem Set 4. Find out the number of times the husband actually shook hands and more importantly with whom he shook hands and whom he has ignored.1. Please note that if these conditions are not met then the sequence will not be graphical. The degree of each vertex is also shown in the last column of the bottom diagram. there is neither any room for negative friendship with some one which means animosity.80 Basics of Graph Theory zero (or an absence of 1) represents no adjacency relationship between the corresponding nodes in the graph. The sum of all numbers in the sequence will always be an even number. she gets the following answer: B says 3.2. Salma’s husband Aslam (known as A) received the guest when they have arrived while Salma was in the kitchen preparing food. from now onwards we shall use the term “the sequence”. It will be interesting to explore the (special) structure of the friendship sequence (or the degree sequence). The sum of all one’s in a row corresponds to the degree of a vertex. what does that mean? 1. Now Salma asks the same question to her husband. he answers zero (he does not shake hands with females). Salma invites three of her oﬃce colleagues for dinner.1) the largest number can not be larger than four. Why? 3. At least one number will be repeated in the sequence. The odd numbers in the sequence will appear even number of times. She can not ask this question directly so she simple asks every colleague about the number of hands she had shaken. what does that mean? Under such conditions the sequence will neither be a friendship sequence. This is because in our understanding of friendship there is no room for self friendship. Problem 4. When we sort the numbers in the last column then we get the degree sequence or the friend-ship sequence.

The diagram on the right shows the next stage. The diagram on the left shows the graph in the making. This time Aslam asked each person including his wife to write on a slip of paper how many hands he or she has shaken.2. (a) Determine if you can seat these people around a round table so that every two neighbors are acquainted. The acquaintance graph of a group of eight people is given in the following diagram.3. Salma & Aslam has invited three married couples.1.1. It is not yet obvious where Salma is and where Aslam is? Each bigger circle in these diagrams contains a husband and wife pair. No one shook hands with one self or with his or her spouse. (b) If answer to (a) is no then is it possible to seat the people around a table so that every two neighbors are acquainted as far as possible? (c) Determine if you can seat these people around a table so that every two neighbors are not acquainted D H G H G . Several handshakes took place when the guests have arrived. the motivation behind this seating strategy is to create a lively atmosphere. Surprisingly each person gave a diﬀerent answer but Aslam does not know which answer belongs to whom.1: We show some intermediate stages (and hints) in the solution of Problem 4.Representation of a Graph 81 Problem 4.3.2.1. Now Aslam is curious about the following: (a) Did a female shake hands with a male? (b) Did Salma shake hands with a male friend? (c) How many times Salma shake hands? (d) How many times Aslam shake hands? (e) Assume that Salma has not shaken hands with any male friend then did Aslam shake hands with a female? Under such conditions was there a husband who refused to shake hands with a female? A B A B C C D F E F E Figure 4. Problem 4.

We show a graph G and its complement H in Fig. we shall need some of its (graph isomorphism) results for formulating necessary and suﬃcient conditions for a graphical sequence. the motivation behind this seating strategy is to encourage strangers to become acquainted with each other. We shall explore necessary and suﬃcient conditions for a sequence to be graphical but before we do that let us ﬁrst discuss some more basic stuﬀ (in general) and graph isomorphism (in particular).82 Basics of Graph Theory as far as possible.1 on the left most graph and the middle graph respectively Try to visualize a graph C having same number of vertices as in G or H and having an edge uv provided the edge uv exists either in G or in H.4 Complement of a Graph Complement of a graph G is another graph H with the same number of vertices such that there is an edge uv in H if and only if there is no edge uv in G. it will be useful and informative if in each problem you try to actually draw the underlying graph. 4. The ﬁrst problem set (some parts of this at least) also exploits some of the necessary conditions. We have already discussed a number of necessary conditions for a sequence to be graphical.2: The acquaintance graph of a group of eight people is given. Now try to visualize a graph E having .3. F H A B G E D C Figure 4. 4.4. we should be able to draw an actual graph with the same degree sequence. Determine if you can seat these people around a round table so that every two neighbors are acquainted.

4. they may still be isomorphic because we fail to ﬁnd a visible G F E Equal Graphs & Isomorphic Graphs G F E . The degree sequences of both these graphs are also indicated. if you draw an adjacency matrix of each graph (after identical labeling) then you will ﬁnd that the two adjacency matrices are exactly the same.2. A completely connected graph is shown in the right diagram.1: A Graph is shown in the left diagram and its complement is shown in the middle. Thus these two graphs are not equal. 65433210 A B 76544321 A B 77777777 A B C D C D C D F E H Figure 4.5 We show 4 graphs in Fig. and same number of edges.Equal Graphs & Isomorphic Graphs 83 same number of vertices as in G or H and having an edge uv provided the edge uv exists in G and in H. 4. All these graphs have the same number of vertices.1 after identical labeling then the two matrices comes out to be diﬀerent as shown in Fig. If now you draw the adjacency matrices of the graphs shown on the extreme left and middle left in Fig.1. The graph on the extreme left and the graph on the extreme right are in fact equal. If you closely look at the two middle graphs you realize that they are diﬀerent graphs meaning that they are neither equal nor isomorphic. This is because in one graph all the four degree vertices are connected in the form of a triangle while in the other graph this is not so.5. So there is a good possibility that they are all equal to each other. H H G 4. 4.4. the degree of each vertex is also indicated along with each vertex. Note that vertices with the same degree in two diﬀerent graphs are colored similarly. in fact they all have the same degree sequence as shown in the same ﬁgure.5.5.

This is evident from the adjacency matrices of the two graphs shown in the bottom diagram.5. at least two are unequal graphs (why?). at least two are non isomorphic graphs (why?).5. Figure 4.2: Graph G shown in the top left corner is not equal to the graph H shown in the top right corner. . Out of these graphs at least two are equal graphs.84 Basics of Graph Theory Figure 4. There is still a possibility that the two graphs are isomorphic to each other as the two graphs have a number of similar qualities and no obvious diﬀerences.1: We show four graphs each having the same degree sequence. Please note that vertices with the same degree are drawn in the same color. and at least two are isomorphic but not equal.

If. .3: Graph H shown in the top right diagram of Fig.1? These two graphs may still be isomorphic? What does that mean? Two graphs G and H are isomorphic provided they can be drawn with identical graph drawings.Equal Graphs & Isomorphic Graphs 85 diﬀerence like the one that we have found for the two middle graphs of Fig. Figure 4.5.2 is redrawn here in the top right corner after rotating it by an angle of 180 degrees.2 by an angle of 180 degrees then we get a drawing which is exactly the same as the graph G.3. It is quite obvious now that the drawing in the top left diagram is the same as the drawing shown in the top right corner.5. 4. Let f be an isomorphism from the left graph (G) to the right graph (H). 4. Then the two graphs are isomorphic provided there is an edge between f (u1 ) and f (u2 ) in the right graph if and only if there was an edge between u1 and u2 in the left graph for every two vertices in the two graphs as shown in the bottom diagram of this ﬁgure.5. this is shown in Fig. 4.5.5. we rotate graph H of Fig. 4. for example.

Problem 4. Find an isomorphic function from a graph G to graph H in case graphs G and H are isomorphic to each other. and the same degree sequence. which are isomorphic but not equal and which are not isomorphic (and also not equal). Find a visible diﬀerence incase the two graphs are not isomorphic. We show eight graphs with the same degree sequence in Fig. Draw as many graphs as possible such that no two of them should be isomorphic to each other and each graph should have a degree sequence 4443322.4. which two are isomorphic. Find which two of them are equal. Basics of Graph Theory Problem 4. Problem 4. There is a possibility that the degree sequence may not be graphical? Under such conditions . Figure 4. 4.2.5.4: Eight graphs with same number of vertices.1.2.2.6 The Degree Sequence Assume that we are given a degree sequence of a graph and we need to ﬁnd the corresponding graph provided the sequence is graphical. and which two are not isomorphic. 4.2. Draw as many graphs as possible such that no two of them should be isomorphic to each other and each graph should have a degree sequence 332222.5. Find which two graphs are equal (and isomorphic).2.86 Problem Set 4.3.

that amounts to removing the vertex v from the graph G. Also assume that (the highest degree) vertex v is connected to the ﬁrst u vertices (after v) in the degree sequence SG of G as shown in the bottom left diagram of Fig. Remove the maximum degree (which is 4) from the degree sequence SG (thus reducing the length of the sequence from seven to six).6.1 2.6. Subtract 1 from the ﬁrst 4 (because maximum degree was 4) integers of the remaining sequence as shown in the top right diagram of Fig. Now when we perform the ﬁrst operation of removing the maximum degree from the degree sequence. Before moving forward ﬁnd a sequence which satisﬁes all necessary conditions that we have discussed (earlier in this chapter) but it is impossible to draw a graph corresponding to this sequence. this transformation makes no sense unless we visualize these operations as if they are performed on a graph. Algorithm 13 transforms a degree sequence into another degree sequence. Algorithm 13: Convert degree sequence SG into SH . The maximum degree here is 4 and the total number of integers in the degree sequence is 7. Input : Original degree sequence SG (Example 4443322) Output: New degree sequence SH (Example 332222) 1. Please note that removing the vertex v from G means that all . we have already studied some necessary condition at the start of this chapter but those conditions were not suﬃcient (for a sequence to be graphical). The resulting sequence will be 443322 as shown in the top middle diagram of Fig.1. How about the degree sequence 543211? Let us assume we are given a degree sequence SG equal to 4443322. 4. So we need to study necessary and suﬃcient conditions for a sequence to be graphical.The Degree Sequence 87 we claim that it is not possible to draw a graph for that sequence (why it is not possible?).6. The new sequence SH will become 332222 shown in the same diagram. Assume that we have a graph G in which the highest degree vertex is known as v and its degree is u. the new graph H will have number of vertices one less than G. We apply the following procedure on this degree sequence SG and convert it into a new degree sequence SH which is equal to 332222. 4. 4.1.

2. We remove the maximum degree from the sequence and subtract 1 from the ﬁrst 4 integers of the remaining sequence as shown in the top diagrams. The maximum degree here is 4 and the total number of integers in the degree sequence is 7.1.1: We are given a degree sequence equal to 4443322 shown in the top left diagram. Claim 4. This is equivalent to reducing the degree by one of all adjacent vertices of v in G. Figure 4. If the new sequence SH is graphical then the original sequence SG is graphical.6. It is interesting to note that the above claims not only provides us a necessary and suﬃcient condition for a sequence to be graphical. In order to prove this necessary and suﬃcient condition we have to make and prove two claims as follows: Claim 4.6. The new sequence will be shorter by 1 as compared to the original sequence as shown in the top right diagram. We claim (Havel-Hakimi) that the original sequence SG (corresponding to a graph G) is graphical if and only if the new sequence SH (corresponding to graph H) is graphical. This meaningful interpretation is possible provided we have the crucial assumption: the highest degree vertex v in G is connected to the ﬁrst u vertices (after v) in the degree sequence SG of G. they also provide us means to draw a graph corresponding to a graphical sequence.6. You may have realized that the new graph will have a degree sequence equal to SH . So before proving the above claims let ﬁrst do the more interesting exercise of ﬁnding a . If the original sequence SG is graphical then the new sequence SH is graphical.88 Basics of Graph Theory edges emanating from G will also be removed and that amounts to operation number 2.

. 2. and apply the following steps which outputs whether the sequence SG is graphical or not. It is very much possible to have two diﬀerent graphs corresponding to the same degree sequence. transform the sequence into a new sequence using Algorithm 13 (by removing the ﬁrst vertex v from the degree sequence with a degree equal to u. and terminate) or if it is not possible then repeat step (1) on the latest new degree sequence (but sort it if it is not already sorted). In this ﬁgure the seven digit degree sequence is converted into a six digit degree sequence and then ultimately into a four digit degree sequence as shown in the top diagrams. We start with a p length degree sequence. verify that it is graphical. a stage comes when it is very much possible to draw the corresponding graph as shown in Fig. If you get a number less than zero in the new sequence then the original sequence was not graphical (output “No”.6. The four digit degree sequence can be recognized to be a graphical sequence. It is then converted into a 5 vertex graph. 4.2.The Degree Sequence 89 graph. 4.6. Either by carefully looking at the latest new sequence. The corresponding 4 vertex graph is shown in the middle right diagram. Each iteration in the above procedure makes the degree sequence smaller in size. and eventually into a 7 vertex graph as shown in the middle left diagram of Fig. and subtracting 1 from the ﬁrst remaining u degrees of the degree sequence). The resulting graph shown in the bottom left diagram is diﬀerent from the middle left graph shown in the same ﬁgure.2. and terminate) otherwise there are two possibilities. you can draw the corresponding graph (output “Yes”. 1. The two graphs are neither equal nor isomorphic (why?). this has been illustrated by the bottom diagram of the same ﬁgure. and then ﬁnd the actual graph corresponding to this sequence. Let us start with the same degree sequence.

1. This seven vertex sequence is converted into a six vertex sequence. It is very much possible to get two diﬀerent graphs from the same degree sequence. .6. For example if 332222 is graphical then 4443322 is graphical.2: A seven vertex degree sequence is shown in the top left corner.6. Let us design an algorithm to construct a graph G corresponding to an original sequence SG provided the new sequence SH and its corresponding graph H is given. it says that if a new sequence SH is graphical then the original sequence SG is also graphical. This four vertex sequence is graphical as shown by the middle and bottom right diagrams. and then ultimately into a four vertex sequence as shown in the top right corner. We get a four vertex graph which is then converted into a ﬁve vertex graph and ultimately into a seven vertex graph as shown in the middle and bottom left diagrams.90 Basics of Graph Theory Figure 4. Let us now take up Claim 4. Can you design a formal proof for this claim? Is your proof based on induction or is it proof by contradiction? Discuss brieﬂy.

let it be u.6. We are also given the new sequence SH and we need to show that it is graphical. it says that if the original sequence SG is graphical then the new sequence SH is graphical. and its graph H is given. Assume that we are given a degree sequence 4443322 and a graph G as shown in the left diagram of Fig. this is certainly a serious deﬁciency of this algorithm? Before correcting this deﬁciency let us look at it a bit more closely in the next part. 4. Let us now take up Claim 4. just move backwards in Fig.1 then you should be able to prove this claim also. Problem Set 4. Input : (1) New degree sequence SH (Example 332222). 91 1.3.2? Can you design an algorithm similar to (or almost a mirror image of) Algorithm 14. Does Algorithm 15 perform the intended function correctly? This is an important question because the answer may be no.3. Problem 4. Note down the highest degree in the degree sequence SG .6.6. Does Algorithm 14 perform the intended function correctly? Problem 4. Problem 4. Add an edge between the vertex v and the appropriate u vertices in the degree sequence SH (why?). Is it possible to apply .2.The Degree Sequence Algorithm 14: Find a graph G corresponding to an original degree sequence SG provided the new sequence SH and its corresponding graph H is given.3. The said algorithm provides a correct solution provided we have the crucial assumption: the highest degree vertex v in G is connected to the ﬁrst u vertices (after v) in the degree sequence SG of G. If the assumption is not true then this algorithm will not provide correct results. (the degree of v should be u (why?)) 3.3. If you can prove Claim 4. 4. this means that we need to draw the corresponding graph H.6. Add a new vertex v in the given graph H. Output: Original Graph G corresponding to the degree sequence SG . It essentially means that now we are given a graph G corresponding to a degree sequence SG .1. (2) Original degree sequence SG is also given (Example: 4443322).3.3.2. 2.

Why? Once it has been established by Algorithm 16 that a given graph F can . and this vertex is not connected with the ﬁrst u vertices in the degree sequence (after v1 ) of this graph.3. and its graph G is given. Remove the vertex v from the resulting graph and we obtain H (why?). 2. 4. (2) New degree sequence SH is also given (Example: 332222).4. two of these vertices are not connected to the ﬁrst four vertices in the degree sequence of this graph. 3. Input : (1) Original degree sequence SG (Example 4443322). Let this vertex be v and let its degree be equal to u. What will be the result of our algorithm? Why our algorithm fails this time? Discuss brieﬂy. Remove all edges emanating from the vertex v. 1. 1 (Note that graph H corresponds to degree sequence SH ?) Algorithm 15 in order to draw a graph with a degree sequence equal to 332222? Please note that there are three vertices with a highest degree equal to four. We need to convert the graph F into another graph G with the same degree sequence but in G the vertex v1 (having highest degree equal to u) is connected to the ﬁrst u vertices in the degree sequence of this graph.6. We claim that such a transformation is always possible. the maximum degree vertex v1 has a degree u. Please note that there are three vertices in this graph with a highest degree equal to four.3. The following algorithm performs this transformation.92 Basics of Graph Theory Algorithm 15: Find a graph H corresponding to a new degree sequence SH provided the original sequence SG and its corresponding graph G are given. Now repeat the above part with the same degree sequences but this time G is as shown in the right diagram of Fig. Problem 4. none of these vertices are connected to the ﬁrst four vertices in the degree sequence of this graph. Locate the vertex of highest degree in G. Output: Graph H corresponding to the degree sequence SH . Suppose that we are given a graph F and its degree sequence SF .

(Why are you guaranteed to ﬁnd such a vertex vn ? 3. From graph H. remove edges (v1 . the maximum degree vertex v1 has a degree u. graph H is now transformed into graph G? . the maximum degree vertex v1 has degree u. Please note that the two graphs are not isomorphic.The Degree Sequence 93 Figure 4. and this vertex is connected to the ﬁrst u vertices in the degree sequence of this graph. vk ) & (vj . vn ).6. and insert edges (v1 . 1. Locate vertex vk and vertex vj in the graph F such that v1 is connected to vertex vk and not connected to vertex vj while the degree of vj is larger than that of vk .3: Two graphs with the same degree sequence 4443322. Algorithm 16: Convert graph F with a degree sequence SF into a graph G with the same degree sequence (but with an important diﬀerence?) Input : A graph F and its degree sequence SF . In the graph H. vj ) & (vk . (If you can not ﬁnd such vertices then graph F is already transformed into G. there is no need to do any thing else) 2. and this vertex is not connected with the ﬁrst u vertices in the degree sequence (after v1 ) of this graph. Output: A graph G with the same degree sequence. vn ). locate a vertex vn such that vj is connected to vn while vk is not connected to vn .

What is that constructive proof? We show our strategy in handling the necessary & suﬃcient conditions for a degree sequence to be graphical in Fig. 4. We are given a graph G with a degree sequence 432221 as shown in the top left diagram of Fig.5. Concentrate on the third line of Algorithm 14: “Add an edge between the vertex v and the appropriate u vertices in the degree sequence SH (why?)”. 2. Given a graph G in which the maximum degree vertex is connected to the ﬁrst u vertices in the degree sequence of this graph (where u is the degree of the highest degree vertex) it is possible to apply Algorithm 15 in order to transform G into another graph H. 3. We show the position of our claims and the respective proofs.6. Problem 4. 4.6. As shown in this ﬁgure the highest degree vertex is connected to a vertex of lowest degree while it is not connected to a vertex of a relatively higher degree.4.1.94 Basics of Graph Theory always be transformed into another graph G. Given a graph G in which the maximum degree vertex is not connected to the ﬁrst u vertices in the degree sequence of this graph (where u is the degree of the highest degree vertex) it is not possible to apply Algorithm 15 in order to transform G into another graph H. The .6. Problem Set 4. they help us in transforming one graph into another but more importantly they provide crucial insight in designing constructive proofs for the two claims.4.6. Algorithm 16 has also made it possible to design a constructive proof for Claim Number 2. Remember we have discussed this problem in the class but have not resolved it completely.2. Problem 4. 4. It is possible to convert this graph G into another graph with the same degree sequence by using Algorithm 16 as shown in the top right diagram of Fig. Under such conditions we ﬁrst transform G into another graph G using Algorithm 16 and then Algorithm 15 will correctly transform G into H. Let us summarize our recent ﬁndings: 1.6.4. What does appropriate mean? Carefully read your text book (page 17) and then make your decision appropriately. it gives rises to a number of important conclusions. Please note that the three algorithms perform a dual purpose.

All these three vertices (with a degree of 4) are connected to a vertex of minimum degree.4: A seven vertex graph is shown in the left diagram with a degree sequence shown in the top of the graph.6. v1 is connected to two vertices with degree 4 and two vertices with degree three. Here there is at least one vertex (v1 ) with a (highest degree equal to four) which is connected to vertices with higher degrees only. The graph in the left diagram is converted into a graph shown in the right diagram by deleting two edges and by inserting two edges (shown in bold). it is not connected to a vertex of degree 2. The graph in the right diagram has the same degree sequence but there is an important diﬀerence. .The Degree Sequence 95 Figure 4. There are three vertices in this graph with a highest degree equal to four. the minimum degree in this graph is 2.

96 Basics of Graph Theory Figure 4. . There are three vertices in this graph with a highest degree equal to four.6.5: A seven vertex graph is shown in the left diagram with a degree sequence shown in the top of the graph. the minimum degree in this graph is 2. All these three vertices (with a degree of 4) are connected to a vertex of minimum degree.

Do we know how to draw the graph for SH provided we have a graph for SG ? Discuss brieﬂy. e. Is it possible to do some thing in this speciﬁc problem so that the problem is resolved just by applying the said algorithm only once? Can you generalize your ﬁndings? How much can you save in time in the worst case analysis? Figure 4. Let another sequence be SH = b − 1.3. g. The ﬁgure down below may be helpful for your imagination. b. c. Let a degree sequence consisting of 11 numbers be SG = a. i.The Degree Sequence 97 problem (that the highest degree vertex is connected to (relatively) lower degree vertices) is still not completely resolved as is evident from the middle left diagram of the same ﬁgure. f. .6. d. As you may have noticed in this speciﬁc problem we have to apply the said algorithm twice to obtain the desired results. h. f − 1. Problem 4. k. j.4. k and assume that a = 5. j. We again apply the same algorithm to resolve the rest of the problem as shown in the middle right diagram. e − 1. d − 1. i. c − 1. The new graph with the same degree sequence and the problem completely resolved is shown in the bottom diagram. g. h.6: A graph with a given degree sequence shown in the top left diagram is converted into another graph with the same degree sequence shown in the bottom diagram.

We check if the degree sequence is graphical. j − 1.4. f. c. if it is graphical then we ﬁnd and draw the actual graph G corresponding to this sequence.4. If the degree sequence is graphical then you are supposed to draw a graph G corresponding to this sequence such that the . d. i − 1. Please verify if this is always right or wrong in general. Discuss brieﬂy. h − 1.4. i.4. Do we know how to draw the graph for SH provided we have a graph for SG ? Discuss brieﬂy. Figure 4. d.4. We are given a degree sequence SG . the highest degree vertex v (with a degree equal to u) will always be connected to the ﬁrst u vertices in the degree sequence SG ? Problem 4.6. j. If the answer to the above problem is no then how can we do some thing to make sure that in the ﬁnal graph. We are given a degree sequence SG . k − 1. g. We check if the degree sequence is graphical. e. h. e. c. Let a degree sequence consisting of 11 numbers be SG = a.7: Two graphs are shown in this ﬁgure. k and assume that a = 5. g − 1. b. The ﬁgure down below may be helpful for your imagination. f. Problem 4. Let another sequence be SH = b. Problem 4. Both these graphs have the same degree sequence which is 54444411111.6.7. In this graph G the highest degree vertex v (with a degree equal to u) will always be connected to the ﬁrst u vertices in the degree sequence SG .98 Basics of Graph Theory Problem 4. The graph shown in the left diagram is a connected graph while the graph shown in the right diagram is a disconnected graph.5.

4. What are necessary & suﬃcient conditions for a degree sequence SG to be graphical such that in the resulting graph G the highest degree vertex v (with a degree equal to u) in the graph should be connected to the last u vertices in the degree sequence SG .9. Problem 4. Problem 4. Is there a possibility that a degree sequence SG is graphical but it is impossible to draw a graph corresponding to this sequence such that the highest degree vertex v (with a degree equal to u) in the graph should be connected to the last u vertices in the degree sequence SG . Discuss brieﬂy if this is always possible and how will you do it? Problem 4. . Is it always possible to convert it into another graph with the same degree sequence but now the highest degree vertex v (with a degree equal to u) is connected to the last u vertices in the degree sequence SG .The Degree Sequence 99 highest degree vertex v (with a degree equal to u) should be connected to the last u vertices in the degree sequence SG .8.4.4.10. Either prove or ﬁnd a counter example. We are given a graph G (and its degree sequence SG ) in which the highest degree vertex v (with a degree equal to u) is connected to the ﬁrst u vertices in the degree sequence SG .

7. The path is shortest in terms of number of edges in between the two terminal vertices. The graph shown in the left diagram is a connected graph while the graph shown in the right diagram is a disconnected graph. . & Paths We show a walk from vertex a to vertex d in a graph shown in Fig.6. 4.100 Basics of Graph Theory Figure 4. 4.7 Walks. A walk or a trail can always be converted into a path as shown in this ﬁgure. A shortest path between the same two vertices is also shown. We also show a path between the same two vertices in this graph.8: Two graphs are shown in this ﬁgure. Remember in a trail it is not allowed to traverse an edge more than once – but it is allowed to traverse a vertex several times. Please note that in a walk it is possible to traverse an edge (and therefore a vertex) several times. We also show a trail between the same two vertices in the same graph. You may have realized that in a path it is not allowed to traverse an edge or a vertex more than once.1. Trails. Both these graphs have the same degree sequence which is 54444411111.

The shortest path from vertex a to d is shown in the bottom right diagram. the path consists of six edges. the trail consists of six edges.1: A walk from vertex a to vertex d consisting of eight edges as shown in the top left diagram. no edge is repeated. . A path is shown from vertex a to vertex d in the top right diagram.Walks. A trail from vertex a to d is shown in the top middle diagram.7. In this trail only a vertex is repeated. Trails. The trail in the top middle diagram is converted into a path from vertex a to d as shown in the bottom middle diagram. & Paths 101 Figure 4. The walk in the top left corner (from vertex a to d) is converted into a four edge path as shown in the bottom left diagram. vertices as well as edges are repeated in the walk.

& (e) Star graphs.. It can be represented by an adjacency matrix. it consists of no self loops or parallel edges. i. (d) Line graphs. 4. & (3) Cyclic graphs. . (2) Bipartite graphs. Figure 4. (c) Cycle graphs. This graph can be represented by an adjacency matrix also shown in the same Fig. graphs containing cycles.102 Basics of Graph Theory 4.1. We categorize graphs into three major categories: (1) Acyclic graphs (or trees).8.8 Multi-graphs and Pseudo-graphs We show a simple graph.8.1: A simple graph containing no self loops and no parallel edges. Under special graphs we consider: (a) Completely connected graphs.9 Broad Categories of Graphs & some Special Graphs We shall talk about very broad categories of graphs and then some special graphs.e. We also show graphs with self loops and parallel edges. How about graphs which are not simple? 4. (b) Regular graphs.

shown in the left diagrams.9. A bipartite graph which is not acyclic is shown in the middle diagrams.1: A cyclic graph which is neither bipartite nor acyclic is shown in the right diagrams. is also a bipartite graph. an acyclic graph (or a tree). .Broad Categories of Graphs & some Special Graphs 103 Figure 4.

4. A graph is a line graph (or a chain graph) if the degree of every vertex is 2 except for two vertices where the degree is 1.9. 4. 4. .1 Tree Graphs A connected graph G is a tree provided it does not contain any cycles.9. 4.1 is not bipartite as it contains an odd cycle. 4. If G does not contain a cycle then G is not only bipartite it is also a tree.9.9.104 Basics of Graph Theory 4.9. A graph G having p vertices is completely connected if the degree of every vertex is p − 1 (please note that the degree of a vertex in a simple graph can not be more than p − 1).9. 4. In other words every edge in a bipartite graph connects a vertex from set A to a vertex in Set B.9.1. A tree graph is shown in Fig. 4.9. A bipartite graph is shown in the left diagram of Fig. It may contain even cycles or no cycles at all. it is bipartite because it does not contain any cycle at all. Another bipartite graph is shown in the middle diagram of Fig.1 and 4.3 Special Graphs A graph G is k-regular if the degree of every vertex is exactly equal to k. A line graph consisting of two vertices is a special case where the degree of both the vertices is 1. The graph shown in the right diagram of Fig. it is bipartite because it does not contain any odd cycles.9. Please note that partite A is an independent set while partite B is also an independent set but neither of the two is a maximum independent set. We show a number of non isomorphic trees with p larger than 1 and smaller than 6 in Fig. The vertex set V (G) of a bipartite graph G can be partitioned into two disjoint sets A and B whereas both A as well as B are independent sets. A graph is a cycle graph if the degree of every vertex is exactly two.2. The A partite as well as the B partite are shown in the middle diagram where the bipartite graph is drawn with a diﬀerent orientation to highlight the two parts. The maximum independent set in this graph is shown in the right diagram of this ﬁgure. We show another bipartite graph in Fig. 4.3.1. The minimum vertex cover of this graph is also shown in this diagram.2 Bipartite Graphs A graph G is bipartite provided it does not contain odd cycles.3.9.

9. This graph is in fact a bipartite graph as shown in the middle diagram consisting of an A partite and a B partite.2: We show a number of non isomorphic trees with p larger than 1 and smaller than 6.Broad Categories of Graphs & some Special Graphs 105 Figure 4. Figure 4.3: A graph G is shown in the left diagram. . The minimum (sized) vertex cover and the maximum (sized) independent set in graph G are shown in the right diagram.9.

A star graph is not regular unless it has a size equal to 2 when it becomes a line graph which is 1-regular. It is obvious from Fig.9.4 that a completely connected graph is (p − 1)regular while a k-regular graph may not be completely connected. being acyclic.4: The degree of every vertex in a completely connected graph is p − 1. . A start graph consisting of two vertices is a special case.9. is always bipartite. A line graph is not regular unless it consists of a special case of a connected graph of two vertices. A cycle graph is also a 2-regular graph as shown in this ﬁgure. 4. A graph G is referred to as a forest if it contains a collection or set of trees. A line graph. The degree of every node is the same for every vertex in a regular graph. Figure 4. The degree of every vertex is exactly 2 in a cycle graph.106 Basics of Graph Theory A graph G is a star graph if the degree of one vertex is p − 1 while the degree of every other vertex is 1. The degree of every vertex is 1 except for one vertex where the degree is p − 1 in a star graph. The degree of every vertex is 2 except for two vertices where the degree is 1 in a line graph.

It is interesting to compare these graphs with the ones shown in Fig.9. A 4-regular graph is shown in the right diagrams.7. We show a number of k-regular graphs in Fig. is always bipartite where one partite consists of size 1 while the other of size p − 1.4. 4.9. We show a number of k-regular graphs in Fig. any edge in these graphs connects a vertex in one partite to any vertex in one of the other partites. A number of cycle graphs are shown in Fig.5. They are rather 4-partite graphs meaning that the vertex sets of each of these graphs can be partitioned into four disjoint sets of vertices (or partites). Please note that all these graphs are bipartite as shown in the bottom diagrams of this ﬁgure. 4. 4.9. A 3-regular graph is shown in the middle diagrams. A curious reader might .5.9.Broad Categories of Graphs & some Special Graphs 107 Also a star graph. All these regular graphs are bipartite as shown in the bottom diagrams. being acyclic.9. Figure 4.5: A 2-regular graph shown in the right diagrams. 4. The four partites are indicated in diﬀerent colors in the bottom diagrams of this ﬁgure. These new graphs are regular and not bipartite.

6: A 6-regular graph shown in the right diagrams.9.108 Basics of Graph Theory appreciate the fact that a cycle graph is bipartite if it consists of even number of vertices. Figure 4. while it is not bipartite if the cycle graph consists of odd number of vertices. A 4-regular graph is shown in the middle diagrams. . Another 4-regular graph is shown in the right diagrams. All these graphs are 3-partite as shown in the bottom diagrams. What may not be obvious is that an odd cycle graph will always be a 3-partite graph as shown in this ﬁgure.

9 above shows the same graph A as shown in Fig 4. Problem 4.Broad Categories of Graphs & some Special Graphs 109 Figure 4. Graph E is obtained by deleting a vertex from graph A. By deleting a diﬀerent set of edges from graph A. Similarly graph C is derived from graph A by deleting another set of edges from B. The ﬁgure below shows a completely connected graph A in the left diagram.5. It is a 7-regular graph consisting of eight vertices. graph B is a 6-regular graph.7: Cycle graphs of diﬀerent sizes are shown. The middle graph shows graph B which is derived from graph A after deleting or subtracting a number of edges from graph A.5.9. we may obtain a graph which is not isomorphic to graph B.2.9. Draw all possible graphs consisting of 8 vertices which are not isomorphic to B but which are 6-regular. Similarly draw all possible non isomorphic graphs of 8 vertices which are 5regular.1.8.5. Problem Set 4. Similarly . The Figure 4. Problem 4.9. Please note that graph C is again a 5-regular graph consisting of 8 vertices.

110 Basics of Graph Theory Figure 4. .9.9.8: Graphs B and C are derived from graph A by deleting certain edges. Figure 4.9: Graphs E and F are derived from graph A by deleting certain vertices.

How many such non-isomorphic graphs we shall be able to obtain? The ﬁgure below shows all non-isomorphic graphs consisting of 8 vertices which are 4regular.9. (a) Is it possible to get a graph which is isomorphic to graph F by deleting any two vertices of graph A? Discuss brieﬂy. 4. we can obtain a 4-regular graph of eight vertices.8.4.Broad Categories of Graphs & some Special Graphs 111 graph F is obtained by deleting another vertex of graph E. Figure 4. By carefully selecting and deleting certain edges of graph C shown in Fig. by deleting certain edges transform it into a 5-regular graph. Please note that both E and F are completely connected and regular graphs. (b) Now concentrate on graph E. Problem 4.5. (c) By deleting another set of edges transform it into a 4-regular graph.9.3. it is a 6-regular graph. (a) Find which of these graphs is a .10: Shows all non-isomorphic graphs consisting of 8 vertices which are 4-regular. Look at the graphs consisting of 8 vertices and are 4regular as shown in the ﬁgure above.5. (d) Draw all non isomorphic graphs which are 4-regular consisting of 7 vertices. Try to match the graphs that you have obtained with the ones shown in the ﬁgure below. Problem 4.

5. (d) Draw all non-isomorphic graphs consisting of eight vertices which are 3-regular.9.5. Figure 4. This category of graphs can easily be represented by an adjacency matrix or an adjacency list data structure. Problem 4. The graph G shown in the ﬁgure below is derived from graph A by subtracting certain edges from graph A. a tree . Un-directed graphs can be further classiﬁed into connected graphs and disconnected graphs. 4. We have mainly conﬁned ourselves to simple graphs in which there are no parallel edges and no self loops. Properties. Connected graphs can also belong to certain categories like a line graph. and are regular consisting of eight vertices.10 Integration of Concepts. Draw all non-isomorphic graphs consisting of 8 vertices which are 5-regular. Out of these graphs indicate which ones are bipartite graphs. and Action Items We have talked about various concepts in graph theory in this chapter. a cycle graph.11: Graphs G is derived from graph A by deleting certain edges. (c) Draw all nonisomorphic graphs consisting of 12 vertices and are 6-regular. we shall study directed graphs in detail in Chapter 8.112 Basics of Graph Theory bipartite graph? (b) Draw all non-isomorphic bipartite graphs which are connected. We have further limited our study to un-directed graphs in this chapter. Note that graph G is 5-regular.

Integration of Concepts. a trail. It will be interesting if we integrate a couple of concepts with a number of properties. and Action Items 113 graph. a cyclic graph and a completely connected graph. Properties. We have also talked about a walk. . or a path between two vertices in a graph. like a Hamiltonian path or an Eulerian path in a graph. We have also talked about certain properties of graphs.

It can be seen that the left graph is the complement of the right graph as well as isomorphic to the right graph. Eccentricity of a vertex 7. Both of them are also Hamiltonian? Necessary Conditions . Radius & Diameter of a graph This section is organized as follows.11 Self Complementing Graphs A self complementing (SC) graph is a graph G whose complement c(G) is isomorphic to itself. We shall conclude with a number of interesting problems.114 Basics of Graph Theory 4. The following concepts are used in a meaningful manner to advance our discussion on self complementing graphs.11. Some of the necessary conditions of SC graphs will be discussed next. Complement c(G) of a graph G 2. We shall ﬁrst show some SC graphs in order to give you a feel of such graphs. We shall show how one SC graph can be transformed into another SC graph with less or more vertices? Some of the interesting properties of these graphs will also be elaborated. Deleting and inserting a vertex in a given graph 6.1 Regular Self Complementing graphs We show a number of non trivial (a graph of one vertex is a trivial example of such graphs) self complementing graphs in the following ﬁgure. Degree sequence of a graph 5. We shall discuss these graphs in some detail as they provide us a platform to connect a number of key concepts in graph theory & algorithms. 1. These graphs are also regular as the degree of each vertex is 2. 4. Graph isomorphism between two graphs G & H 3. Regular & non regular graphs 4. The problem of how to construct a SC graph of ﬁxed vertices will also be discussed. That means that both these graphs are self complementing.

p will become 9. The complement c(G) of graph G is obtained by deleting all edges of graph G from the corresponding completely connected graph. Let us try to explore graphs with 9 vertices with the degree of each vertex equal to 4.1: A graph and its complement which is isomorphic to the original graph. If c(G) is isomorphic to G then it should have the same number of edges as G . When k = 2. Then the number of edges in the graph will be exactly 2 p(p−1) . We have already drawn such a graph with p = 5 when k = 1. Will all such graphs be isomorphic to each other? Will such graphs (or at . Does that mean that p or p − 1 in an SC graph should be divisible by 4 4? Are these necessary or suﬃcient conditions for such a regular graph to be self complementing? It will be rewarding if you draw a couple of regular graphs with the property that the degree of each vertex is p−1 .11.Self Complementing Graphs 115 Figure 4.that means the degree of every vertex in a regular self complementing graph should be p−1 . Can you draw such a graph if p is even? 4 Can you draw such a graph if p is any odd number? It will be essential to answer the above questions before moving forward? If you have tried to draw such graphs then you will soon realize that a nregular graph (where n = p−1 ) is possible if and only if p = 4k + 1 where 4 k is an integer equal to or larger than one. Does this mean that all regular graphs are self complementing? But a cycle graph of three or six vertices is not self complementing? There must be a class of regular graphs which will be self complementing? The following ﬁgure shows the same graph along with the corresponding completely connected graph of ﬁve vertices.

2: A self complementing graph of 5 vertices (left diagram) and a completely connected graph of 5 vertices. least some of them) self complementing? If you take the complement of any such graph it will certainly have the same degree sequence and same number of edges? Again it will be rewarding if you draw some of these graphs before arriving at a conclusion? We show three such graphs in the ﬁgure below. What does this example tell us? .116 Basics of Graph Theory Figure 4. Are any two of them isomorphic to each other? Is one complement of the other? Are they self complementing? Please try to answer these questions before moving forward.11. It will be exciting if you draw the complement of the left graph? You will soon realize that the top right graph is the complement of the top left graph while the bottom graph is isomorphic to the top right graph.

11. Top right diagram shows the complement c(G) of graph G. . The bottom graph is equal to c(G).Self Complementing Graphs 117 1 9 2 9 1 2 8 3 8 3 7 6 5 4 7 4 6 5 1 6 5 2 9 7 3 8 4 Figure 4.3: Top left diagram shows a graph G.

1 13 12 2 3 12 10 1 3 5 11 4 8 7 10 6 8 7 5 6 11 2 13 9 9 4 Figure 4. If we take the complement of one such graph it will transform either into one of such graphs or into itself.5: A regular self complementing graph of 13 vertices. A very few of them indeed transform into themselves when you take the complement.4: A regular self complementing graph of 9 vertices.11. Most of them transform into one another if you take the complement of one such graph as shown above. How about imagining non isomorphic regular graphs having p = 13 and degree of each vertex equal to 6.11. 1 7 4 9 1 2 5 6 8 3 2 8 3 9 7 6 5 4 Figure 4. . One such self complementing graph is shown below. One such graph is shown in the ﬁgure below.118 Basics of Graph Theory If you actually draw all non isomorphic graphs with p = 9 and degree of each vertex equal to 4 you will realize that there are 16 such graphs possible. There are (367860) six-regular non isomorphic graphs with 13 vertices.

The degree sequence of a completely connected graph of four vertices is 3333.11. Now we have to verify if these degree sequences are really graphical. Necessary Conditions Is it possible to have a non regular graph of ﬁve vertices which is self complementary? Let us try out various degree sequences with the above necessary condition? There are only three choices possible under the conditions laid out before: 22222. & 32221. The degree sequence of the complement of this line graph can be obtained by subtracting 2211 from 3333.6: A self complementary line graph of 4 vertices. The ﬁrst degree sequence corresponds to a cycle graph which was regular and we have already seen it. 1 2 3 4 1 2 3 4 Figure 4. This provides us a necessary condition for a non regular graph to be self complementary? The degree sequence of c(G) should be such that if we add it (after sorting it in increasing order) with the degree sequence of G (having p vertices) then we should get the degree sequence of a completely connected graph of p vertices. it comes out to be the same as the four vertex line graph is self complementary. 33211. and if they are then do they really belong to graphs which are self complementary? Let us start with the sequence 32221. The other two belongs to non regular graphs and are of interest to us.11.Self Complementing Graphs 119 4. Can you draw its graph and check out if the graph is self complementary? The sequence is graphical but is itself complementing? .2 Non Regular Self Complementing graphs One important question that should agitate you is every self complementing graph a regular graph? Is it possible to have a non regular graph to be self complementing? How about a line graph of four vertices? Its degree sequence is 2211.

we have seen a non regular SC graph of 4 vertices in the last diagram. we can safely say that a SC graph of 4k vertices will always be non regular? Why? .7: A 5 vertex non-regular self complementing graph. we have also seen a non regular SC graph of 5 vertices. Please note that the condition (the degree sequence of c(G) should be such that if we add it (after sorting it in increasing order) with the degree sequence of G (having p vertices) then we should get the degree sequence of a completely connected graph of p vertices) is a necessary condition.120 Basics of Graph Theory Now let us check the other sequence which is 33221. In fact we have earlier claimed that a regular SC graph can have only 4k + 1 vertices. it is not suﬃcient. We have already seen a regular SC graph of 4 + 1 = 5 vertices. Thus this condition along with others (for example the number of odd degrees in a degree sequence should be even for a degree sequence to graphical) may narrow down our search for SC graphs but we always have to verify if a given graph G is a SC graph? These simple conditions tells us that an SC graph (which may or may not be regular) can only have p equal to 4k or 4k + 1 vertices where k can be equal to or larger than 1. this indeed comes out to be graphical as well as self complementary as shown below: 1 2 3 4 5 1 2 3 4 5 Figure 4.11.

Self Complementing Graphs 121 4. It will be interesting if you try to check if a graph corresponding to these degree sequences is indeed self complementary? This will certainly be a tiring process . An edge between G and c(G) means that every vertex G is connected to every vertex of c(G). 55552222. If we connect graph G and its complement in the following conﬁguration then we claim that the new graph will be a SC graph. and G may contain more than one vertex. Given any graph G we can always ﬁnd its complement c(G).3 Constructing Self Complementary Graphs Let us consider graphs where p = 8 and assume that its degree sequence satisﬁes the stated necessary conditions for a SC graph. If G contains a single vertex then this graph is certainly SC graph.11.we shall now discuss ways of constructing large SC graphs bypassing this tiring process? The new method will help us further in making meaningful connection between relevant concepts. Please note that a line between G and c(G) means that each vertex of G is connected to every vertex of c(G). 44443333. The resulting super graph is a self complementing graph. Some of the possible degree sequences are listed here: 66661111. 55443322. But if G contains more than 1 vertex then why this composite graph is self complementary? Figure 4.8: Here vertex G is a graph while c(G) is complement of graph G. 66443311.11. Let us actually construct such graph and see how it looks? Assume that G .

then c(G) will simply consist of two isolated vertices.11.here also G is any graph and is connected with its neighboring graph in the same fashion? Here x is just one vertex and we claim as before that the resulting graph will be self complementary. How the above conﬁguration would look like when it is actually drawn? If you look at the diagram below you will realize that the graph is indeed self complementary.and that will be two isolated vertices 3 & 4.then c(G) will be a line graph of two vertices.9: Here graph G is a line graph of two vertices 1 & 2. The number of vertices in the SC graph will still be 4p where G has p vertices. 7 5 8 6 1 6 5 2 1 3 2 4 7 3 7 4 Figure 4. The degree sequence of this graph is 44443333 it is one of the sequences that we have predicted earlier in our discussion? We can also start with G equal to two isolated vertices . Then c(G) will be its complement .consisting of vertex 7 and vertex 8. Using these building blocks you can also construct another SC graph? If you have the patience of constructing such a graph you will realize that its degree sequence will be 55552222. .122 Basics of Graph Theory is a line graph of two vertices . Another copy of G will consist of a line graph of two vertices . Another way to construct a SC graph is shown below . Why? The number of vertices in the resulting SC graph will be 4p + 1 where p is the number of vertices in G.

Please ﬁnd the degree sequence of each of the following graph? Can you ﬁgure out how these SC graphs are constructed? .10: Here vertex G is a graph while vertex c(G) is the complement of graph G. Vertex x may be a single vertex graph. 1. There a number of interesting possibilities in the above conﬁguration.11. How about if instead of single x vertex we have a graph H connected to its neighbors? In order to make the whole conﬁguration SC should it be any graph H or a special graph H? What special property it should possess? As you can discover yourself H should be a self complementary graph for the above conﬁguration to be self complementary? 2. How about if we insert a self complementary graph H in the place of x as well as G in the above conﬁguration? 4.Self Complementing Graphs 123 G c(G) G ) c(G c(G) G x c(G) x G Figure 4. An edge between G and c(G) means that every vertex G is connected to every vertex of c(G). The resulting super graph is a self complementing graph. What would happen if the self complementary graph H in the above step is regular? How about if it is non regular? 5. Is it possible that we insert graph G in the place of x in the above conﬁguration? Please note that G is any graph? 3. Will the above conﬁguration result into a regular or a non regular SC graph? The following diagrams will help you answer these interesting questions.

11. It will contain 4k + 1 vertices. 4.11: A line graph of 4 vertices is used as a building block in the left diagram.124 Basics of Graph Theory Figure 4. By deleting any vertex from this graph is it possible to convert it into another SC graph having 4k vertices? Let us start with a simpler problem of a regular SC graph having 9 vertices as shown below.4 Transforming a SC graph with 4k + 1 vertices into another SC graph with 4k vertices We know that a SC graph should have either 4k or 4k + 1 vertices? This immediately leads us to conjecture that if we have a SC graph of 4k + 1 vertices then by deleting one vertex we can convert it into another SC graph having 4k vertices? Is it straight forward or we need to devise an intelligent algorithm to do so? Similarly if we are given a SC graph having 4k vertices then is it possible to construct a SC graph having 4k + 1 vertices by inserting a new vertex and connecting it to some of the vertices of the original graph? Again do we need some thinking to do so or is it a trivial problem? In order to answer these questions let us start with a regular graph which is SC. A cycle graph of 5 vertices is used as a building block in the right diagram.11. Can we delete any vertex and the resulting graph would stay a SC graph of 8 vertices? Please note that initially the degree sequence is .

It is no longer a trivial problem and we should devise an algorithm to solve the problem? . It becomes 44443333 after deleting that vertex. 125 What about if we delete any vertex from the 25 vertex graph shown earlier.Self Complementing Graphs 444444444. Will the new graph be also self complementary? Why? How about if we have a non regular SC graph of 4k + 1 vertices? Can we delete any vertex to make it another SC graph with 4k vertices? How about this graph? It has a degree sequence 332211.

11.126 Basics of Graph Theory Figure 4. We remove vertex 2 from the same SC graph in the bottom diagram.12: We remove vertex 1 in the top diagram from a SC graph in the top diagram. .

Self Complementing Graphs 127 Figure 4.13: We remove a vertex from the 25 vertex SC graph. Is the resulting graph a SC graph? .11.

Figure 4. This graph may also provide insights needed to design an intelligent algorithm to solve the above problem.15: A SC graph having 9 vertices. Here we show another interesting graph which is not regular but is self complementing.14: A SC graph having 5 vertices which is not regular.11. Its degree sequence is 774444411.128 Basics of Graph Theory Figure 4.11.after deleting one vertex the new degree sequence should possess certain properties if it represents a self complementing graph? For example it can be 66443311 or 77443300. Can we remove any vertex and still it remains a SC graph? Given a degree sequence 774444411 of a self complementing graph . etc. The problem is to decide which vertex should be removed? .

The resulting graph is SC and is also regular .11. Again we shall show you a number of graphs and then provoke you to design an eﬃcient algorithm to solve the problem. Figure 4.11.16: We insert a vertex x in a self complementing graph. The graph is redrawn in the bottom diagram to emphasize that it is indeed a beautiful regular graph? . Now start with the same original graph (with a degree sequence equal to 44443333) while the new graph should have a degree sequence equal to 444444444.although it has not been drawn in a suitable manner in the top diagram.Self Complementing Graphs 129 Should we always remove the vertex with degree equal to 4? Why? Should that vertex be connected with lower degrees or higher degrees? 4.5 Transforming a SC graph with 4k vertices into another SC graph with 4k + 1 vertices Now let us look into the problem of inserting a vertex in a SC graph consisting of 4k vertices such that the new graph having 4k + 1 vertices is also selfcomplementing. Please note that we can also put an extra constraint that the resulting SC graph should be regular. We show the same graph with a degree sequence 44443333 being converted into a new SC graph with degree sequence 555543333.

17: After inserting vertex x we have a regular SC graph.11. .130 Basics of Graph Theory Figure 4.

this is c(G) and now check if G and c(G) are isomorphic.11.Self Complementing Graphs 131 So the problem is where to connect the inserted vertex and what should be its degree? Perhaps another example may provide you a solution? Please check the degree sequence of the graph before after inserting a new vertex? Figure 4.11.18: Inserting a vertex x in a SC graph? 4.then can we solve the graph isomorphism problem? How? .6 The Self Complementary problem and Graph Isomorphism If we know how to ﬁnd if G and H are isomorphic then we can always check if G is a self complementary graph? How? Take the complement of G . But suppose we know how to check if G is a self complementary graph .

We claim that if the top (or the bottom) graph is self complementary then graph G is isomorphic to graph H? Why? We can also use the following conﬁguration to check if G and H are isomorphic also by substituting H in an appropriate place in this diagram? Figure 4.20: We need to check if graph G is isomorphic to graph H? 4. .19: We need to check if graph G is isomorphic to graph H? Look at the ﬁgure above.132 Basics of Graph Theory Figure 4.11. We need to check if a given graph G is isomorphic to another given graph H.11.not less than 2 and not more than 3? Instead of proving the above statement let us ﬁrst do a simple one.7 A SC graph has diameter 2 or 3 .11. Can we prove that for any graph G the following conﬁguration will give us a SC graph with a diameter not more than 3.

11.11.21: What is the diameter of this super graph? Again can we prove that for any graph G the following conﬁguration will give a SC graph with diameter not more than 2? Figure 4.22: What is the diameter of this super graph? We shall now attack the more general problem? But before that let us refresh our knowledge regarding some old concepts: the eccentricity of a vertex.Self Complementing Graphs 133 Figure 4. The diameter in the top graph will be 7 while the radius will be 4 in the top diagram. Let us see how the eccentricities of various vertices look like in a line graph of eight and ﬁve vertices as shown below. The diameter and radius for the bottom line graph will be respectively 4 and 2. Similarly we show another ﬁve vertex graph where the . and the radius and diameter of a graph.

Its diameter as well radius will be inﬁnite.24: A completely connected graph G and its complement. It is a completely connected graph . Thus its diameter is 2 while its radius is 1. Figure 4. Please note that the diameter in the line graph was 4 while it has reduced to 2 in the complement of the line graph.11. The complement of this graph is also shown in the bottom diagram.the diameter as well as the radius is 1 in this graph. The diameter in the complement of graph G is inﬁnite while its radius is also inﬁnite. You can well imagine that if the diameter in a graph G is more than 3 then . Here the eccentricity of each vertex in G is 2 except for vertex 1.134 Basics of Graph Theory Figure 4. The eccentricity of each vertex is indicated in the line graph as well as in its complement. The ﬁve vertex line graph and its complement are shown in the bottom diagram. eccentricity of each vertex is 1. Another ﬁve vertex graph G and its complement is shown below.23: The eccentricities of diﬀerent vertices in a line graph. The diameter as well as the radius in the complement graph is 2.11.

26: A line graph and its complement.11.25: A star graph and its complement.Self Complementing Graphs 135 Figure 4. . Figure 4.11.

8 Bipartite self complementary graphs Deﬁnition: Assume that the complement of a bipartite graph BP is isomorphic to bipartite graph BP . Alternatively in order to ﬁnd complement of graph BP . Please note that this not a Category A SC bipartite graph? Why? .11. Let us call these category A SC bipartite graphs. That means a graph G with a diameter more than 3 cannot be self complementary.thus all the A (and B) partite vertices in BP will become completely connected in the complement of BP . Now assume that the bipartite complement of bipartite graph B is isomorphic to bipartite graph B.the resulting graph will be a bipartite complement of bipartite graph BP . Similarly if the radius or the diameter in a graph G is 1 then it cannot be isomorphic to its complement? Why? Does that mean that a SC graph can have diameter 2 or 3 . Please note that bipartite complement of a bipartite graph is diﬀerent from this complement. We then remove existing edges in BP from this completely connected bipartite graph . Let us call these category B SC bipartite graphs. we ﬁrst form a completely connected general graph consisting of all BP vertices . Here we ﬁrst form a completely connected bipartite graph consisting of as many vertices in the A as well as B partites of bipartite graph BP .not more than 3 and not less than 2? How about the radius of a SC graph? Should it be always 2 . The following graph is a Category A SC graph.not more not less? 4.we then remove those edges which are already present in BP .136 Basics of Graph Theory the diameter in its complement is reduced to 2. Please note that it is not a Category B SC graph? Why? Can you draw another bipartite graph which is a Category A SC graph? Can you prove that such graphs are not possible if any partite contains more than two vertices? We show a category B SC graph BP in the ﬁgure below.this will give us the complement of graph BP . We assume that while taking the complement of graph BP we simply consider it a general graph .

28: A bipartite graph and its bipartite complement.11.Self Complementing Graphs 137 Figure 4. .11. The complement of graph BP is shown in the bottom diagram. Figure 4.27: A bipartite graph BP shown in the top left diagram. The corresponding completely connected graph is shown in the top right diagram.

29: Top left diagram shows a bipartite graph BP. While that of the completely connected bipartite graph is 44444444. Top middle diagram shows the corresponding completely connected bipartite graph. The following bipartite graph is a non regular self complementing graph with a degree sequence 33222211. The bottom diagrams once again shows the two bipartite graphs shown in the standard form. The degree sequence of the above graph is 22222222. The degree sequence of a corresponding completely connected bipartite graph is also 44444444.138 Basics of Graph Theory The same graph BP is drawn below in a diﬀerent shape. The corresponding completely connected bipartite graph and the complement of bipartite graph BP is also shown here. As you can see this is a regular SC bipartite graph. Figure 4. Here we show another Category B SC graph with red vertices in one partite . Top right diagram shows the bipartite complement of the bipartite graph.11.

and green vertices in another partite.we shall simply refer them as SC bipartite graphs. How many edges are there in a complete SC bipartite graph with m vertices in one partite and n vertices in another partite? That is equal to mn. That is an important necessary condition for a bipartite graph to be self complementary.11. Figure 4.11. Thus either m or n should be even. . From now on wards we shall consider only category B self complementary bipartite graphs . The number of edges in a SC bipartite graph will be mn/2.Self Complementing Graphs 139 Figure 4.31: A regular SC graph having 12 vertices.30: A SC bipartite graph which is not regular.

Similarly there is a graph G(B) consisting of vertices in the set B. 4.graph G(A). We put vertices in G − x which are adjacent to x in set A while the rest of the vertices in G − x goes in the set B. In addition to that there will be a graph inside G consisting of vertices belonging to the set A .9 Decomposition of a SC graph G Here we shall talk about the decomposition of a SC graph G into a number of edge-disjoint graphs . There will be a bipartite graph having edges going between the set A and the set B.11.11. Please note that the following graph is a SC graph with or without the vertex x. Thus even if we remove vertex x the resulting graph G − x will still be a SC graph as shown below .although vertex x provides a useful function of pinpointing certain vertices needed for the decomposition of the graph? Vertices in G − x which are adjacent to x belong to one partite while the rest of the vertices in G − x belong to the other partite. The original graph can thus be decomposed into edge-disjoint graphs .32: A SC graph where the size of two partites is diﬀerent. bipartite graph BP .we call this the graph G(A).140 Basics of Graph Theory Figure 4.one of them is a SC bipartite graph? Initially we shall talk informally and provide some insight and then we shall discuss it more formally. graph G(B) and the vertex x connected to all .

The bipartite graph BP (A.11. 1. 141 Figure 4. 2. B) will also be a SC bipartite graph.Self Complementing Graphs vertices in graph A. It can be observed that the following properties should hold for the original graph G to be SC. The two partites are balanced that is the size of A and B is the same.there is some relationship between these two graphs? . The graph G(A) and graph G(B) . The graph (x. A) 3.33: A self complementing graph is decomposed into a number of edge-disjoint graphs.

34: A SC graph decomposed into a number of edge-disjoint graphs. Isomorphism. and 4 back to 1. The vertex 9 is mapped onto itself.11. This is a so called circular permutation in which we map 1 onto 2. Figure 4. In order to show that this new graph is isomorphic to the original graph G we have to ﬁnd an isomorphic function .142 Basics of Graph Theory Let us consider another example to conﬁrm/enhance our observations before formally discussing the decomposition of a SC graph.10 Permutation.11. 2 onto 3. 3 onto 4. 4. automorphism & Self Complementing Graphs Any permutation of vertices of any graph G may create a diﬀerent graph H. This graph H will always be isomorphic to graph G but may not be equal to graph G (as the adjacency matrix may be diﬀerent). This permutation permutes the vertices of G and produces a new graph which is not equal but isomorphic to the original graph G. 4.11.35. For example consider the permutation p1 equal to (1234)(5678)(9) as shown in Fig.

Self Complementing Graphs 143 (or a permutation) which maps the vertices of the new graph back onto the vertices of graph G such that adjacency as well as non adjacency is preserved in the two graphs.35: Graph G (top left diagram) and another graph (top right diagram) where the vertices of G are permuted according to the given permutation p1 . Please note that graph G is equal to the bottom graph If a permutation p of a graph G creates a graph H which is equal to graph G (that means the adjacency matrix will exactly be the same) then that permutation is known as an automorphism of graph G. We may be more interested in the non trivial permutations of graph G? It may be possible for a certain category of graphs that the only automorphism is the trivial identity permutation? Please note that if p is an automorphism of graph G then the permutation p2 is always an automorphism of graph G If a permutation p of vertices of graph G creates a graph H which is the complement of graph G then the permutation p is known as the complementing . Figure 4. The identity permutation is always an automorphism . In this case this permutation p2 will be (4321)(8765)(9).it is known as a trivial permutation.11. The two graphs are not equal but they are isomorphic thus the permutation p1 is not an automorphism of graph G.

11.36: Graph G (left diagram) and another graph (right diagram) where the vertices of G are permuted according to the given permutation p. permutation of graph G and graph G is a SC graph. Any complementing permutation of a graph G is certainly not an automorphism of graph G but the permutation p2 is always an automorphism of graph G if p is a complementing permutation.144 Basics of Graph Theory Figure 4. Thus every self complementing graph G has a complementing permutation p associated with that graph G. Whenever we claim that G is self complementing then we have to ﬁnd out the self complementing permutation? . The two graphs are not only isomorphic but also equal thus the permutation p is an automorphism of graph G but it is not a complementing permutation of graph G.

11. This new graph is equal to graph G .that means the permutation p is a complementing permutation of graph G but it is not an automorphism of graph G. This new graph is also the complement of graph G . .37: Graph G (top left diagram) and another graph (top right diagram) where the vertices of G are permuted according to the permutation p.Self Complementing Graphs 145 Figure 4. The bottom diagram shows another graph where the vertices of p(G) are permuted once again according to the same permutation p.thus p2 (G) is an automorphism of graph G.

146 Basics of Graph Theory Let us now consider certain self complementary bipartite graphs and the related complementary permutations .11.38: Bipartite graph BP and a complementing permutation. 4.in the lower permutation it is mapped onto the same partite? . According to this permutation vertices of one partite are permuted onto vertices of the other partite in the complement of BP . 4.39 is also a self complementing permutation.11. But in the top permutation one of the partites is mapped onto the other partite . The permutation in Fig.11. The permutation in Fig. Figure 4.two of them are shown in the ﬁgures below.38 is a self complementing permutation.

39: Bipartite graph BP and its complement.11. 38. In the decomposition or the synthesis eﬀort to be explained in the coming examples we are more interested in those bipartite graphs which are similar to bipartite graphs similar to the one shown in Fig. Why? In the coming ﬁgures you ﬁnd certain clues of synthesizing self complementing graphs using simple building blocks? . According to this complementing permutation vertices of one partite are permuted onto vertices of the same partite. The complementing permutation p = (1A3A)(2A)(4A)(1B3B)(2B)(4B).Self Complementing Graphs 147 Figure 4.

11.40: A successful attempt to synthesize a self complementing graph. The bottom diagram shows graph G. p(G) and p2 (G) in that order. .148 Basics of Graph Theory Figure 4.

p(G) and p2 (G) in that order. .11.41: A successful attempt to synthesize a self complementing graph. The bottom diagram shows graph G.Self Complementing Graphs 149 Figure 4.

11.150 Basics of Graph Theory Figure 4. . p(G) and p2 (G) in that order. The bottom diagram shows graph G.42: A successful attempt to synthesize a self complementing graph.

43: A failed attempt to synthesize a self complementing graph from individual components. .Self Complementing Graphs 151 Figure 4. p(G) and p2 (G) in that order. The bottom diagram shows graph G.11.

152 Basics of Graph Theory .

5 5.4 5.3 5.9 Design of Algorithms The Bucket Algorithm Finding if a Graph is Connected Finding if a Graph is a Tree Finding a Spanning Tree of a Graph Finding a Minimum Spanning Tree of a Weighted Graph Finding a Path in a Graph The Shortest Path Problem Graph Traversal Techniques 5.7 5.2 5.8 5.11 Shortest Path Algorithms 5.6 5.10 Some Graph Theoretic Claims 5.1 5.Chapter 5 Basics of Graph Algorithms 5.12 Discussion .

For example. A four line procedure known as the Bucket Algorithm which can be molded into a number of useful and powerful graph algorithms based on greedy strategies. how can we ﬁnd an actual cycle in a cyclic graph (see Concept Map 5.154 Basics of Graph Algorithms Introduction We have studied a number of concepts related to graph theory in the last chapter. The original research papers were about encouraging students to discover and learn (graph algorithms) by themselves with minimal help provided by an instructor in the form of provocative questions. We have also studied a number of properties linking diﬀerent concepts. For example. mathematics. In this chapter. Vol. and ofcourse computer science. The initial part of this chapter is based on one of our papers published in IJECE. Summer-Fall 2003. The paper was co-authored by Sara Tahir. 2. . The later part of this chapter is based on one of our CS department research reports which was coauthored by Komal Syed. social sciences. For example an edge is a bridge edge provided its removal disconnects a graph. In this chapter we shall study a number of graph algorithms. engineering. biology. No. we provide a detailed study of a number of graph algorithms that have applications in diverse ﬁelds like chemistry. we talked about a bridge edge and a cycle in a graph. The recursiuon tree and the colored puzzle are some of these visual aids which facilitate a learner or a designer in his or her path towards discovery. Again this building block can be used to design a number of sophisticated shortest path algorithms based on dynamic programming. Another four line procedure known as 2-edge Shortest Path Algorithm which ﬁnds shortest paths of length 2 from a given vertex to every other vertex in a weighted directed graph. and its title was Should We Teach Algorithms.1). Almost all of these algorithms are based on the following easy to understand and friendly to use buliding blocks: 1. 2.Making and Breaking Connections.2. We have also studied that a graph is cyclic if it contains a cycle. how can we check if an edge is a bridge edge. how can we check if a graph is cyclic. We also provide a number of powerful learning tools to understand and design various algorithms. and Yasser Hashmi and its title was Shortest Path Algorithms .

.155 Concept Map 5.1. A panoramic picture of some Concepts. Properties. Action items and Graph Algorithms.

Despite the fact that one cannot guarantee that a student could become an eﬃcient algorithm designer. We stress that while we are familiarizing students with existing algorithms. Our experience of teaching algorithms indicates that creativity in algorithm design depends. one can always encourage students to redesign an algorithm right from scratch.1 Design of Algorithms Teaching the standard course “Analysis & Design of Algorithms” at an undergraduate level in a typical Computer Science program essentially has two objectives. we believe that the instructor. Polya [10] remembers the time when he was a student himself: he was always perturbed by the question: ”Yes the solution seems to work. dealing with analysis. we should not formally teach anything. and above all the conﬁdence required in solving a non-textbook problem. It is now . excitement. and stimulating questions posed by the instructor. is to equip the students with the necessary tools and techniques. The ﬁrst objective. can sow the seeds that could blossom into the genius that produces eﬃcient yet astonishingly simple algorithms. on how we deal with the analysis phase. Similarly the ability to understand and analyze algorithms does not guarantee that one could become an eﬃcient algorithm designer. to a large extent. is essentially a creative eﬀort containing all the ingredients of a thriller: adventure. rather incite. Though there are rules of thumb that can be followed to help an individual design an algorithm. There is no guarantee that one who critiques literature can learn to write beautiful poetry. following our approach and providing proper guidance. This second objective. it appears to be correct. which is perhaps far more important. timely hints. Instead we should encourage. and suspense. challenge. students to create algorithms themselves using some very fundamental concepts. The second one. The study of the methods and rules of discovery and invention is a ﬁeld in its own right.156 Basics of Graph Algorithms 5. The objective is that students should experience the thrill and excitement of discovery even during the initial phases of understanding existing algorithms. but how is it possible to invent such a solution? How could I invent or discover such things by myself ?” We feel that with the availability of some pre-requisite knowledge. concerned with the design of algorithms. there is no precise algorithm available that can be used to design new algorithms. is to familiarize students with existing algorithms.

In the words of Hale [5]. Taylor [18]. occasionally asking a question. 5. allowing his students to ﬁnd the answers in their own ways”.1. and other courses. 5.1. or technology”. [6]. Rine [13] deﬁnes design as ”A systematic. on the other hand. leading to an eﬀective or eﬃcient outcome. Many professors still use his teaching style not only in his subject of specialization (topology). made and deployed. It is interesting to note that our approach is similar in some aspects with the so-called Moore Method of teaching and learning.2 The Bucket Algorithm We start with a simple algorithm which we call the Bucket Algorithm (the bucket symbolizes a friendly container where a child puts every new toy or every new discovery) consisting of just four lines of pseudo code: We shall show how this primitive procedure can be used to reinvent a number . and then actively guides the students in their path of discovery. does not allow collective eﬀort on the part of the students inside or outside of class. The last deﬁnition suits our discovery based learning approach in which a teacher formulates a directed set of questions and hints in order to help his/her students design algorithms. L. mostly quiet. He sat in the back of the room. solution. and have advanced or modiﬁed the Moore Method in a number of ways [3]. directed set of decisions that are introduced. starts with something (very simple). while characterizing (his version of) the Moore method of teaching. he did not profess.1 What is Design? According to the Webster’s dictionary [1]. 157 5. but in analysis. ”Design is to conceive and plan out in the mind”. Moore was a professor of mathematics at the University of Texas. encourage lively discussions inside as well as outside the classroom. We. The teacher.The Bucket Algorithm important to ﬁnd a good working deﬁnition of design (of algorithms). algebra. He also does not allow the use of any source material. ”What was so special about his mode of teaching was that he did not lecture. In the words of Miller [9].2 The Moore Method R. game theory. in our model. ”Design is the thought process comprising the creation of an entity”.

1: Two pictures of what the Bucket B will look like in the initial stages of the Bucket Algorithm. j g h k f d e i g j i h k f d e a b c a b c Figure 5.158 Basics of Graph Algorithms Algorithm 17: The Bucket-Algorithm input : A Graph G output: A Bucket B 1 Put any vertex x of Graph G in the Bucket B. 2 while there are edges coming out of the Bucket B do 3 Select an edge connecting vertex u in B to v not in B.2. 4 Put v in B . .

1 Understanding the Bucket Algorithm The Bucket Algorithm is simple and straightforward. Speciﬁcally the Bucket Algorithm would be used to solve the following problems: 1. 3. Find a spanning tree of a graph. Conduct a breadth ﬁrst search in a graph. [2]. Find the number of connected components of a graph. 9. [11]. It is just a 4-line algorithm with a simple while loop (with no conditional statements or recursive calls). 5. [14]. Rediscover Prim’s Algorithm.The Bucket Algorithm 159 of existing powerful algorithms in graph theory ([16]. 5. Solve the single-source shortest-paths problem: rediscover Dijkstra’s Algorithm. 7. because it is easy to understand and at the same time ﬂexible enough to handle a variety of diﬀerent problems. With some encouragement from the instructor. 4. Find if a graph is a tree. [15]. 11. [17]. We start with something simple but potentially very powerful. Find a minimum-spanning tree of a graph. Find a bridge in a graph. Rediscover Kruskal’s Algorithm. They would learn the ways and means of devising their own algorithms.2. the students should develop a keen desire and ability to understand the motives behind. Simple. [4]). 12. Conduct a depth ﬁrst search in a graph. . and the procedures followed in order to arrive at innovative solutions. Find if a given graph is connected. 10. Find a path between two vertices in a graph provided a path exists. 2. 6. 8.

An edge belonging to this last set of edges is called a cross edge and is of most interest to us. b. {d. k}. and those outside the bucket. {d. The second is the set of edges connecting vertices outside the bucket with each other: {{f. of the Graph G into the bucket. {b. Notice that there are two types of vertices: those inside the bucket represented by the set {a.2: Two pictures of the Bucket B after diﬀerent iterations through the Bucket-Algorithm. e}}.160 j g h k f d e a b e c f d i g h k a b c j i Basics of Graph Algorithms j g h k f d e a b c i Figure 5. . say node b.2. k}. {a. {b. j}.2). c}.1). Next we choose any edge joining vertex a to any other node. c. d}} to choose from in Step 3 as we iterate through the while loop. d}. f }}. {a. Depending on the constraint we place on the selection of cross edges in Step 3. Figure 5. Now we have a set of nodes {a. j.2(middle diagram) shows the bucket B after diﬀerent iterations through the Bucket Algorithm.2. Step 1 instructs us to put any node. h. g. b} in the bucket giving rise to a set of edges {{a. g}. c}. 5.1 for a picture of what the Bucket B will look like at this stage. This set of edges is equal to {{a.2. {h. k}}. {b. The ﬁrst is the set of edges connecting vertices inside the bucket with each other: {{a.2 How does it Work? We identify a Graph G and a Bucket B (See Figure 5.2. {i. h}. d.2. The third is the set of edges (the “branches coming out of the Bucket B” in Step 2) connecting vertices inside the bucket to vertices outside the bucket (see the middle diagram of Figure 5. These two diﬀerent kinds of vertices give rise to three diﬀerent kinds of edges. See Figure 5. the set {f. {i. k}. say node a. {c. i. {b. in the graph (since all other nodes are currently outside of the bucket) and put b in the bucket.2. f }. i}. k}. we can implement numerous algorithms. b}. f }. {g. e}.

The Bucket Algorithm 161 5. What is the worst-case complexity of this algorithm? It is recommended that the instructor not involve the underlying data structure at this stage in order to tackle the issue of complexity. During this activity the instructor should ask thought provoking questions such that the students focus on multiple facets of the algorithm that would later help in designing new algorithms.3 Playing with the Algorithm We strongly encourage our readers to play around with the Bucket Algorithm to get comfortable with it. Would all the vertices of the graph move into the bucket after the completion of the algorithm? When would this scenario be true.4 Solving Other Problems The above questions would induce a deeper understanding amongst students about how the Bucket Algorithm works under diﬀerent conditions and give some hints while solving more complex problems. Out of a sequence of six questions posed by Skiena [16] in order to guide one to discover the right algorithm.2. It will be useful at this stage if the students are asked to derive the time complexity of the Bucket Algorithm. Students must come to realize the importance of cross edges: it is because of this cross edge {u. v} we select in Step 3 that we discover the new vertex v. 5. According to David [12].2. It may be advisable to include it at a later stage.5 The Right Provocation It is well known that a real understanding of the problem is a necessary condition to solve any problem. “Half way home to solving a problem is a clear understanding of the problem”. the ﬁrst question is ”Do I really understand the problem?” Then comes the role of the teacher in terms of how he/she states a problem and provokes (or guides) his/her students to solve it in a speciﬁed manner.2. For . After the students are conﬁdent that they understand the idea behind the Bucket Algorithm. 5. the instructor can start asking them to modify it to solve more complex problems. and when would it be false? Does it make any diﬀerence if we have a diﬀerent starting vertex? Note that there are situations when it really makes a diﬀerence. Such questions could be: Under what conditions would there be no edges coming out of the Bucket? Note that this condition should be met otherwise the algorithm would never terminate.

Please see Concept Map 5. the instructor should ask the students: “Can you modify the Bucket Algorithm such that you may be able to determine whether a given graph G is connected?” The emphasis should be on using the existing techniques with minimum modiﬁcation. The answer is simple: if. 5. Brighter students would have been able to identify at that stage that some nodes will be left outside the Bucket B when a graph is not connected since cross edges do not exist connecting them to nodes inside the bucket (Figure 5. The teacher should ﬁrst make the students appreciate the need for partitioning the array into halves such that all numbers in the ﬁrst half are smaller than each number in the second half. he/she cannot expect his/her students to discover the said algorithm just after understanding the sorting problem. the instructor asked when there would be nodes left outside the bucket. The instructor in this case will have to make an extra eﬀort to guide such students. Please see Concept Map 5. the complexity of the modiﬁed algorithm. Not all students may be able to identify this property of the Bucket Algorithm. . there are still any nodes left outside the bucket then the graph is not connected. Why we should do this and how should we do this are both equally important for designing. Once all students have understood the solution (having arrived at it on their own with well-timed prodding from the instructor) the instructor should start the discussion regarding cost calculation.3 Finding if a Graph is Connected Assuming that the students know what a connected graph is.162 Basics of Graph Algorithms example if a teacher is talking about Quick Sort. discovering (and even understanding) the said sorting algorithm.3. however. The understanding of the previous state of an abstract system and the (usefulness of the) ﬁnal system state after the application of a so called fundamental operation [7] (for example the partitioning procedure in Quick Sort) is crucial in problem solving in computer science as in elsewhere.1). all nodes come inside the bucket. If. after the Bucket Algorithm has been applied to a graph G. then graph G is connected.2..e. Notice while students were becoming familiar with the Bucket Algorithm.2. i.

1: A graph G that is not connected.3. Applying the Bucket Algorithm once on a graph with more than one connected component would tell us that the graph is not connected as all the vertices of the graph do not end up in the bucket. What would be the resulting time complexity of this algorithm? The . 5. and so on and so forth. it is the job of the instructor to at least identify them for those students who cannot visualize the solution immediately. There are essentially two diﬀerent problems here. Applying the algorithm again with a new bucket would give us a new connected component. This could be solved if we remove the given edge and then check the number of connected components in the resulting graph.2 Finding a Bridge in a Graph A cut edge or bridge is one whose removal produces a graph with more connected components than the original. nodes i and j will be left outside the Bucket B. The ﬁrst problem is to check if a given edge is a bridge.3.3.Finding if a Graph is Connected j g h i k h 163 g j i k f d e a b c f d e a b c Figure 5. The number of times we have to apply the Bucket-Algorithm depends upon the number of connected components. The vertices that do end up in the bucket belong to a single connected component.1 The Number of Connected Components Once we understand how to ﬁnd if an un-directed graph is connected the above problem becomes simple and very little imagination is needed to answer the above question. and this would determine the worst-case time complexity. once the Bucket Algorithm terminates. 5.

Solving a problem from diﬀerent angles and then making a comparison is the single most important exercise for a student studying algorithms (Rawlins [11]). The problem is thus reduced to repeatedly applying the algorithm designed to .1 Every Edge in a Tree is a Bridge We know that a tree having n vertices consists of bare minimum number of edges. This implies that removing any edge would disconnect a tree. We already know how to check if a given edge is a bridge in a graph. It highlights the fact that looking at various deﬁnitions or properties (which come from a study of graph theory) is sometimes extremely useful and it provides the seed for designing a number of very powerful algorithms. How many times the Bucket-Algorithm is applied and what is the resulting worst-case complexity of the algorithm? g h j g i k h j i k c b e f d e a f d a b c Figure 5. 5. which makes it a connected graph.164 Basics of Graph Algorithms second problem is to ﬁnd or locate a bridge in a given graph. 5. This in not only true for this problem but is true for a majority of problems.4. Thus every edge in a tree is a bridge.4 Finding if a Graph is a Tree The algorithms that solve this problem depend on how we deﬁne a tree.2: A cut edge or bridge is one whose removal produces a graph with more connected components than the original graph. Once the ﬁrst problem is solved it should be a simple matter to handle it.3.

4. We know how to ﬁnd if a given graph is connected using the Bucket Algorithm. Once they have the answers it would again be stimulating for them to compare their ﬁndings with their colleagues within the classroom. p − 1. A spanning tree of a given graph also satisﬁes this property. In fact. For example..2 The Number of Edges in a Graph We can deﬁne a tree in a number of ways. 5. This deﬁnition or property can be used to design an algorithm to check if a given graph is a tree. all of these deﬁnitions are equivalent implies. Thus the spanning tree of a tree would be exactly the same tree. 5. How complex is this problem? Is it possible to count the number of edges while we are checking if the given graph is connected? Would that perhaps reduce the complexity? 5.e. Encouraging and initiating interesting discussions and even heated debates is one of the most important responsibilities of a teacher: (s)he must simply coordinate and make sure that the interaction is moving in the right direction. i. The number of times we would have to do this and ﬁnding the resulting complexity is an interesting exercise by itself.Finding if a Graph is a Tree 165 check if an edge is a bridge.4 A Comparison A comparison of all these algorithms would be extremely beneﬁcial to the students if they are encouraged to work it out independently.4. .3 The Spanning Tree of a Tree We know that a tree has the minimum number of edges required to connect a given number of vertices. So the problem is reduced to counting the number of edges.4. Only when the students have gained conﬁdence that they understand the basic problem and can ﬁnd an eﬃcient solution should we move to more complex problems such as ﬁnding whether a given graph is a forest. a connected graph is a tree provided the number of edges in the graph is exactly equal to one minus the number of vertices in the graph. The catch is that the graph should be connected otherwise the deﬁnition would not apply (why?). as it is a tree.

5. What would be the worst-case time complexity of this algorithm? 5. 5.5.5 Finding a Spanning Tree of a Graph The algorithm that we design to solve this problem depends on how we visualize the development of a spanning tree. This idea would give birth to an algorithm: Remove all edges that do not disconnect the given graph. Or we can start with no edges and start growing edges until we get a tree. In the earlier approach we should be careful and should not disconnect the graph. The resulting complexity would change dramatically depending upon the approach used. We can start with the original graph and start with pruning or removing edges until the graph becomes a tree. How many times we use the Bucket-Algorithm eventually decide the overall worst-case complexity.3 Selecting Edges While running the Bucket Algorithm. In the second approach we should be careful not to create cycles in the graph. Each approach has its merits and demerits and the comparison itself is very enlightening especially because each approach has more advanced applications. 5.166 Basics of Graph Algorithms 5. This approach is opposite to the one discussed above: instead of pruning we are growing edges.5. If we just keep a record of all such edges we might get the spanning tree of the given .2 Growing Edges We start with no edges at all but with p isolated vertices. which would constitute the spanning tree. we might have noticed that every time we discover a new vertex it is because of a cross edge (step 3). We add edges out of the edge pool of the graph such that the resulting graph remains a tree. and that the number of such cross edges would be exactly equal to p − 1.1 Cutting Edges If we remove all redundant edges from a given graph and just keep edges essential to keep it connected the remaining graph would be a spanning tree of the given graph. It is also possible to identify some of the so-called cross edges (edges which are coming out of the Bucket). In each case the Bucket Algorithm helps us.

5. which looks at all possible solutions and then selects the one of our choice. It is very much possible to have multiple non isomorphic minimum spanning trees of a weighted graph but the weight .4 Integrating Concepts and Discovering Algorithms We show a concept map (Concept Map 5. We show in Concept Map 5. properties and the Bucket Algorithm. which if reﬁned will lead to a number of important algorithms. thus giving rise to diﬀerent spanning trees.1 Cutting or Growing Edges: A Krushkal’s like greedy algorithm Each algorithm used to ﬁnd a spanning tree in the previous section could be used with proper modiﬁcation to ﬁnd a minimum-spanning tree of a connected and weighted graph. a number of systematic questions that if asked.6 Finding a Minimum Spanning Tree of a Weighted Graph There could be many non-isomorphic spanning trees possible for a given graph: each approach that we have described for ﬁnding a spanning tree of a graph was ﬂexible and there was a lot of maneuvering possible within it.6. This would give rise to an algorithm very similar to Krushkal’s. While cutting edges we select the edge of maximum weight (provided it does not disconnect the graph).2. Similarly. See Figure. having ﬁrst sorted the edges in descending order of weight. will provoke the learner to discover a number of interesting techniques.3. It is very much possible to discover most of the algorithms (that we have presented in this chapter) in class once we have become comfortable using and manipulating the Bucket Algorithm.5.2) which integrates diﬀerent concepts. 5. What if we ﬁnd all distinct spanning trees of a given graph using any approach and then select the one with minimum weight? Why is this approach.Finding a Minimum Spanning Tree of a Weighted Graph 167 graph.6. not feasible (although it is correct)? 5. How eﬃcient would this be if compared with the algorithms described earlier? 5. we can grow edges starting from the edge of minimum weight (making sure no cycle is created).

A minimum spanning tree of G is shown in the middle diagram. The Concept Map and an iterative sequence (ascending order) of asking questions help student discover or understand a number of useful graph algorithms. .2.168 Basics of Graph Algorithms Concept Map 5.1: A weighted graph G shown in the left diagram. Another minimum spanning tree is shown in the right diagram. j g 2 4 f 2 e 1 3 a 4 h 3 i 6 9 2 3 k 5 c f 2 1 e 3 d 4 g 2 4 j 3 i 6 9 2 3 b 2 e 3 k a 5 c f 2 1 3 d 4 g 2 4 j 3 i 6 9 2 3 b 2 3 k a 5 c h h d 3 b 2 Figure 5.6.

X c . Another maximum spanning tree is shown in the right diagram.6.6.3: Pictures of the graph after cutting edges of maximum weight in a Krushkal’s like algorithm. j g 2 4 f 2 d 3 e 1 3 a 4 h 3 i 6 3 k 4 5 c 2 b e 1 2 f 2 d 3 g 2 4 j j 3 i g 3 k a 2 3 b e 5 c 2 2 1 d 3 4 3 f a 2 4 h 3 i 3 k h 6 9 5 2 b 2 j g 2 4 f 2 d e 1 3 a 4 h 3 i 3 k 4 f 2 d e 1 3 g 2 4 j 3 i 3 k a c 2 b 2 h c 2 X3 2 b Figure 5. The minimum spanning tree is also shown in the bottom right corner.2: A weighted graph G shown in the left diagram.Finding a Minimum Spanning Tree of a Weighted Graph 169 j g 2 4 f 2 e 1 3 a 4 h 3 i 6 9 2 3 k 5 c f 2 1 e 3 d 4 g 2 4 j 3 i 6 9 2 3 b 2 e 3 k a 5 c f 2 1 3 d 4 g 2 4 j 3 i 6 9 2 3 b 2 3 k a 5 c h h d 3 b 2 Figure 5. A maximum spanning tree of G is shown in the middle diagram.

6.4: Pictures of the graph after growing edges of minimum weight in a Krushkal’s like algorithm.170 Basics of Graph Algorithms j g 2 4 3 f 2 d 3 e 1 a 4 h 3 i 6 9 3 k 5 c 2 b e 1 2 f 4 3 2 d g 2 4 j 3 i 6 9 2 2 3 b e 1 3 k a 5 c f 2 d 4 3 g 2 4 j 3 i 6 9 2 2 3 b 3 k a 5 c h h j g 2 4 3 f 2 d 3 e 1 a 4 h 3 i 6 9 2 2 b e 1 3 k 5 c 3 f 2 d 4 g 2 4 j 3 i 6 9 2 2 3 b e 1 3 k a 5 c f 4 3 2 d g 2 4 j 3 i 6 9 2 2 3 b 3 k a 5 c h h Figure 5. .

unlike some textbooks. although greedy approaches are relatively eﬃcient (being based on local conditions only). put this edge in M ST . It is important that the minimum spanning tree problem is an optimization problem in which we intend to minimize the sum of weights of all edges in the spanning tree. Please note that here we are not using any fancy data structure since the objective is not to have a complicated design. select one with minimum weight connecting u in B to v not in B. we are trying to minimize a local quantity. A lively discussion can be initiated to ﬁnd the merits and demerits of individual work.Finding a Minimum Spanning Tree of a Weighted Graph 171 of each tree would be the same (why?).2 Selecting Edges: A Prim’s like greedy Algorithm While forming a spanning tree we can select any cross edge.6.5). while there are edges coming out of the Bucket B do Out of all the edges coming out of B. In order to form a minimum spanning tree. we should try to include edges of less weight thus excluding those of higher weight. We show here how the simple Bucket Algorithm can be reduced into a minimum spanning tree ﬁnding algorithm which resembles Prim’s Algorithm. It would be useful if the students were asked to prove that this greedy approach would actually ﬁnd a minimum spanning tree. Using this simple technique the Bucket-Algorithm can easily be modiﬁed to ﬁnd a minimum spanning tree of a weighted directed or undirected graph (Figure 5. Without reading proofs given in the textbook they should come up with something of their own making.6. Put v in B. In order to minimize the global sum. It follows that among all cross edges that we may select we should pick the one of minimum weight. they are not always optimal. However. We are lucky this time: a so-called greedy approach is working optimally and is in fact optimizing the global sum also. Algorithm 18: Find Minimum Spanning Tree of a graph G input : A weighted Graph G output: Minimum Spanning Tree (MST) of Graph G 1 2 3 4 Put any vertex x of Graph G in a Bucket B. 5. They should also be asked to derive the time complexity .

6.5: Pictures of the Bucket B while ﬁnding a Minimum Spanning Tree of a weighted graph in a Prim’s like algorithm. .172 Basics of Graph Algorithms j 3 j i 6 3 3 g 2 4 3 4 g 2 4 i 6 3 h h k a 2 9 5 4 3 k a 2 9 5 f 2 c d 3 2 f 2 c 2 b e 1 d 3 b e 1 j g 2 4 4 3 j i g 3 2 4 3 i 6 3 h 6 h k a 9 2 5 4 k a 9 2 5 f 2 3 c 2 f 2 3 c 2 d e 1 3 b e d 1 3 b Figure 5.

In this algorithm (middle diagram) it is essential to check that the new edge that is selected should not form a cycle with the previously found minimum spanning tree. The top diagrams in this ﬁgure show how we grow a minimum spanning tree in a single bucket (this is a Prim’s like algorithm).6. Why? The reason is in fact more exciting because Prim’s algorithm is not just greedy. 5. It would be useful if they compare this approach with Prim’s algorithm. In the top algorithm there was no explicit need to check that this condition is true. we select an edge out of all edges (coming out of all buckets) in the graph and thus this technique grows various spanning trees in diﬀerent buckets. In the middle diagrams we can visualize that each vertex is initially in a separate bucket. the process of selecting the desired edge out of all edges coming out of the single bucket makes sure that no cycle is generated. something magical which cuts down the time complexity for not so obvious reasons. This technique (based . In fact. We should understand both the diﬀerences as well as the similarities. In the top diagrams we select an edge of minimum weight out of all edges coming out of the single bucket in which we have our minimum spanning tree growing. However the time complexity of Prim’s algorithm (as stated in most textbooks) is better.Finding a Minimum Spanning Tree of a Weighted Graph 173 of this approach. there is something else.6. The middle diagrams show a minimum spanning forest growing up in various buckets using a Kruskal’s like algorithm. 5. What is that magic? How and why it is working? Can this magic be used elsewhere and under what conditions? We shall discuss it later in this chapter. How about if we start Prim’s algorithm from every vertex? Thus we may be able to avoid an expensive check (that the resulting graph should not be cyclic) each time we insert a new edge (as in Prim’s algorithm) and at the same time we can exploit the inherent parallelism which was lacking in Prim’s algorithm? We initially put every vertex in a separate bucket. We show three diﬀerent techniques in action on the same weighted graph in Fig. the two approaches look identical.6.3 A Panoramic Picture of various MST Finding Techniques It will be useful from a learning perspective if we make a comparison between various minimum spanning tree ﬁnding techniques. for each bucket we select the edge of minimum weight coming out and thus grow various minimum spanning trees in diﬀerent buckets.

.6: Pictures of diﬀerent Buckets while ﬁnding a Minimum Spanning Tree of a weighted graph using diﬀerent techniques including the Boruvka’s Algorithm.6.174 Basics of Graph Algorithms c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 g 14 a 3 9 f 11 g 14 a 3 9 f 11 g 14 a 3 9 f 11 g 14 a 3 9 f 11 d e d e Prim’s like Algorithm d e d e c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 g 14 a 3 9 f 11 g 14 a 3 9 f 11 g 14 a 3 9 f 11 g 14 a 3 9 f 11 d e d e Krushkal’s like Algorithm d e d e c 2 7 5 4 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 c 2 7 5 12 6 b 1 8 c 2 7 5 4 12 6 b 1 8 g 14 a 3 9 f 11 g 14 a 3 9 f 11 g 14 a 4 3+43 9 f 11 g 14 a 3 9 f 11 d e d e Boruvka’s Algorithm d e d e Figure 5.

if. It will be useful to formally prove that in case of Prim’s algorithm we do not need a cycle test and still no cycles will be formed. Prim’s algorithm terminates when all vertices come inside the bucket. 2.6. But we do need a cycle test in case the edge weights are not unique. In case of Prim’s algorithm we need not be worried about the formation of a cycle. In case of Kruskal’s algorithm either we are growing a minimum spanning tree (by inserting edges starting from low cost ones) or we are cutting edges starting from high weight edges. however we consider all edges incident on a vertex inside a bucket then we do need to be worried about the formation of a cycle. Why? Do we need a cycle test in Kruskal’s algorithm in case all edge weights are unique? We do not need a cycle test in Prim’s algorithm in spite of the fact that edge weights are not unique? Why? 5. We try to exploit the inherent parallelism in this scheme where each processor is running a Prim’s like algorithm on each vertex. If all edge weights in a graph are unique then we do not need a cycle test in Boruvka’s algorithm. The big question is do we need to make an expensive cycle check each time we insert an edge? It will be interesting to ﬁnd under what conditions we need a cycle test and when we do not need such a test? This algorithm terminates when the number of edges selected becomes exactly equal to one less than the number of vertices in the graph. It will also . In case of Boruvka’s algorithm. The algorithm terminates when all edges have been considered. It is interesting to note the following about the three minimum spanning tree ﬁnding algorithms: 1. 3. 4. This is because of the fact that we consider edges coming out of the bucket only. 5. In the ﬁrst case we have to make sure that no cycle is created and in the second case we should be worried about disconnecting the graph.6. we grow a minimum spanning tree in each bucket just like Prim’s algorithm.Finding a Minimum Spanning Tree of a Weighted Graph 175 on the Boruvka’s algorithm) is shown in action (on the same weighted graph) in the bottom diagrams of Fig. the way we move forward makes sure that no cycle is formed.

6.2.4 The Maximum Spanning Tree Problem All the minimum spanning tree algorithms described here can easily be modiﬁed in order to ﬁnd the maximum spanning tree of a weighted graph G.1. We shall repeat this problem while ﬁnding the shortest path (or the longest path) in a graph having negative edge weights. Algorithm 19: Find Maximum Spanning Tree of a graph G input : A weighted Graph G output: A Maximum Spanning Tree (MaxST) of Graph G 1 2 3 4 Put any vertex x of Graph G in a Bucket B.7. put this edge in M axST . A curious reader may have realized by now that positive or negative edge weights in a weighted graph does not create any problem while evaluating the minimum or maximum spanning tree of a graph. while there are edges coming out of the Bucket B do Out of all the edges coming out of B.1. and ﬁnd the maximum spanning tree while showing the contents of the Bucket B after each step. We can make a small change in one of the Minimum Spanning Tree Algorithms in order to convert it into a Maximum Spanning Tree Algorithm as follows.1. A small change in the algorithm can do the job. We shall address these and other related issues in a problem set. We shall discuss that the shortest path problem becomes complicated if all edge weights are not positive. Apply the above algorithm to the following graph G consisting of positive as well as negative edge weights. 5. Do we face a similar problem while ﬁnding a minimum spanning tree of a graph having negative edge weights? . Apply this algorithm to the graph shown in Fig. Problem Set 5. Do you think there will be any complication in ﬁnding a maximum spanning tree if the edge weights are negative (or if they are positive). Problem 5. 5.6.1. select one with maximum weight connecting u in B to v not in B. Put v in B.176 Basics of Graph Algorithms be interesting to prove that in case of Boruvka’s algorithm no cycles will be formed even if we do not make a cycle test provided all edge weights are unique. Problem 5.

6. 5.1). If we keep moving along the edges connecting one vertex to another within the graph.7. What is wrong with this approach? If there are cycles in the graph it is possible that we never reach our destination. a time would come when we would reach our destination.7: A Graph G having negative edge weights for problem set. Now instead of checking whether the graph is connected or not. we better check if the two given vertices belong to a single connected component.Finding a Path in a Graph 177 Figure 5. . since we might have to do a lot of backtracking.7. What would be the worst-case time complexity of this algorithm? Note that we have used a similar technique to ﬁnd a spanning tree of a graph.7 Finding a Path in a Graph It is possible to ﬁnd a path between two vertices provided the graph is connected. It would be useful to pinpoint the similarities as well as the diﬀerences.1 Cutting Edges If we remove all redundant edges from a given graph and just keep the edges essential to keep the two vertices connected. 5. the remaining graph would be a “straight forward” path between the two vertices in the given graph (Fig. What if there are no cycles in the graph – what if we ﬁrst make a spanning tree of the graph? Even now it would be diﬃcult to ﬁnd a path. 5.

178 Basics of Graph Algorithms j g h i k g j i h k g j i h k f d e a b c f d e a b c f d e a b c j g h i k g j i h k g h i k f d e a b c f d a b c f d a b c Figure 5.1: Pictures of the graph after cutting edges in order to ﬁnd a path between vertex a and vertex c. .7.

We assume that we are ﬁnding shortest paths from a single vertex to all other vertices. Students should experience this confusion and the resultant backtracking. be a shortest path? If not then what should be done to achieve our objective? Note that it is easier to ﬁnd a shortest path in a graph with uniform edge weights. would the problem become simpler? What if we ﬁrst ﬁnd a minimum spanning tree of a graph and then move backwards from the destination to the source vertex in order to ﬁnd shortest paths as described earlier? It is obvious from Figure 5.1. Suppose we apply the Bucket Algorithm starting with the given vertex: the spanning tree thus formed would originate from the given vertex since the given vertex would be the root. now the root. 5.2). we would eventually reach the root without any confusion (Fig. so ﬁrst we should solve this problem (which is simpler) before attacking a more complex one. However if we start from the destination vertex and keep selecting the parent vertex.7. Do we need a diﬀerent algorithm from the one used to ﬁnd a shortest path in a graph with uniform edge weights? Why? If somehow we remove edges of higher weights from the graph without disconnecting the two given vertices. but again we may start our journey in the wrong direction and would have to backtrack. Now assume that the edge weights are diﬀerent. It will still be interesting to investigate how a shortest path algorithm resembles and at the same time diﬀers from a minimum spanning tree algorithm. found using the algorithms of the previous section. would the path.The Shortest Path Problem 179 5. We shall come back to this problem after discussing graph traversal techniques in a later section.8. to the destination vertex? The answer is still “no” because a parent may have multiple children. . and thus there still exist many diversions. With this additional information would it be easier to ﬁnd a path from the given vertex.7. that a minimum spanning tree of a weighted graph does not always provide shortest distances from a given vertex.2 Selecting Edges Does the problem become simpler if we ﬁrst ﬁnd the spanning tree of the given graph? Now if we start moving from the given vertex to the destination vertex. 5.8 The Shortest Path Problem If all edges in the graph were to have the same weight. would it be less confusing? Perhaps. We also keep a record of the parent of every vertex in the spanning tree.

2: Various stages in ﬁnding a path from every vertex to vertex a in a graph.180 Basics of Graph Algorithms j g h i k a d e j g h i k a d e a f g h i j k c j e d b g h i k c b e c f d g b e j c f d g j i h k a b c f i h k a b c f a f d e b Figure 5.7. .

It should also be kept in mind that the minimum spanning tree can easily be modiﬁed to ﬁnd a maximum spanning tree of a graph while it is not possible to do so in case of ﬁnding a longest path in a graph G (with positive edge weights).1 Dijkstra’s (like) Algorithm We produce both the algorithms side by side.2 Discussion on Dijkstra’s (like) Algorithm It was interesting to compare the described shortest path algorithm with the corresponding minimum spanning tree algorithm – but at the same time .2).8. There is indeed a delicate diﬀerence between the two – this diﬀerence should make us understand why minimum spanning tree algorithm fails to ﬁnd a shortest path spanning tree and why a shortest path spanning tree algorithm fails to ﬁnd a minimum spanning tree of a weighted graph G.The Shortest Path Problem j g 2 4 f 2 e 1 3 a 2 d 3 b 9 4 h 6 17 j 3 i 3 k 5 c 2 4 7 f 2 6 1 e 3 d 5 11 g 2 4 h 13 a 0 3 2 b 2 2 6 e 9 6 15 j 3 k 5 3 c 4 f 2 3 d 1 5 7 g 23 4 2 4 h 9 a 0 3 6 9 2 b 2 181 3 20 i 3 i 12 3 k 5 c 4 9 2 Minimum Spanning Tree Weight of the tree = 26 Shortest Path Spanning Tree Weight of the tree = 31 Figure 5. The step by step working of the two algorithms is shown in the ﬁgure below (Fig. 5.8. The shortest distances (as shown in red color) from vertex a provided by the two spanning trees are diﬀerent as indicated in these diagrams. The weight of the minimum spanning tree is also diﬀerent from that of the shortest path spanning tree. 5.8. The right diagram shows a shortest path spanning tree (SST) of the same graph.8. it will become obvious that the two algorithms are derived from a common ancestor – the Bucket Algorithm. It is obvious that initially the two algorithms produce similar results but then they depart ultimately producing diﬀerent results. 5.1: The middle diagram shows a minimum spanning tree (MST) of a weighted graph G shown in the left diagram.

while there are edges coming out of the Bucket B do Out of all the edges coming out of B.182 Basics of Graph Algorithms Algorithm 20: Find Minimum Spanning Tree of a graph G input : A weighted Graph G output: A Minimum Spanning Tree M ST 1 2 3 4 5 Put any vertex x of Graph G in a Bucket B. a vertex x output: Shortest Distance Dist(i) of every vertex i from x 1 2 3 4 Put vertex x in Bucket B. Dist(v) = Dist(u) + w(u. while there are edges coming out of the Bucket B do Out of all the edges coming out of B. v) in M ST . Put edge (u. Algorithm 21: Find shortest distance of every vertex from a given vertex x in G & also the shortest path spanning tree of G from x input : A weighted Graph G. and Dist(i) of every other vertex i equal to ∞ . . Put vertex v in B and edge (u. select the edge for which Dist(u) + w(u. select one with minimum weight connecting u in B to v not in B. Initialize Dist(x) = 0. v) in SST . v) is minimum where vertex u is in B and vertex v is outside the Bucket B. Put vertex v in B. v).

3 where some edge weights are negative. and put it in Bucket B. we consider vertices at a distance of one edge. Remember vertex i is the last vertex which went into the Bucket B. we select a vertex j which is at a shortest distance from vertex x. We show another weighted graph in the right diagram of this ﬁgure. In order to assert that Dijkstra’s like algorithm is able to ﬁnd correct results let us ﬁrst present a scenario where the above mentioned algorithm fails to ﬁnd shortest paths. Out of all these vertices (some of which are at a distance of one edge and some at a distance of two edges). In the second iteration of the while loop. the edge (x. 1.8. The cost of this action is equivalent to making p − 2 + p − 3 = 2p − 5 steps. This action is tantamount to a claim that we have found a shortest path from vertex x to vertex i. The vertex j goes in the Bucket B and the corresponding edge goes in shortest path spanning tree. 5. we consider vertices which are directly connected to x. Again this action means that we have found a shortest path of vertex j from vertex x. Remember that this algorithm works on a greedy strategy – it makes decisions on the basis of local conditions – but produces optimal results on a global basis provided all edge weights in a graph are positive. The cost of this action is equivalent to making p − 2 comparisons. If all edge weights are positive then this claim will be right – it will. and which are indirectly connected to x through vertex i. 2. The same weighted graph and its (correct) shortest path spanning tree is shown in Fig. we select a vertex i which is at a shortest distance from x. be violated if some edge weights in G are negative. This graph is diﬀerent from the one shown in the left (and middle) diagram in the following ways: .4.8. however.The Shortest Path Problem 183 it will be a learning experience if we look into the working of the shortest path algorithm under conditions when it fails to provide optimal results. Out of all such vertices (at a distance of one edge from x). In the ﬁrst iteration of the while loop. But before we do that let us discuss some of the salient features of this algorithm. It is obvious from this ﬁgure that Dijsktra’s algorithm fails to produce correct results. i) goes in the shortest path spanning tree. We show a directed graph in the Figure 5.

8.2: Pictures of the Bucket B while ﬁnding a Minimum Spanning Tree (left diagrams) as compared to the pictures while ﬁnding a Shortest Path Spanning Tree (right) from vertex a. .184 Basics of Graph Algorithms Figure 5.

8.3: Pictures of the Bucket B while ﬁnding a shortest path spanning tree using a Dijsktra’s like algorithm. . The ﬁnal answer as shown in the bottom right diagram is incorrect.The Shortest Path Problem 185 j g 2 4 f 2 e -5 3 a -4 h 3 i 6 9 2 3 k 3 c f 2 e -5 4 3 g 2 -4 j 3 i 6 0 a 2 9 3 k 3 c b 2 2 e 3 f 2 -5 4 3 g 2 j -4 h 3 i 6 0 a 2 9 3 k 3 c b 2 2 h d -4 b 2 d d -4 -4 Vertex a at a shortest distance of zero edge Vertex b at a shortest distance of one edge Vertex f at a shortest distance of (at most) two edges 5 j g 2 4 3 f 2 e -5 3 -4 h 0 a 2 d -4 b 2 2 e 6 9 3 i 3 k 3 c 4 3 f 2 -5 d 3 5 -4 4 0 a 2 b 2 2 0 e 9 g 2 -4 h 6 j 3 i 3 k 3 c 3 f 4 2 -5 d 3 5 -4 4 j 7 g 2 9 -4 h 0 a 2 b 2 2 6 9 3 i 8 3 k 7 3 c 4 Vertex c at a shortest distance of (at most) three edges Vertex d at a shortest distance of (at most) four edges The (incorrect) Shortest Path Spanning Tree Figure 5.

. 5. The middle diagram shows the correct shortest path spanning tree for the same graph.186 Basics of Graph Algorithms 1. Please note that there are negative weight edges in this graph but no negative weight cycles: a negative weight cycle is a cycle in a graph where the net sum of the weight of the edges in the cycle is less than zero. 5 j 7 g 2 4 3 f 2 0 e -5 d 9 3 5 -4 -4 h 0 a 2 b 2 2 0 e 6 9 3 i j 8 3 k 7 3 c 4 3 f 2 3 7 4 g 2 9 5 3 i 6 0 a 2 9 8 3 k 6 4 3 c 3 2 1 e f 2 -5 g 2 -12 j 3 i 6 0 a 9 2 -4 b 2 3 k 3 c -4 h h 3 d d -5 5 -4 b Dijkstra’s shortest path spanning tree (incorrect) (Correct) shortest path spanning tree Shortest distances keep on decreasing in a negative weight cycle Figure 5.4: The left diagram shows an (incorrect) shortest path spanning tree produced by a Dijkstra’s like algorithm. In the graph shown in the right diagram (Fig. The shortest distance path from vertex a to any other vertex is a simple path – no edge or vertex is repeated in this path. The right diagram shows a graph where shortest distances of red vertices from vertex a keep on decreasing if we move in a cyclic path as shown in red. This happens in any graph where there are negative weight cycles.8. 5. The shortest distances of the red vertices keep on decreasing if we move in a cyclic path as shown in red color with the result that the shortest distance of such vertices ultimately approaches minus inﬁnity.8.4). The magnitude of this shortest path is ﬁnite. 2. In other words the shortest distance between any two vertices does not reduce if we move in a cyclic path. The above observation is true for the left or the middle graph in the ﬁgure below (Fig.4) the above observations are not true.8.

8. now if we increase k to 6 there is no improvement in any shortest distance. 5.8. j) + Distk (j)}. it is denoted by Distk+1 (i) 1 2 3 for i = 1 to p do for j = 1 to p do Distk+1 (i) = min{Distk (i). The weighted adjacency matrix of the given directed graph provides all one edge paths from vertex x.8.3 The Shortest Path Problem Redeﬁned: The kedge Shortest Path Problem In order to overcome the above mentioned complication we redeﬁne the shortest path problem as follows.The Shortest Path Problem 187 5. Once we have the 1-edge shortest paths – we can convert them into 2-edge shortest paths and then into 3-edge shortest paths according to the algorithm described below. This graph is reproduced in Fig. k-edge shortest distance of every vertex i from vertex x denoted by Distk (i) output: (k + 1)-edge Shortest distance of vertex i from vertex x. If there are no parallel edges in the graph then these paths will also be the shortest paths from vertex x to every vertex adjacent to x.6 where we ﬁnd diﬀerent edge path from vertex . if no improvement takes place in any path then we stop. w(i. input : A weighted directed Graph G. Such one edge paths are shown in the top left diagram in Figure 5. Instead of ﬁnding the shortest path between two vertices we intend to ﬁnd k-edge shortest paths from a given vertex to every other vertex in a directed graph containing negative edges – the graph may even contain negative weight cycles.4. this happens when k = 5.5. 5.8. 5. Algorithm 22: Find (k+1)-edge shortest distance of every vertex from a given vertex x in a weighted directed graph G. Let us explore the consequences of the presence of negative weight cycles in a graph like the one shown in the right diagram of Fig. a vertex x. A k-edge shortest path (between two given vertices) requires that the path should be shortest but it should not consist of more than k edges.5.8. now we claim that we have found the shortest distance of every vertex from x. For the graph shown in the Fig. It is evident from the ﬁgure below – as we move from k-edge to (k + 1)-edge shortest paths there is some improvement in the length of a shortest path.

But when k increases beyond 5 then there is no change in shortest paths.5: We show k-edge shortest paths from vertex a to every vertex in graph G.8. When k changes from 1 to 5.188 Basics of Graph Algorithms j g 2 4 3 f 2 e -5 3 0 a -4 h j 3 i 6 9 2 3 k 9 3 c b 2 2 e 3 f 2 d -5 5 7 4 3 0 a g 2 -4 h 3 i 12 6 9 3 k 9 3 c 4 b 2 2 0 e 3 f 2 -5 3 d 5 7 4 g 2 9 -4 j 3 i 6 0 a 2 -4 b 12 3 k 9 7 3 c 4 2 1 h 2 -4 d -4 Vertices at one edge shortest distances 5 3 i 6 0 a 3 2 0 -5 e Vertices at (at most) four edge shortest distances: Not Stable 2 d 5 -4 b 2 1 0 e 9 Vertices at (at most) two edge shortest distances: Not Stable j 5 3 i 6 0 a 3 2 -5 2 d 5 -4 b 2 1 0 e 9 8 3 k 6 3 c 3 7 4 3 f 2 Vertices at (at most) three edge shortest distances: Not Stable j g 2 9 5 3 i 6 0 a 3 2 d 5 -4 b 2 1 -5 9 8 3 k 6 3 c 3 j 7 4 3 f g 2 9 -4 h 10 3 k 7 4 3 c 3 3 f 7 g 2 9 -4 h -4 h Vertices at (at most) five edge shortest distances: Not Stable Vertices at (at most) six edge shortest distances: STABLE Figure 5. . shortest path distances of some vertices change.

8. But when k goes beyond six then we are caught in a negative cycle – the shortest path of three vertices (belonging to a negative weight cycle and shown in red color) keeps going down. When k changes from 1 to 6.The Shortest Path Problem j g 2 4 3 f 2 e -5 3 0 a 2 d -4 b 2 2 e 9 -12 h 6 j 3 i 3 k 9 3 c 3 f 2 d -5 5 7 4 3 0 a 2 -4 b 2 2 0 e Vertices at (at most) three edge shortest distances 9 g 2 -12 h 6 j i 12 3 k 9 3 c 4 3 f 2 -5 3 d 5 7 4 g 2 9 -12 h 0 a 2 -4 b 6 9 3 i 189 3 12 3 k 7 3 c 4 2 1 Vertices at one edge shortest distances -3 3 -12 2 9 3 2 0 -5 e Vertices at (at most) four edge shortest distances 2 d 5 -4 b 2 1 0 e h 0 a 6 9 i Vertices at (at most) two edge shortest distances -3 3 i 6 0 a 3 2 -5 2 d 5 -4 b 2 1 9 0 3 k 6 3 c 3 3 f 7 4 j 7 4 3 f g j 10 3 k 7 4 3 c 3 3 f 7 g 2 9 j -3 g 2 6 0 a 3 2 0 -5 e -12 h -12 h 3 i 6 0 3 k 9 6 3 c 3 2 d 5 -4 b 2 1 Vertices at (at most) five edge shortest distances Vertices at (at most) six edge shortest distances: Still Not Stable j -6 7 4 3 f 2 0 -5 e g 2 6 0 a 3 -12 h 3 i 6 j -6 0 3 k 9 6 4 3 c 3 b 2 1 3 f 2 0 -5 e 3 7 g 2 6 0 a -12 h 3 i 6 j -3 3 k 9 6 4 3 c 3 b 2 1 3 f 2 0 -5 e 3 7 g 2 -12 -∞ 3 6 0 a 2 i -∞ 3 k 9 6 3 c 3 b 2 1 -∞ h 2 d 5 -4 2 d 5 -4 d 5 -4 Vertices at (at most) seven edge shortest distances: Still Not Stable Vertices at (at most) eight edge shortest distances: Still Not Stable Vertices at (at most) infinite edge shortest distances Figure 5. . the shortest paths of some vertices change. and this situation never becomes stable.6: We show k-edge shortest paths from vertex a to every other vertex in graph G.

8. 5. .1.8.2.2. Thus k keeps increasing and the distances keep going down. Please recall the weighted graph of Fig.4 The k-edge Longest Path Problem The k-edge longest path problem is quite similar to the k-edge shortest path problem.8. Find k-edge shortest paths with respect to vertex a while k changes from 1 to 10. Problem 5. no edge or vertex is repeated in these paths. 5.6.8. This is quite expected in view of our prior experience: if there are negative weight cycles in a graph then the shortest path (of certain vertices) keep increasing with k.5. An Important Conclusion If there are no negative weight cycles in a directed graph consisting of some negative weight edges then we can use our k-edge shortest path technique to ﬁnd shortest paths. Please note that the resulting shortest paths will be simple paths. it may become stable after some time as shown in Fig.8. Remember if we increase k beyond 5 while ﬁnding k-edge shortest paths then no (shortest) distance (with respect to vertex a) changes with k. we claim that we have found the shortest paths.8. The shortest distances of the rest of the vertices become stable as soon as k approaches 5. As soon as all the k-edge shortest paths become stable with increase in k. 5. This situation never becomes stable because of the presence of a negative weight cycle comprising three vertices shown in red color. 5. the shortest paths becomes stable. it is just like maximum spanning tree versus minimum spanning tree problem. We now change the magnitude of the weight associated with the edge (f. there are positive weight cycles in the graph then we shall be caught in an inﬁnite loop and the longest distances (of at least some vertices) will keep increasing with increase in k. When k increases the shortest path distances go down.190 Basics of Graph Algorithms x. It means that k would be less than or equal to p − 1 in case there are no negative weight cycles in the graph. the same weighted graph is reproduced below in the left diagram of Fig. Problem Set 5.7 where we operate on the same graph of Fig. As we increase k the longest path of certain vertices increases. Find how and at what value of k. however. If. g) from 4 to 40 as shown in the middle diagram of this ﬁgure. 5.

But when k goes beyond four then the longest distance of any vertex does not change.7: We show k-edge longest paths from vertex a to every other vertex in graph G.8: A weighted graph G for a problem set . the situation becomes stable and we claim that we have found longest paths in this graph. j g 2 4 f 2 d e -5 -4 3 0 a 2 b 2 2 e 9 -4 h 6 3 i 3 k 3 c f 2 -5 40 3 0 a 2 d -4 b 2 e 9 g 2 -4 h 6 j 3 i 3 k 3 c f 2 d -5 -40 4 3 0 a 2 b 2 9 g 2 -4 h 6 j 3 i 3 k 3 c Figure 5.The Shortest Path Problem j g 2 4 3 f 2 e -5 3 0 a 2 d -4 b 2 2 e 9 -12 h 6 j 3 i 3 k 9 3 c 3 f 2 d -5 5 7 4 3 0 a 2 -4 b 2 2 0 e Three edge (at most) longest paths 9 g 2 -12 h 6 j i 12 3 k 9 3 c 4 3 f 2 -5 3 d 5 2 -4 b 2 2 7 4 g 2 18 -12 h 0 a 6 9 3 i 191 3 12 3 k 9 3 c 4 One edge longest paths Two edge (at most) longest paths 6 j 3 i 6 0 a 2 -4 b 7 4 3 f g 2 -12 h 18 3 12 3 k 9 9 3 c 4 2 2 0 e 3 f 2 -5 7 4 g 2 6 j -12 h 18 3 d 5 3 i 6 0 a 2 -4 b 12 3 k 9 9 3 c 4 2 2 2 -5 0 e d 5 Four edge (at most) longest paths Not Stable Five edge (at most) longest paths Stable Figure 5.8.8. When k changes from 1 to 5 the longest path of some vertices improves.

8.2.8.5.2.8. Problem 5. vary k from 1 to 11.2. b). 5. Problem 5. the shortest distances become stable at a ﬁnite value of k? Why? What do you think are necessary and suﬃcient conditions for the shortest distances to become stable for a ﬁnite value of k in a weighted graph? Problem 5. Find if the longest paths become stable with increasing value of k.8. We already know that if there . Problem 5.7.8. Is it possible to use the above algorithm to ﬁnd if an undirected graph contains negative weight cycles? Problem 5. Please note that there is a big negative weight equal to -40 associated with the edge (d. Problem 5. Find k-edge longest paths for each vertex with respect to vertex a in the graph shown in the left diagram of Fig.5 The Shortest Path Problem in Undirected Graphs with Negative Weights We consider the shortest path problem in undirected graphs with negative edge weights but no negative weight cycles. if we further increase k then there is no change in the shortest distance of any vertex with respect to vertex a.3. 5.2. 5. Find k-edge shortest distances of all vertices with respect to vertex a.6.2. We need to explore if shortest distances of all vertices with respect to vertex a become stable when k increases while ﬁnding k-edge shortest paths.e.9.2. Comment on the claim that the longest path problem is a hard problem while the shortest path problem is a solvable problem. i. In spite of a large negative weight in the graph shown in the right diagram of Fig. What do you think are necessary and suﬃcient conditions for the longest distances to become stable for a ﬁnite value of k in a weighted graph? Problem 5.8.2. Repeat the above problem for the graph shown in the right diagram of Fig. We show another weighted graph as shown in the right diagram of Figure 5.8.2.8.8..192 Basics of Graph Algorithms Problem 5.4.2.8. Describe an eﬃcient algorithm (based on ﬁnding k-edge shortest distances) to ﬁnd if a directed graph contains negative weight cycles. 5. Find the value of k at which the shortest distances become stable.

5.8. 5. 5. Each such shortest path starts from vertex x and terminates . The undirected graph is converted into a directed graph as shown in the right diagram of this ﬁgure.9. Let us represent a k-edge shortest path of any vertex j from vertex x by SP athk (j).9) we run into a complication. When we apply our k-edge shortest path algorithm to the directed graph (shown in the right diagram of Fig.The Shortest Path Problem 193 are no negative weights then a simple greedy strategy (like that of Dijskrta’s Algorithm) will solve the shortest path problem in undirected graphs. It is quite evident that k-edge shortest distances do not stabilize in this graph with increase in k. and we get incorrect answers for shortest distances. Remember that the so called technique was designed for directed graphs and in order to apply it to undirected graphs we have to ﬁrst convert the undirected graph into a directed one.8. We show an undirected graph in left diagram of Fig. The challenge is how to handle this complication? Please understand that we are limiting our focus on a directed graph which is derived from an undirected graph as shown in Fig.8. The undirected graph is converted into a directed graph as shown in the right diagram.8. 5. 0 0 5 a 5 b a 5 5 a 5 6 -3 6 -3 2 2 c b b 6 d -3 6 -3 2 c d 4 2 c 2 d Figure 5.9: We show an undirected graph with negative edge weights but no negative weight cycles in the left diagram.8. With negative edge weights (but no negative weight cycles) we expect that our kedge shortest path technique will work with the hope that the k-edge shortest paths will stabilize for a ﬁnite value of k and we shall get the optimal answer.9. we have created a two-edge negative weight cycle in the directed graph. The working of the k-edge shortest path technique on this graph is shown in Fig. The correct shortest paths & distances with respect to vertex a are indicated in the middle diagram.10. The shortest distances with respect to vertex a are indicated in the middle diagram.

The shortest distances do not become stable for any ﬁnite value of k.10: Shows k-edge shortest paths & distances with respect to vertex a with k changing from one to ﬁve.8.194 Basics of Graph Algorithms 0 5 5 0 5 5 0 5 -1 a 5 6 -3 b 6 a 5 -3 b 6 a 5 -3 -3 b 6 3 2 2 6 6 -3 2 2 d 6 c ∞ d 6 2 2 c 2 d 4 c 2 One edge shortest paths Two edge (at most) shortest paths Three edge (at most) shortest paths 0 5 -1 5 5 -7 a 6 b -3 6 a 5 b -3 6 -3 2 2 6 -3 2 2 d 4 c -4 d -2 c -4 Four edge (at most) shortest paths Five edge (at most) shortest paths Figure 5. .

Apply the above Algorithm to the graph shown in Fig. w(i. it is denoted by SP athk+1 (i). 5. Algorithm 23: Find (k + 1)-edge shortest path & distance of every vertex from a given vertex x in a weighted directed graph G. Eﬃciency demands that we do not visit the same vertex again and again. Problem 5. Its weight is represented by Distk (j). 5. Now we are in a position to ﬁnd (k + 1)-edge shortest path of a vertex i from vertex x in a graph using the following algorithm. We must make every . 5. Out of the remaining paths we claim that Distk+1 (i) = min{Distk (i). input : A weighted directed Graph G. a vertex x.9 Graph Traversal Techniques It is possible to traverse a graph in a haphazard manner. Check if k-edge shortest paths stabilize for a ﬁnite value of k. Will it be possible to provide a warning that the given graph contains negative weight cycles? What modiﬁcations are needed in our existing algorithms to solve this problem? 5. output: (k + 1)-edge Shortest path of vertex i from vertex x.9 and verify that it provides correct results for values of k in the range of 1 to 5.Graph Traversal Techniques 195 at vertex j. Please note that this graph contains negative weight cycles. Compare your results with the correct shortest paths given in the middle diagram of Fig.8.3.3. assume that the last vertex in this shortest path is yj before terminating at j. k-edge shortest path of every vertex j from vertex x denoted by SP athk (j).3. its weight is equal to Distk+1 (i) 1 We need to ﬁnd SP athk+1 (i): We consider k-edge shortest path for every vertex j in the graph except for j where yj = i.3.8.8. Consider an undirected graph containing negative weight cycles.11 for values of k in the range from 1 to 8. Problem 5.3. The last vertex in a shortest path SP athk (j) is vertex yj before terminating at j. Apply the above Algorithm to the graph shown in Fig.1. Problem 5.9.2. Problem Set 5. j) + Distk (j)} .

1).196 Basics of Graph Algorithms a b a b d c d c Figure 5. The undirected graph is converted into a directed graph as shown in the right diagram. The Bucket Algorithm is simple because it is more abstract and ﬂexible.8. you would only ﬁnd some very speciﬁc techniques like the Breadth and Depth First Search traversal algorithms – more specialized and less ﬂexible than our Bucket Algorithm. Baase [2] uses JAVA to describe algorithms and this may be one reason why the book is relatively diﬃcult to read even if students have prior knowledge of the language. in most of the current textbooks. 5.9. move in a systematic manner to ensure that we do not miss out any vertex belonging to the same connected component [3].11: We show an un-directed graph (left diagram) with a negative weight cycle. Some of these cross edges come from vertices that en- . The objective was to highlight the basic idea and initially suppress the programming details.9.9.2 The Underlying Data Structure We know that we use a cross edge to discover a new vertex in the BucketAlgorithm (step 3).1 Traditional Techniques & the Bucket-Algorithm It is interesting to note that the Breadth as well as Depth First Searches are two diﬀerent implementations of the Bucket-Algorithm (Fig. While introducing this algorithm we purposely did not disclose the implementation details ignoring the underlying data structure required to program the algorithm. 5. 5. You might have noticed that the Bucket-Algorithm is essentially a graph traversal algorithm. Cormen [17] and Skiena [16] use a pseudo programming language and operate at a slightly higher level. However.

.9.1: Pictures of the Bucket B while performing a BFS (DFS) traversal in a graph starting from a vertex a shown in the top (bottom) diagram.Graph Traversal Techniques 197 j g h i k a d e BFS S DF j g h i k a d e BFS j g h i k a d e b c f c b f c b f j g h i k a d e b c DFS j g h i k a d e b e c f d g j i h k a b c f f Figure 5.

in the k th iteration of the BFS traversal. its BFS spanning tree is shown in the middle while a DFS spanning tree of this graph is shown in the right diagram.1. all vertices at a distance of exactly k edges from the starting vertex will be discovered.10. .1 below.10 Some Graph Theoretic Claims We make the following claims about the BFS traversal in an un-directed and connected graph G: Claim 5. In the ﬁrst iteration of the BFS traversal.9.10. BFS spanning tree of a graph G is a minimum distance spanning tree in terms of number of edges between the starting vertex and any other vertex in graph G. all vertices at a distance of one edge from the starting vertex are selected (or goes in the Bucket).198 Basics of Graph Algorithms tered the bucket earlier. others from vertices that are new comers in the bucket. Please see the Figure 5. j g h i k a d e b e c f d g h j i k a b e c f d g h j i k a b c f Figure 5. Using a Last in First Out (LIFO or a stack) or a First In First Out (FIFO or a queue) data structure to store the already discovered vertices would make all the diﬀerence: a stack implementation would convert the Bucket-Algorithm into a Depth First Search while a queue would transform it into a Breadth First Search.2. Claim 5. The non spanning tree edges are shown in pink color by thin lines. The way we decide which vertex to choose would convert the BucketAlgorithm into a Breadth First Search. 5.10. Depth First Search.2: A Graph G shown in the left diagram. or a combination of the two.

10. the middle diagram shows that vertices at a distance of two edges moves in the bucket in the 2nd iteration. . and so on.Some Graph Theoretic Claims 199 j g h i k a d e b e c f d g j i h k a b e c f d g j i h k a b c f a 0 a 0 f 1 a 0 f 1 k 1 g 2 2 b 1 k 1 f 1 b 1 b 1 k 1 g 2 2 d e 3 c 2 i 2 d c 2 i 2 3 3 j h Figure 5. The bottom left diagram shows that in the ﬁrst iteration of the BFS algorithm.1: Pictures of the Bucket B while performing a BFS traversal in a graph starting from a vertex a shown in the top diagrams. The distance of each vertex with respect to vertex a is indicated in red color along with each vertex in the bottom diagrams. vertices at a distance of one edge from vertex a goes in the bucket.

Please see Fig.3. these two paths along with edge j. If there is no edge in G other than the ones in the BFS spanning tree of G then G is a tree provided G is a connected graph. Please see Fig. The edge between vertex h and vertex j creates an odd cycle in the graph as both these vertices are at the same distance from vertex a. h makes a cycle.10. If there is an edge in G other than the ones in the BFS spanning tree of G then this edge will connect two vertices x and y in the BF S spanning tree such that Dist(x) − Dist(y) is either zero or one whereas Dist(x) is the distance of vertex x from the starting vertex in the BFS spanning tree.10. (Remember Dist(x) is the distance of vertex x from the starting vertex in the BFS spanning tree).200 Basics of Graph Algorithms Claim 5. If there is an edge in G other than the ones in the BFS spanning tree of G connecting vertex x and vertex y in the BFS spanning tree such that Dist(x) − Dist(y) is zero then there will be an odd cycle in graph G. It will be an odd cycle as vertices h and j are at the same distance from vertex a.10. 5. Claim 5.10.10.5.2: BFS spanning tree of a graph G is shown. We also know a path between vertex j and vertex a. we also know a path between vertex h and vertex a as shown in green color in the top right diagram.6. If there is an edge in G other than the ones in the BFS spanning tree of G connecting vertex x and vertex y in the BFS spanning . j g h k f d e a b h c g 2 2 3 a 0 i f 1 b 1 k 1 d e 3 c 2 i 2 3 j Figure 5. Claim 5.4. 5.2. As we know the distance of vertex h from vertex a.10.2 Claim 5.10.

Please see Fig.3: BFS spanning tree of a graph G. If a graph G is a tree then there will be a unique path between every pair of vertices of G.10. 5.10. The edge between vertex h and vertex i creates an even cycle in the graph G as vertex h is at a distance one larger than the distance of i from a. (Remember Dist(x) is the distance of vertex x from the starting vertex in the BFS spanning tree). When we grow a BFS spanning tree in a Bucket starting from a given vertex.Some Graph Theoretic Claims 201 tree such that Dist(x) − Dist(y) is one then there will be an even cycle in graph G. If every edge of G connects a vertex x to vertex y in the BFS spanning tree of G such that Dist(x)−Dist(y) is exactly equal to 1 then graph G is a bipartite graph. Please see the Fig. Similarly if there is a unique path between every pair if vertices in a connected graph G then G is a tree.10. Similarly if there is an edge of G connecting vertex x to vertex y in the BFS spanning tree of G such that Dist(x) − Dist(y) is exactly equal to 0 then graph G is not a bipartite graph. A graph G is bipartite if and only if it does not contain any odd cycles. Claim 5. Claim 5.10. 0 j g h k f d e a b 3 a i f 1 b 1 k 1 c g 2 2 d e 3 c 2 i 2 3 j h Figure 5.9.8. Claim 5. 5. the given vertex goes in the bucket ﬁrst.4 below.10.10.10.7.10. In the ﬁrst . Claim 5.3 below.

.4: BFS spanning tree of a graph G which is a bipartite graph is shown in the top diagrams.10.202 Basics of Graph Algorithms j g h k f d e a b 3 a 0 i f 1 b 1 f a k 1 d c 2 i 2 g c 3 j b k e h c g 2 2 d e 3 h i j f a 0 j g h k f d e a b h c g 2 2 3 i f 1 b 1 a k 1 d g c e 3 3 j b k e h d c 2 i 2 i j Figure 5. BFS spanning tree of another graph G which is a not bipartite is shown in the bottom diagrams.

If G is a connected graph and if the number of edges is one less than the number of vertices in G then G is a tree. Please see the Fig. one more vertex and an edge go in Bucket. At any point in time there will be k vertices and k − 1 edges in the Bucket.10.10. we discover a new vertex because of an edge going out of the Bucket.11.5: We show the contents of the Bucket at diﬀerent times while we make a BFS traversal of a graph.Some Graph Theoretic Claims 203 iteration of this algorithm. j g h k f a b e No spanning edge & One vertex in the Bucket j i g h k f a b e One spanning edge & Two vertices in the Bucket j i g h k f a b i c c c d e d d Two spanning edges & 3 vertices in the Bucket j g h k f a b e f c d i g j i h k a b e 4 spanning edges & five vertices in the Bucket j g h k f a b i c c d e d 3 spanning edges & four vertices in the Bucket 10 spanning edges & 11 vertices in the Bucket Figure 5. .10. Claim 5. Initially there will be only one vertex and no spanning edge as shown in the top left corner. 5.5. Finally there will be 10 spanning edges and 11 vertices in the Bucket.

The interesting thing about this style of design is that we shall be using a single building block (sometimes the Bucket Algorithm and some times a 2-edge Shortest path Algorithm) to design or describe an algorithm. Design of a shortest path algorithm for directed acyclic graphs with negative as well positive edge weights. Modifying the Bucket algorithm to ﬁnd a minimum spanning tree (MST). We intend to do the following in this section: 1. Design of all pair shortest path algorithms including the slow all pair. 4.204 Basics of Graph Algorithms Claim 5. 2. If G is acyclic & number of edges in G is one less than the number of vertices then G is a tree. 2. Finding k-edge shortest or longest paths in a weighted graph. 3. On the basis of that precious prior knowledge we can design interesting shortest path algorithms.11 Shortest Path Algorithms We have already done the following in earlier sections of this chapter. faster all pair.10. We shall further modify the Bucket algorithm to achieve our objectives. Here we assume that there may be negative edge weights in the given weighted directed graph. Floyd-Warshall and Johnsons shortest path algorithms. We shall again modify the Bucket algorithm to achieve our objective. 5. 1.12. This is about single source shortest path algorithms assuming that all edge weights are positive in the given weighted graph. Modifying the Bucket algorithm to ﬁnd a shortest path spanning tree (SST) or shortest distances in a weighted graph from a given vertex. 3. Analyze the existing minimum spanning tree & shortest path ﬁnding algorithms and improve their eﬃciency as far as possible. Design of single source shortest path algorithms based on our prior knowledge of ﬁnding k-edge shortest paths from a given vertex. We also assume that the directed graph may have cycles. .

. We apply the shortest path algorithm and ﬁnd the shortest distances from vertex a in this graph where a = 1 also shown in Fig. Dist(k) = Dist(j) + w(j. 5.1. Food for thought: The graph shown in Fig.Shortest Path Algorithms 205 5. 5. and Dist(k) of every other vertex k from vertex a equal to ∞. k) in SST .1 has negative edge weights.11.11. We shall study this algorithm using diﬀerent tools before improving its time complexity. Put edge (j. Put vertex k in B. The visual tool demonstrates at what stage and when a vertex enters the Bucket while the shortest path algorithm moves forward.11. while there are edges coming out of the Bucket B do Select the edge for which Dist(j) + w(j. As soon as a vertex enters the bucket its color changes from blue to orange and then its distance from the start vertex cannot change . The shortest distances from vertex 1 as found by this algorithm are also indicated in the bottom diagram. a vertex a output: Shortest distance Dist(k) of every vertex k from vertex a 1 2 3 4 5 Put vertex a in Bucket B.it is ﬁxed and ﬁnalized.1. k).11. 5. Initialize Dist(a) = 0. We have already witenessed that this algorithm does not always provide correct results for graphs with negative weight edges. That is why the shortest paths found by the crude Dijkstra’s algorithm are not correct.1 Single Source Shortest Path Algorithms with positive edge weights We copy here the modiﬁed Bucket algorithm designed in the last section to ﬁnd shortest paths from a given start vertex. But we also know that this very algorithm provides correct results when all edge weights are positive. We introduce a visual tool known as ”opening up the graph” as shown in Fig. Algorithm 24: (Crude-Dijkstra): Find shortest distance of every vertex from a given vertex a in G & also the shortest path spanning tree (SST ) of G from vertex a input : A weighted Graph G. k) is minimum where vertex j is in B and vertex k is outside the Bucket.

It shows at what stage (edge distance) a vertex enters the Bucket while executing crude shortest path algorithm. .1: We use a new tool ”Opening up the graph” as shown here. It also shows how and when the distance of a vertex changes from the start vertex.it is ﬁxed and ﬁnalized.206 Basics of Graph Algorithms Figure 5. As soon as a vertex enters the bucket its color changes from blue to orange and then its distance from the start vertex cannot change .11.

The outcome of this step is that the number of edges (which really matters) coming out of the bucket B from vertex a is limited by p and not p2 . Its time complexity is too high. Surprisingly this can be done with a slight modiﬁcation in the crude algorithm as shown below. 5.2: The number of edges coming out of the Bucket B at any time will be proportional to p2 under worst case conditions. Somehow we should reduce the number of relevant edges coming out of the Bucket to as small as p .11. Now we consider the edges coming out of the Bucket from (only) vertex a instead of edges coming out of the Bucket from all vertices in the Bucket. however. The number of edges coming out of the Bucket B at any time is proportional to p2 as illustrated in Fig.3. It is interesting to note how the shortest distances are provided in the output in this new algorithm.this will automatically cut down the time complexity of this single source shortest path algorithm to p2 . As this loop runs as many times as p so the overall time complexity will be p3 of this algorithm. What we essentially do is to change the graph itself at each step as shown in Fig.Shortest Path Algorithms 207 Figure 5.2. Although it provides correct results for positive edge weights. It does not provide correct results for negative edge weights. This requires as many comparison steps to move forward in the while loop. 2. The shortest paths.11. 5. In fact there are two complications with this algorithm: 1. The issue of negative edge weights will be handled in the next sub-section. We shall reduce the time complexity in the following reﬁned version of shortest path algorithm.11. could not be found .

The reﬁned version of that algorithm is given below . . w(a. a vertex a output: Modiﬁed adjacency matrix of graph G in which the row corresponding to vertex a gives shortest distances of every vertex from vertex a. It is important to note that we may be able to make similar modiﬁcations in the crude minimum spanning tree algorithm to make it more eﬃcient.208 Basics of Graph Algorithms Algorithm 25: (Reﬁned-Dijkstra):Find shortest distance of every vertex from a given vertex a in weighted graph G input : A weighted Graph G. k). j) + w(j. k) without an extra eﬀort using this reﬁned algorithm. k) We can recover shortest paths by adding a parent table as shown in Fig. k). while there are edges coming out of the Bucket B from vertex a do Select the edge for which w(a. Put vertex j in B. 1 2 3 4 5 Put vertex a in Bucket B while there are edges coming out of the Bucket B from vertex a do Select the edge for which w(a. w(j. Again it will be interesting to understand that this algorithm will provide the weight of the minimum spanning tree of a weighted graph . Algorithm 26: Find weight of MST of a weighted graph G input : Adjacency matrix of a weighted Graph G output: Modiﬁed adjacency matrix of graph G in which the row corresponding to vertex a gives weight of MST 1 2 3 4 5 6 Put any vertex a in Bucket B. k)} to w(a. j) is minimum where vertex j is outside the Bucket B.not the minimum spanning tree itself as shown in the diagrams below. for every edge coming out of B from vertex j do assign min{w(a. Put vertex j in B for every edge coming out of B from vertex j do assign min{w(a. j) is minimum where vertex j is outside the Bucket B.its time complexity also reduces from O(p3 ) to O(p2 ). k)} to w(a.

.3: We modify the graph as we move forward in the shortest path algorithm.k) = min{w(a.k)} j 3 g k 3 2 6 a f 2 d 1 e 5 3 1 3 5 2 2 b e 4 h 3 c 6 7 3 4 c f 2 d 1 5 3 1 i 3 k 3 6 3 5 a 2 2 b g 2 4 h 6 7 3 4 c j 3 i 3 k 4 2 b Figure 5.11.Shortest Path Algorithms 209 j 3 g 2 3 f 2 1 e 3 a 2 d 3 1 2 b e 4 h 6 9 i 3 k 3 c f 2 d 1 3 3 5 g 2 4 j 3 i 6 9 a 2 2 3 1 b e 4 3 k 3 c f 2 d 1 3 6 3 5 g 4 2 j 3 i 6 9 a 2 2 3 1 b 4 3 k 3 c h h ut sb ce s tan path is t d test r es o rt h o sh he s the of t d fin rack We se t lo j 3 g 2 6 a f 2 d 1 e 5 3 1 3 5 2 4 h 3 6 7 i 3 w(a. j)+w(j. w(a.k).

We have provided a hint in the same ﬁgure. 5.11.11.11. You can yourself make suitable modiﬁcations in the algorithm according to these modiﬁcations.7 determining the actual shortest paths in a directed graph is an interesting problem. See how by increasing memory or space requirements we can reduce the time complexity of an algorithm. 5.2 Single Source Shortest Path Algorithms for Directed Acyclic Graphs We know that by deﬁnition a directed acyclic graph contains no cycles. 5.11. If we can recover shortest paths then we should also be able to recover a minimum spanning tree using the reﬁned minimum spanning tree algorithm. We can even solve the Hamiltonian Path problem in this very restricted class .11.6 & 5.4: We modify the graph as we move forward in the minimum spanning tree algorithm.210 Basics of Graph Algorithms Figure 5. Food for thought: Given a parent table and shortest distances as shown in Fig.7. We can ﬁnd shortest paths in such graphs in the presence of negative edge weights and we can also ﬁnd longest paths in the presence of positive edge weights.

Weight of the minimum spanning tree is indicated in the bottom right graph.Shortest Path Algorithms 211 Figure 5. Shortest distances with respect to vertex a are indicated in the bottom left graph. Please note that the shortest paths and minimum spanning tree are not easily available here.5: The original graph is shown in the top diagram. .11.

11.7: How to recover shortest paths with the help of a parent table? .212 Basics of Graph Algorithms Figure 5.6: We need to add a parent table array in order to ﬁnd shortest paths in addition to shortest distances. Figure 5.11.

9. The Bucket Algorithm (described earlier) can easily be modiﬁed to create an algorithm which can ﬁnd shortest paths from any given vertex in a very eﬃcient manner. If we need to ﬁnd shortest paths from a source vertex a then we should put that vertex in the bucket ﬁrst. In both these algorithms we made certain comparisons to select the next entrant into the bucket. So coming back to the important question: which vertex (and on what basis) . In the bottom diagram we arrange its vertices such that all edges move from left to right. The crucial question is which will be the next vertex to go in the bucket and on what basis. Recall how we select the next candidate vertex which enters into the bucket in case of Dijkstra like algorithm or in case of Prim’s like algorithm. 5.it will also decide its time complexity. This observation is explained in detail in Chapter 8 while discussing directed acyclic graphs.11.11.Shortest Path Algorithms 213 of graphs. An answer to this question will not only determine the character of this algorithm . Please see the concept map in Fig. The intuition of this algorithm comes from the observation that we can always arrange the vertices of a DAG such that all edges in the DAG move from left to right as shown in the ﬁgure below.8: A directed acyclic graph D shown in the top diagram. Figure 5. The numbers inside each vertex is the start time and ﬁnish times obtained during a depth ﬁrst search of the directed graph.

10. The corresponding algorithm is described below. . It will be an interesting challenge to derive the time complexity of this elegant shortest path algorithm.11. should enter the bucket after putting the start vertex in the bucket? The interesting observation is that after arranging vertices of a DAG (such that all edges move from left to right) the next vertex to enter the bucket has already been decided. 5. We need no comparisons or extra steps to make this decision. Its working is shown in Fig.214 Basics of Graph Algorithms Figure 5. It is the next left vertex in the new arrangement of the vertices of the graph.11.9: A concept map depicting which vertex should next enter the bucket in diﬀerent algorithms.

Shortest Path Algorithms 215 Algorithm 27: Find shortest distance of every vertex from a given vertex a in a directed acyclic graph D input : A directed acyclic and weighted Graph D. We need to ﬁnd shortest paths from vertex a in this graph. j) + w(j. w(a. k)} to w(a.11. The graph is already drawn such that all edges are going from left to right.10. The next vertex which goes in the bucket is vertex b in spite of the fact that the edge joining vertex a with vertex b is the heaviest edge in this graph. 11. Do you think Dijkstra’s like algorithm will also ﬁnd correct shortest paths in a DAG? And at what cost? 2. Put vertex j in B for every edge coming out of B from vertex j do assign min{w(a. k) Food for Thought 1. k). Can we still apply this algorithm without any modiﬁcation to ﬁnd shortest paths? How about if we need to ﬁnd shortest paths from a vertex other than the source vertex in a DAG? 3. Consider the directed acyclic graph shown in Fig. . How about if we need to ﬁnd longest paths instead of shortest paths from a given vertex in this or any other directed acyclic graph? Which vertex will next end up in the bucket? What changes are needed in this algorithm to ﬁnd longest paths? Please see ﬁgure 5.11. a vertex a output: Modiﬁed graph D in which the weighted edges coming out of vertex a provides shortest distances from this vertex. If we had applied Dijkstra’s algorithm to this graph then it would have selected vertex c (instead of vertex b) as the edge joining vertex a with vertex c having the minimum weight. How about if there are negative weight edges in the graph? Would this algorithm still provide correct results? 4. Assume that we have a DAG with multiple source vertices. 1 2 3 4 5 6 Arrange vertices of the DAG such that all edges move from left to right Put given vertex a in Bucket B while there is an edge going out of the Bucket B do Select the next right vertex j.

Weight of every edge not indicated in the diagram is equal to 1. .10: We need to ﬁnd shortest distances from vertex a in this graph. Now the next vertex to move in the bucket will always be the next left vertex. The vertices of the DAG have been arranged such that all edges move from left to right.216 Basics of Graph Algorithms 5.11. Can we use a similar algorithm to ﬁnd a Hamiltonian Path in a directed acyclic graph provided it exists? Figure 5.

.11: We need to ﬁnd longest distances from vertex a. Weight of every edge not indicated in the diagram is equal to 1. Now the next vertex to move in the bucket will always be the next left vertex.11. The vertices of the DAG have been arranged such that all edges move from left to right.Shortest Path Algorithms 217 Figure 5.

We assume that all distances are to be measured and minimized with respect to a start vertex a. Remember we have already reduced the time complexity of our modiﬁed shortest path algorithm from p3 to p2 . k) + Disti (j)} A 2-edge shortest path algorithm Let us make this building block consistent with our earlier policy of modifying the graph as we move forward in the algorithm. In this building block we just convert the one edge distances into 2-edge shortest distances as given in the following algorithm.11. We shall follow this terminology throughout this section. That was Dijkstra’s like algorithm which can handle positive edge weights in a graph with cycles but does not provide us with correct results if there are negative edge weights in the graph. It has been copied below. Here w(a. i-edge shortest distance of every vertex k from vertex a denoted by Disti (k) output: (i + 1)-edge Shortest distance of vertex k from vertex a. a vertex a. w(j.3 Single Source Shortest Path Algorithms for directed graphs with negative edge weights We have discussed directed acyclic graphs and the ease with which we can ﬁnd shortest paths in such graphs in the last section. If a graph is cyclic then we cannot use the simplicity and elegance of this algorithm. Let us recall the (i + 1)-edge shortest path algorithm described earlier in this chapter.218 Basics of Graph Algorithms 5. Algorithm 28: (Bellman-Ford Building Block-A): Find (i + 1)-edge shortest distance of every vertex k from a given vertex a in a weighted directed graph G. This will make it friendlier to use as a building block. The terminating vertex is k and the intermediate vertex is indicated by vertex j. input : A weighted directed Graph G. it is denoted by Disti+1 (k) 1 2 3 for each (terminating) vertex k do for each (intermediate) vertex j do Disti+1 (k) = min{Disti (k). Now is the time to get rid of the bucket as it is hindering our way to handle negative edge weights. k) represents the initial one edge path of vertex k from . Then we need to revert back to algorithms discussed earlier.

a vertex a. input : A weighted directed Graph G. j) + w(j. k). k)} Algorithm 29: (Bellman-Ford Building Block-B): Find 2-edge shortest distance of every vertex k from a given vertex a in a weighted directed graph G. and assign min{w(a. w(a. k) = min{w(a. k). k) from vertex a to vertex k will then be given by the following recursive equation: (5. w(a. k)} to w(a.Shortest Path Algorithms 219 vertex a. The 2-edge shortest distance w(a.1) w(a. 1-edge shortest distance of every vertex k from vertex a provided by the row corresponding to vertex a in the adjacency matrix G output: Modiﬁed graph G in which row corresponding to vertex a provides 2-edge shortest distance of every vertex k from vertex a 1 2 3 for each (terminating) vertex k of graph G do for each (intermediate) vertex j of graph G do Find a 2-edge path from vertex a to k passing through j. j) + w(j. k) .

k)} .11. Here a = 1. 5. w(a.w(a.220 0 1 ∞ 2 ∞ 3 ∞ 4 ∞ 5 ∞ 6 Basics of Graph Algorithms ∞ 7 0-edge apart 1-edge apart 1 2 1 3 4 5 1 6 7 1 2-edge apart 1 2 3 4 5 6 7 1 1 7 2 2 ∞ 1 1 3 1 1 0 2 0 2 2 7 1 6 4 3 6 3 2 4 3 5 4 Input Graph 4 5 ∞ 1 2-edge Shortest paths? Figure 5.j)+w(j.k)=min{w(a. Edge weights not shown are equal to 1.12).12: Execution of the 2-edge shortest path algorithm from start vertex a. Please see the accompanying ﬁgure (Fig.11. We vary j and k for the entire vertex range and ﬁnd the 2-edge shortest distances of every vertex from vertex a. The 2-edge shortest distances are indicated in the modiﬁed graph shown in the bottom right corner.k).

Here intermediate vertex j is ﬁxed at 4 and the destination vertex k is varied ﬁrst.13).it also becomes a powerful tool for the algorithm designer (Fig. .11. 5. The end result remains the same. This switching of two loops is an exciting idea in the development of shortest path algorithms . Please note that it is immaterial whether you execute the j-loop ﬁrst and the k-loop later or vice versa.11.Shortest Path Algorithms 221 Figure 5.13: We execute the k-loop ﬁrst and then the j-loop in the 2-edge shortest path algorithm.

222 Basics of Graph Algorithms Figure 5.11. k).14. A recursion tree corresponding to the equation w(a. A vertex (13) in the bottom row of the recursion tree corresponds to one edge distance of vertex 3 from vertex 1 in original graph. As you can understand this 2-edge shortest path algorithm becomes a building block for so many shortest path algorithms. w(a. While vertex (13) in the top row of the recursion tree corresponds to the two edge shortest distance from vertex 1 to vertex 3 in the original graph. 5. j) + w(j. Please note that the number of edges in the recursion tree is exactly equal to the number of steps performed by the algorithm. . k) = min{w(a. The Recursion Tree We illustrate the 2-edge shortest path algorithm by one additional tool known as the recursion tree (although strictly speaking it is a DAG) as shown in Fig. The number of edges in the recursion tree corresponds exactly to the number of steps performed by the two edge shortest distance algorithm.14: Execution of the 2-edge shortest path algorithm is illustrated. k)} is also shown in the bottom diagram.11.

and assign min{w(a. k) This algorithm resembles the so called Bellman-Ford algorithm with a time complexity of p3 as we have three nested for loops. k).Shortest Path Algorithms Bellman-Ford like Shortest Path Algorithm 223 In order to ﬁnd a shortest distance in a weighted graph with negative edge weights we just have to run the 2-edge shortest path building block suﬃcient number of times as shown in the following algorithm. The outer most loop in the Bellman-Ford Algorithm (known as Algorithm 30) is represented by blue color in Fig. k) := min{w(a. Algorithm 29 has two f or loops. w(a. This outer loop executes Algorithm 29 p − 1 number of times and minimizes the value of w(a.15. See without this blue box the remaining two boxes (brown and orange) represents the 2-edge shortest path algorithm known as Algorithm 29. j) + w(j. k) according the following equation: w(a. k)}. k). w(a. The Colored Puzzle The colored puzzle highlights the fact that Algorithm 29 can be used to become a building block for Bellmam-Ford Algorithm. j) + w(j. 5. Please note that the nesting of f or loops in these algorithm can be nicely . One is the terminating vertex k loop represented by brown color in the colored puzzle. Algorithm 30: (Bellman-Ford1): Find shortest distance of every vertex k from a given vertex a in G input : Adjacency matrix of weighted Graph G and a start vertex a output: Modiﬁed adjacency matrix G in which row corresponding to vertex a provides shortest distance of every vertex k from vertex a in G 1 2 3 4 for i=1 to p-1 do for each (intermediate) vertex j of graph G do for each (terminating) vertex k of graph G do Find a two edge path from vertex a to vertex k in G passing through an intermediate vertex j.11. k)} to w(a. Fig. Here we introduce another tool to study an algorithm. The other is the intermediate vertex j loop represented by orange color in the puzzle.

It is possible to run the intermediate vertex j-loop (orange color) ﬁrst and then the destination vertex k-loop (brown color) or vice versa.15: A colored puzzle depicting the positioning of the diﬀerent for loops in the shortest distance ﬁnding algorithm. The positioning of the j and k loops in the Bellman-Ford Algorithm can be interchanged without aﬀecting the outcome of this algorithm as shown in Fig.16 along with the corresponding colored puzzles.15. 5. It is interesting to note that each such algorithm appears in pairs . The outer most loop in the algorithm is represented by blue color. for i =1 to p-1 for each vertex k for each vertex j for i =1 to p-1 for each vertex j for each vertex k Figure 5.11.11.thanks to the colored puzzle which provokes a learner to note this interesting property. cannot be changed without adversely aﬀecting the performance of the algorithm. Other shortest path algorithms can also be represented by this puzzle with the addition of the start vertex a loop shown by green color in coming ﬁgures. The recursion tree corresponding to the Bellman-Ford Algorithm is shown in Fig. The position of the blue loop. however. .224 Basics of Graph Algorithms captured by nested colored boxes in the colored puzzle. 5.11.

It is also possible to rephrase this algorithm so that we do not need any .16: The recursion tree corresponding to Bellman-Ford like algorithm.Shortest Path Algorithms 225 Figure 5. Time Complexity of Bellman-Ford shortest path algorithm We have witnessed that the time complexity of Bellman-Ford1 shortest path algorithm is O(p3 ) with an adjacency matrix data structure.11.which is equal to p3 . The complexity of algorithm is equal to the number of edges in this recursion tree . The colored puzzle corresponding to this algorithm is again shown in the bottom diagram. How about a sparse graph and if we represent it using an adjacency list representation? It may be a good idea to see if the time complexity can be reduced to at least O(pq) which will be less than O(p3 ) for a suﬃciently sparse graph.

k) = 3 k j w(j. k).k) = 1 k New Dist(k) = 6 New Dist(k) = 5 Figure 5. Dist(j) + w(j.11. Distance Dist(a) of vertex a from itself is zero and from any other vertex it is inﬁnite. k)} Dist(k) = min{ Dist(k).k) k a Dist(k) = 6 Dist(j) = 4 j w(j. k) in graph D do Dist(k) = min{Dist(k). output: Distance array Dist(k) storing minimum distances of every vertex k from vertex a. The rephrased algorithm is shown below.17: How and when the (shortest) distance Dist(k). 1 2 3 for i=1 to p-1 do for every directed edge (j.226 Basics of Graph Algorithms extra intelligence (in its implementation) to make it a O(pq) algorithm. with respect to vertex a changes when we consider the directed edge (j. In this version of Bellman-Ford the time complexity will always be pq with an adjacency list data structure and without an extra intelligence in its implementation. Line 3 is the basic building block of this algorithm. . Algorithm 31: (Bellman-Ford2): Find shortest distance of every vertex k from a given vertex a in G input : Directed and weighted graph D. Dist(j) + w(j. k)} a Dist(k) Dist(j) j a Dist(k) = 6 Dist(j) = 4 w(j. Its working is explained in the ﬁgure below.

Shortest Path Algorithms

227

5.11.4

All Pair Shortest Path Algorithms

We shall describe now three all pair shortest path algorithms. They will all use a single building block which is the 2-edge shortest path algorithm described earlier. The slow all pair shortest path algorithm has a O(p4 ) complexity, faster all pair shortest path algorithm has a O(p3 log2 p) complexity while Floyd-Warshall all pair shortest path algorithm has O(p3 ) time complexity under worst case conditions. The Slow All Pair shortest Path Algorithm The Bellman-Ford like algorithm ﬁnds shortest distances from a ﬁxed start vertex in a graph. If we run this algorithm for every vertex in the graph then we end up with the so called slow all pair shortest path algorithm with a time complexity of O(p4 ). This algorithm is depicted pictorially by the colored puzzle shown in the left diagram of the ﬁgure below. Algorithm 32: Slow All Pair: Find shortest distance of every vertex from every vertex in G input : Adjacency matrix of weighted Graph G output: Shortest distance of every vertex from every vertex in G

1 2 3 4 5

for each (start) vertex a of graph G do for i=1 to p-1 do for each (intermediate) vertex j of graph G do for each (terminating) vertex k of graph G do Find a two edge path from vertex a to vertex k in G passing through an intermediate vertex j, and assign min{w(a, k), w(a, j) + w(j, k)} to w(a, k)

The Faster All Pair shortest Path Algorithm It is interesting to note that if we switch the blue p-loop with the green a-loop in the colored puzzle as shown in the diagram below then we end up with another all pair shortest path algorithm, known as faster all pair shortest path algorithm. It will be interesting to derive its time complexity and compare it with that of slow all pair shortest path algorithm. The working of this algorithm is shown in the diagram below.

228

Basics of Graph Algorithms

for each vertex a for i =1 to p-1 for each vertex j for each vertex k

for i =1 to p-1 for each vertex a for each vertex j for each vertex k

w(a,k) = min{w(a,k), w(a, j)+w(j, k)}

Figure 5.11.18: The start vertex loop is represented by green color. The intermediate vertex j loop is represented by orange color and the terminating vertex k loop is represented by brown color. There is another p-loop - it is represented by blue color. The diagram shows the eﬀect of switching between the blue and the green loops. The left diagram depicts the slow all pair shortest path algorithm while the right diagram represents the faster all pair shortest path algorithm.

Algorithm 33: Faster All Pair: Find shortest distance of every vertex from every vertex in G input : Adjacency matrix of weighted Graph G output: Shortest distance of every vertex from every vertex in G

1 2 3 4 5

for i=1 to p-1 do for each (start) vertex a of graph G do for each (intermediate) vertex j of graph G do for each (terminating) vertex k of graph G do Find a two edge path from vertex a to vertex k in G passing through an intermediate vertex j, and assign min{w(a, k), w(a, j) + w(j, k)} to w(a, k)

Shortest Path Algorithms

229

Figure 5.11.19: Working of the faster all pair shortest path algorithm is shown. Please note that from two edge all pair shortest distances we jump to 4-edge and then to 8-edge shortest distances.

230

Basics of Graph Algorithms

Figure 5.11.20: The recursion tree and the colored puzzle corresponding to faster all pair shortest path algorithm. Here it is also obvious that from 2-edge shortest distances we directly jump to 4-edge shortest distances.

Shortest Path Algorithms Food for thought

231

1. Is the time complexity of this algorithm any better than that of slow all pair shortest path algorithm? If yes then why? 2. You may have noticed that in this algorithm (FAster All Pair) the number of edges in shortest paths jumps in the powers of 2 as shown in Figure 5.11.20. What does that mean? The outer most loop (the blue colored loop in the colored puzzle) should run from 1 to p or from 1 to log2 p? How will it aﬀect the time complexity of this so called faster all pair shortest path algorithm. 3. In the slow all pair shortest path algorithm the blue loop should run from 1 to p and not from 1 to log2 p? Why? All Pair (Floyd-Warshall) Shortest Path Algorithm Consider the faster all pair shortest path algorithm. We know it can be represented by the colored puzzle as shown in Fig. 5.11.21. The recursive equation used as a building block is also indicated in this ﬁgure. There are essentially four for loops in this algorithm represented by four nested rectangles in the multi colored puzzle. If the intermediate vertex j loop (also known as the orange loop in the colored puzzle) becomes the outermost loop while the source vertex a loop (green) and destination vertex k loop (brown) are inner loops (in any order) then (surprisingly) we end up with one of the most eﬃcient all pair shortest path algorithms as shown in Fig. 5.11.22. Please note that now we have only three loops and there is in fact no need to have the fourth loop - the so called blue loop in the colored puzzle. The time complexity will now be O(p3 ) as there are only three loops. Its time complexity is as good (or as bad) as that of Bellman-Ford algorithm (which is a single source shortest path algorithm) for non sparse graphs. The basic building block of this algorithm is the same recursive equation that we used in other algorithms. See Fig. 5.11.22 & 5.11.23.

232

Basics of Graph Algorithms

w(a,k) = min{w(a,k), w(a, j)+w(j, k)}

for i =1 to log2p for each vertex a for each vertex j for each vertex k for i =1 to log2p for each vertex a for each vertex k for each vertex j

Figure 5.11.21: The colored puzzles corresponding to faster all pair shortest path algorithm.

Algorithm 34: (Floyd-Warshall): Find shortest distance of every vertex from every vertex in G input : Adjacency matrix of weighted Graph G output: Shortest distance of every vertex from every vertex in G

1 2 3 4

for each (intermediate) vertex j of graph G do for each (start) vertex a of graph G do for each (terminating) vertex k of graph G do Find a two edge path from vertex a to vertex k in G passing through an intermediate vertex j, and assign min{w(a, k), w(a, j) + w(j, k)} to w(a, k)

**Shortest Path Algorithms
**

for i =1 to for each vertex j p-1 for each vertex k for each vertex a for each vertex j for each vertex a for each vertex k

233

Figure 5.11.22: We show the possibility of having the intermediate vertex j loop become the outer most loop. There is no fourth loop in this diagram and surprisingly there is no need for it. Once the j-loop becomes the outer most loop then it does not matter if the order of the green loop and that of the brown loop is interchanged. Food for Thought: What is the trick or intuition behind this algorithm? Is this not surprising that without a fourth loop we can design an all pair shortest path algorithm? A spectrum of single source and all pair shortest path algorithms We show a spectrum of shortest path algorithms in Fig. 5.11.24. We also show connections or links between diﬀerent algorithms. Note that the Bucket algorithm is the ancestor of most of these algorithms. This panorama of shortest path algorithms is also depicted by the colored puzzle shown in Fig. 5.11.25. Please appreciate the fact that for the entire galaxy of such algorithms we use a single building block - the 2-edge shortest path algorithm.

5.11.5

Johnson’s all Pair Shortest Path Algorithm

We have studied in the last section that all pair shortest path algorithm (Floyd-Warshall) has a worst case time complexity of O(p3 ). This is the best performance seen so far for an all pair shortest path algorithm. In this subsection we shall study another all pair shortest path algorithm which works faster than O(p3 ) for graphs which are suﬃciently sparse. Required Prior Knowledge: First we shall talk about the prior knowledge required to understand this

234

Basics of Graph Algorithms

Figure 5.11.23: The recursion tree corresponding to Floyd-Warshall all pair shortest path algorithm. The number of edges in the recursion tree is equal to the number of steps performed by the said algorithm - and this is equal to O(p3 ).

Shortest Path Algorithms

235

Figure 5.11.24: We show a concept map of various single source and all pair shortest path algorithms.

236

Basics of Graph Algorithms

w(a,k) = min{w(a,k), w(a, j)+w(j, k)}

2-edge shortest path algorithm

Bellman-Ford (single source)

Slow All Pair

Faster All Pair

Floyd-Warshall (all pair)

Figure 5.11.25: We show the galaxy of single pair and all pair shortest path algorithms. Each algorithm can be represented by a diﬀerent color arrangement in the rectangular puzzle. It is interesting to note that each shortest path algorithm has at least one dual with the same performance and output.

Figure 5.11.26: It will be interesting to see if any of these colored arrangements represents one of the already discussed shortest path algorithms.

We know that Bellman-Ford algorithm can ﬁnd shortest paths from a single source vertex in time O(p3 ) even if there are negative edge weights in a directed graph. The time complexity of this algorithm is O(pq) provided we use an adjacency list as a data structure to represent the input graph. We know that Dijkstra’s shortest path algorithm ﬁnds correct shortest paths from a single vertex provided all edge weights are positive. If we convert this O(pq) Bellman-Ford algorithm into an all pair shortest path algorithm then its time complexity would become O(p2 q) which is worse than O(p3 ) for Floyd-Warshall. If that becomes clear then it is almost trivial to appreciate the innovation behind this algorithm. We also know that its time complexity is O(p2 ) if we use an adjacency matrix as a data structure. Its time complexity can be improved with an adjacency list data structure provided we use a minimum heap to locate the next vertex which goes in the bucket. 2. If all edge weights are positive then we can apply Dijkstra’s algorithm p times to ﬁnd all pair shortest paths in O(p2 logp + pq). This time complexity is better than O(p3 ) (Floyd-Warshall) in suﬃciently spare graphs.Shortest Path Algorithms 237 algorithm. Once all edge weights are made positive we can use . It is interesting to note that this is not entirely a new algorithm . 1.it innovatively combines two shortest path algorithms (Dijkstra + Bellman-Ford) and creates an all pair shortest path algorithm such that the overall time complexity becomes better than that of best known shortest path algorithm . This can further be improved to O(plogp + q) if we use a Fibonacci heap to implement the minimum priority queue. But if there are negative edge weights then we shall get incorrect results.Floyd-Warshall (p3 ) under certain conditions. Again this is an improvement over O(p3 ) provided we have a suﬃciently sparse graph. If there are no negative cycles then this algorithm somehow uses results of Bellman-Ford algorithm to convert negative edge weights into positive without disturbing the relative path lengths. So we need to do something more? Something very innovative? Johnsons’Algorithm = Bellman-Ford + Innovation + Dijkstra Johnson’s algorithm ﬁrst uses Bellman-Ford to check if there are any negative weight cycles. The improved time complexity is O(qlogp). This requires time proportional to pq.

All distances are measured with respect to vertex a.28. k)}. Algorithm 35: Find shortest distances of every vertex k from vertex a in D input : Directed and weighted graph D. We initialize Dist(a) = 0 and set Dist(x) of every other vertex x from vertex a equal to inﬁnity. output: Distance array Dist(k) storing minimum distances of every vertex k from vertex a. If it does not then there are no negative cycles reachable from vertex a in the directed graph. Consider the Bellman-Ford algorithm described earlier and reproduced here.11. Dist(j) + w(j. Food for Thought 1. k) in the graph D do Dist(k) = min{Dist(k). Please see Fig. Distance Dist(a) of vertex a from itself is zero. Under such conditions this algorithm should at least inform us that in the given graph there are negative weight cycles. We then run this loop one more time to check if any distance changes. What modiﬁcation is needed in this algorithm for this extra intelligence? The required modiﬁcation is simple and elegant? We run the outer most loop p − 1 times and store distance of each vertex x from the start vertex a. How about if the distance of no vertex changes after an initial iteration i when i < p − 1.238 Basics of Graph Algorithms the improved Dijkstra’s algorithm to ﬁnd all pair shortest paths in time O(p2 logp + pq). 5. 1 2 3 for i = 1 to p − 1 do for every directed edge (j.11.27 . 5. . If there are negative weight cycles then complications arise as already discussed. Does that mean there are no negative weight cycles and should we stop without further iterating? See Fig. Checking Negative Weight Cycles in a directed graph: The above algorithm ﬁnds shortest paths correctly in case there are no negative weight cycles in the directed graph. If it does then it means we have negative weight cycles in the directed graph reachable from vertex a as shown in the ﬁgure below. It was already discussed that its worst case time complexity will be O(pq).

29. Does that mean we have to apply Bellman-Ford algorithm at each vertex to ﬁnd if there are any negative weight cycles in the graph? But that will be very costly? Figure 5.11.28: After ﬁnding 3-edge shortest paths in this graph from vertex a there will be no change in distance calculations. This does not conﬁrm that there is a negative weight cycle.Shortest Path Algorithms 239 Figure 5. 5. See Fig. Does that mean that we should stop here and declare that there are no negative weight cycles in this graph? Applying Bellman-Ford Algorithm once to determine Negative Weight Cycles The problem is how can we apply Bellman-Ford algorithm just once from a (special) vertex and check if there are any negative weight cycles in the di- .27: If we ﬁnd i-edge distances in this graph from vertex a then we observe that some distances will change when i goes from 4 to 5.11.11. 2. But when a distance of a vertex from vertex a changes when i goes from 5 to 6 then that is a conﬁrmation that there is indeed a negative weight cycle in this graph. How about if we apply Bellman-Ford at a vertex which is not reachable to a negative cycle.

If there are no negative weight cycles then what are the shortest distances of each vertex from the newly added vertex x.11. 5. This information will further be used to convert negative edge weights into positive edge weights. Converting negative weight edges into positive weight edges Please note that we need to simultaneously fulﬁll the following two objectives: . If. Thus we cannot add an arbitrary positive number in each edge weight as it will disturb the relative path lengths in the new graph as shown in the following ﬁgure. 2. Whether there are any negative weight cycles in the graph.30.11.240 Basics of Graph Algorithms Figure 5. rected graph? The answer to this problem is given in elegant transformation shown in Fig.29: If we apply Bellman-Ford algorithm in this graph to ﬁnd shortest distances from vertex e then we should never be able to conﬁrm that there will be negative weight cycles in this graph. If there are any negative weight cycle then the algorithm should not move forward and should terminate. we apply this algorithm from vertex a then it is possible to verify that indeed there are negative weight cycles in this graph.31. How about adding a big positive number in each edge weight such that every (edge) weight becomes positive? See what complication would arise if we do so as shown in Fig. 5.11. The application of Bellman-Ford algorithm in the transformed graph just once (from the newly added vertex x) provides us the following information: 1. If the graph does not contain any negative weight cycles but contains negative weight edges then we should somehow try to make the negative weight edges positive and then apply Dijsksta’s algorithm from each vertex as already planned. however.

All edges coming from vertex x have a zero weight. But adding a constant in each edge weight disturbs the relative weights of diﬀerent paths and leads to a wrong answer.11.Shortest Path Algorithms 241 Figure 5. Figure 5.30: The transformation in this diagram allows us to apply Bellman-Ford algorithm just once and verify if there are any negative weight cycles in the graph. We apply Bellman-Ford algorithm to this transformed graph and ﬁnd shortest distances from vertex x.11.31: We can always convert negative edge weights by adding a positive number in each weight so that we can apply a more eﬃcient algorithm to ﬁnd shortest paths in a graph with positive edge weights. .

11. k)new = w(j. All negative edge weights should be converted into positive weights. It requires that vertices should not be labeled arbitrariliy but with some intelligence as described below. 5. So now the problem is reduced to ﬁnding an appropriate number Label(j) to be associated with a vertex j and another number Label(k) to be associated with vertex k (assuming that there is an edge from j to k with a weight w(j. In the top diagram we try to initially label k such that . The other problem (converting all negative edge weights into positive) remains to be solved. Then we shall modify this scheme so as to convert all negative edge weights into positive edge weights thus fulﬁlling both the above objectives. k)) such that if w(j.242 Basics of Graph Algorithms 1. Before ﬁnding a systematic scheme of providing labels to each vertex let us try to work out a simple example. 5. k)old is negative then w(j. and Label(k) are all negative. Consider a directed edge (j. Label(j). If we associate an arbitrary number with each vertex of the graph and change edge weights according to the formula described then we claim that relative path lengths between any two vertices will be the same in the new graph as compared to the old graph.11. In other words Label(k) should be at least equal or more negative than wjk (old)+Label(j) assuming that wjk (old). How about associating any arbitrary number Label(j) with a vertex j and another arbitrary number Label(k) with vertex k.This would require that wjk (old) + Label(j)−Label(k) is greater than or equal to zero. namely the relative distances between two vertices remain the same in the new graph as compared to the old graph.33. It means that wjk (old)+ Label(j) is not less than Label)k). k)old + Label(j) − Label(k) becomes positive. 2.11. Putting arbitrary labels solves only one problem.30. All relative distances between two vertices should remain the same in the modiﬁed graph with positive edge weights. First we shall devise a simple scheme to alter edge weights such that relative distances between any two vertices do not change in the given graph. What numbers are desirable and should be associated with two adjacent vertices j and k are indicated in Fig. In fact the new path length from a vertex a to a vertex b will be the old path length plus Label(a) − Label(b). See Fig. Here vertex x is a vertex added to the given directed graph just like the one shown in Fig. 5. k) is changed according to a formula where wnew = wold +Label(j)−Label(k).32. k) with a weight equal to w. Now the edge weight w(j.

Shortest Path Algorithms 243 b 11 11-6=5 -6 a -2 -2+3-4+7=4 c 7 -4 -3 d 3 e f 0 11 b -6 11-6=5 -4 a -3 -2 -2+3-4+7=4 c b 0 11+0+3 11-6+0+4=9 -6-3+4 7 -4 d -4 -1 3 e -2 f -5 a -2+0+1 c 7-5+4 -2+3-4+7+0+4=8 d -1 3-1+2 e -2 -4-2+5 f -5 Figure 5.32: How relative distances remain the same if we associate an arbitrary number with a vertex and then add a number in the edge weight of each edge according to a ﬁxed formula.11. .

See Fig. If you are still undecided then read the following paragraphs and look at the coming ﬁgure. Check if there are any negative weight cycles in the graph D using Bellman-Ford algorithm applied to the graph after inserting a source vertex x as shown in Fig.244 Basics of Graph Algorithms weight of edge (j1 . That shortest distance Dist(k) become Label(k) of vertex k. If there are no negative weight cycles in graph D then move to step 2 otherwise terminate.35. 1. It should become quite evident now that if Label(j) is the shortest distance of vertex j from vertex x and Label(k) is the shortest distance of vertex k from vertex x then the required inequality would be satisﬁed and the edge weight for edge (j.34 where the shortest distance of vertex j is updated. Let us recall the basic building block of Bellman-Ford algorithm and how the shortest distance of a vertex k from a source vertex x is updated. In step 1 we have already found shortest distance Dist(k) of each vertex k from newly inserted vertex x. k) also becomes positive.11. Now coming back to the general question: What systematic scheme should be applied which guarantee the allocation of desirable numbers to vertices of a graph such that all edge weights become positive while relative distances between any two vertices remain the same? After looking at the last ﬁgure you must have some idea of what is going on or what should be done.35.33 where the label of a vertex is updated and now loook at Fig. 2. 5. 5.11.11. In the bottom diagram we intend to re-label k such that weight of edge (j3 . Now draw another copy of graph D with all edge . 5. The interesting thing is that we need not spend extra time in ﬁnding these labels as they have already been found while checking if the given graph has negative weight cycles. 5. See Fig.34 for a demonstration of this updating. k) becomes positive. Please see once again Fig. k) will eventually become positive if it was initially negative.11.11. Summary So now we are in a position to describe Johnson’s algorithm in the following meaningful manner as applied on a directed graph D. Please note that the new label of k (equal to -80) will make sure that all edges incident to vertex k have positive edge weights. 5.

k) becomes positive. and j3 are already labelled while we need to label k so as to make edge weights positive. In the top diagram we try to initially label k such that weight of edge (j1 .Shortest Path Algorithms 245 Figure 5. Please note that the new label of k (equal to -80) will make sure that all edges incident to vertex k have positive edge weights.33: We assume that vertices j1 . In the bottom diagram we intend to re-label k such that weight of edge (j3 . k) also becomes positive.11. . j2 .

34: While executing Bellman-Ford algorithm we use a basic building block as shown above.11.k) k x Dist(k) = -70 j w = -40 k New Dist(k) = -60 j Dist(j) = -20 w = -40 k New Dist(k) = -70 Figure 5.246 Basics of Graph Algorithms Dist(k) = min{ Dist(k). . Dist(j) + w(j.11. The bottom diagrams show how and when the shortest distance of vertex k from a source vertex x is updated. k)} x Dist(k) Dist(j) j x Dist(k) = -10 Dist(j) = -20 w(j.35: How to determine which labels to associate with each vertex. x Transform 0 b 8 -2 -4 -4 1 -2 2 b 0 -2 a -2+2 8-2 1+0 2+4 -4+4 a c -4 c d 0 3 e 0 d 0 3+0 e 0 Figure 5.

5. In this chapter we have demonstrated how a teacher can help students discover a number of graph algorithms with some initial help. 3. If the teacher helps too much. but I refer here to the intellectual kind.11.Discussion 247 weights modiﬁed. We have also shown that making comparisons between various techniques and solutions provides a deep insight which itself is very useful in solving otherwise diﬃcult problems [8]. All negative edges become positive as shown in Fig.” .12 Discussion The most important task of a teacher should enable the students to discover and acquire experience of independent work. nothing is left to the students. To learn means to cause your mind to function in a diﬀerent way: new memories are created and/or new connections are forged. The theory of NP-Completeness connects all problems that are NP-Complete: it is also possible to ﬁnd a useful relationship among solvable problems and this is what we have attempted to do in this chapter. so that the student shall have a reasonable share of the work. We have shown that by asking thought provoking questions it becomes possible for the teacher to guide the students while solving complex problems. According to Polya [10]: If the student is left alone with his problem without any help or with insuﬃcient help. The teacher should help. he may make no progress at all. According to Hale [5]: “There are diﬀerent kinds of learning. Similarly it is diﬃcult to solve a problem in its original form while it is easier to solve it while placing certain restrictions (the graph isomorphism problem is solvable for trees but is diﬃcult to solve in general). but not too much and not too little. At times it is almost impossible to solve a given problem while it is easy to solve a related problem (the shortest path problem is solvable while the longest path problem is unsolvable). starting with something seemingly simplistic yet capable of being transformed into a number of powerful algorithms with minor modiﬁcations.35. 5. It is extremely useful to ﬁnd why a certain technique works under certain conditions and why it fails in others (greedy methods provide optimal solutions in ﬁnding the shortest path but fail to ﬁnd the longest path). Now apply Dijksta’s shortest path algorithm at every vertex in the modiﬁed graph (with positive edge weights) to ﬁnd all pair shortest distances and paths.

Khan for providing motivation as well as inspiration for this project. Lahore University of Management Sciences for providing support for this research. Maud. . T. We wish to specially thank R. S. Jadoon for their help and encouragement. J. Acknowledgement We are thankful to the Department of Computer Science. K. Mahkari. Skiena. Baase. Mian. Ikram. A. S. M.248 Basics of Graph Algorithms These relationships provide the algorithm designer a perspective that proves invaluable when solving new problems and analyzing old one’s. Fahd. Alvi. H. We also wish to thank S.

8 6.1 6.3 6.5 6.Chapter 6 Network Flows.4 6.7 6.9 Introduction Deﬁnitions & Prior Knowledge Konig’s Theorem.2 6. Menger’s Theorem & Hall’s (Marriage) Theorem Revisited Network Flows The Matching Problem in Bipartite Graphs The Max-Flow Min-Cost Problem Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem . Connectivity and Matching Problems 6. Menger’s Theorem & Hall’s (Marriage) Theorem Menger’s Theorem Konig’s Theorem.6 6.

What is the smallest subset of vertices of the graph that covers all edges in the graph? Independent (Vertex) Set: What is the largest subset S of vertices of a graph such that no pair of vertices in S has an edge in between? Is there a .1 Introduction We shall ﬁrst address the problem of vertex or edge connectivity in general graphs. what is the smallest subset T of S such that the union of all these sub sets in T covers all elements of U (it means that every element in U is contained in any of the subsets in T and the set T has the smallest possible size). We shall also be discussing the network ﬂow problem. That is why we ﬁrst provide a uniﬁed picture and then go deeper in order to analyze each area in detail. The Marriage (Hall’s) theorem provides necessary and suﬃcient conditions for a bipartite graph to have a perfect matching. Vertex Cover: The Universal set U is the set of all edges in a graph. 6. and last but not the least the Circulation problem.2 Deﬁnitions & Prior Knowledge Set Cover: Given a set of subsets S of a Universal Set U . will be to integrate concepts so that the enabled learner is able to appreciate the bigger picture where one relationship implies another and one theorem can be used to prove the other. Connectivity and Matching Problems 6. We shall also discuss the matching problem in bipartite graphs. Our intention (and desire) in this chapter. We shall also discuss Konig’s Theorem which relates the size of the vertex cover to the size of maximum matching in a bipartite graph. we shall be designing algorithms to solve a number of related problems. the maximum ﬂow at minimum cost problem. We have witnessed the subset sum problem in which we have to select integers (out of a set of integers) such that the sum of the selected integers is equal to a given constant. which if removed will disconnect a special node from another special node in a graph.250 Network Flows. We use a single building block in this entire chapter for designing almost every algorithm. In addition to making formal proofs for a number of theorems. Speciﬁcally we shall be describing Menger’s Theorem which relates maximum number of vertex-disjoint (or edge-disjoint) paths with minimum number of vertices (or edges).

The size of a matching is equal to the size of set A. as compared to the number of vertices .Deﬁnitions & Prior Knowledge connection between the vertex cover and the independent set problem? 251 v u Figure 6. i. (A line graph is a tree where the degree of each node is not more than 2) Maximum Matching: It is a matching in a graph with maximum possible size? How bad can a maximal matching become as compared to maximum matching? (It means how small the size of the maximal matching can become as compared to the size of the maximum matching) Edge Cover: The Universal set is the set of all vertices in a graph. Maximal Matching: This is a matching in which more edges cannot be added to increase the size of this matching. Note that every non leaf vertex is a cut vertex and every edge is a cut edge or a bridge in a tree graph. Each leaf vertex is at a distance of 3 from the root vertex.2. The root vertex is shown at the top of the diagram.1: A perfect binary tree is shown. while any vertex cover will include non leaf vertex v. that is. Perhaps a more meaningful deﬁnition will be a set A of non-adjacent edges. Find a simple algorithm to ﬁnd a maximal matching in a line graph. Matching (Independent Edge Set): A sub-graph of G.e. which covers all vertices? How small (or big) can the size of the edge cover become. where the maximum degree of each vertex is one. Any independent set will include leaf vertex u. no two edges in the set A share a common vertex. What is the smallest subset of edges. These edges are also known as independent edges. no edge has a common end point. Every edge connecting a leaf vertex u and a non leaf vertex v will always be part of the edge cover.

a leaf vertex u will always part of an independent set (why?).2. It has exactly 2h+1 − 1 vertices where h is the path length (in terms of number of edges) between the root vertex and any leaf vertex in the perfect binary tree. The root vertex is shown as the top most vertex in Fig. In a perfect binary tree graph G.1 has 8 leaf vertices.1 has h equal to 3 and it has 15 vertices.2. 6. Independent set and vertex cover vertices are shown in Fig. every vertex of the graph is incident to exactly one edge of the matching. The perfect binary tree shown in Fig. The perfect binary tree shown in Fig. Every perfect matching is both maximum and hence maximal. 6. A binary tree is a tree where the degree of each vertex is less than or equal to 3. In some literature. 6. It has exactly 2h leaf vertices. Here we deﬁne a perfect binary tree. We know that in a tree every edge is a cut edge or bridge while every (non leaf) vertex is a cut vertex. 6. While a non leaf vertex v which is adjacent to a leaf vertex will always be part of a vertex cover (why?). We are given a perfect binary tree G (see Fig.1. 6. We shall observe later in this chapter that there is indeed a relationship between graph connectivity and number of paths in a graph (Menger’s Theorem).2 for the perfect binary . A Perfect Binary Tree: We know that a tree is a connected graph where each edge is a bridge edge. There are 7 non leaf vertices in tree shown in Fig.2.1.2. 2. As described before each leaf vertex in a perfect binary tree has a path length equal to h from the root vertex. Connectivity and Matching Problems A Perfect Matching is a matching which covers all vertices of the graph.2. It has exactly 2h − 1 non leaf vertices including the root vertex.2. 4.252 in a graph? Network Flows. 6. 3. Let us call it the root vertex.1) and we intend to solve a number of problems related to connectivity and matching.2. Problem Set 6.1) has the following features: 1. That is. We also know that there is always a unique path between every two vertices in a tree. It has a single vertex with degree equal to 2. Using this logic all leaf vertices will be part of the independent set and will not be part of the vertex cover. All non leaf vertices other than the root vertex has a degree exactly equal to 3.1. 6. the term complete matching is used for perfect matching. A perfect binary tree (shown in Fig.

The maximum matching in this graph is not a perfect matching. The bottom left diagram highlights.2. The rest of the vertices belong to the independent set in this diagram as shown in the top right corner. the maximum matching edges in the given tree. The bottom right diagram shows the edges belonging to the edge cover.2: The top left diagram shows the vertices belonging to the vertex cover highlighted by double circled vertices. these edges are shown in bold in green.Deﬁnitions & Prior Knowledge 253 u Vertex Cover u Independent Set u u v u u u v u u Maximum Matching u Edge Cover u u v u u u v u Figure 6. You may have also noticed some relationship between the size of the vertex cover and the size of the independent set? . You may have noticed that the size of the maximum matching is equal to the size of the vertex cover in this graph. in brown bold. as all vertices here are not matched as shown by black circled vertices.

Please note that a perfect binary tree graph is a fairly restricted structure and our existing prior knowledge of graph theory and algorithms is suﬃcient to solve these problems. 6. Problem 6. Does a perfect matching exist in a perfect binary tree? Discuss brieﬂy.1.2. however a near perfect matching may exist.2.1.1. Problem 6.2.1.1) will always be part of the edge cover.2.254 Network Flows.7.2.1. How can we ﬁnd an independent (edge) set.2. The bottom left diagram of Fig. 6.2 to see if a near perfect matching exists in a perfect binary tree.1. How can we ﬁnd an independent (vertex) set in a perfect binary tree? Problem 6.3.2.6.2. A perfect matching may exist for the tree graph if the two halves have the same size. what conditions are necessary and which are suﬃcient? Problem 6. For a perfect matching to exist in a tree graph. meaning a maximum matching in a perfect binary tree? Problem 6. 6. We know that a tree is a (restricted) bipartite graph consisting of two halves. Check Fig.1. then a perfect matching cannot exist.2 shows a maximum matching in the perfect binary tree graph of Fig. How can we eﬃciently ﬁnd a vertex cover in a perfect binary tree? Problem 6. It may thus be possible to ﬁnd a maximum matching given a vertex cover in a tree graph. Connectivity and Matching Problems tree graph of Fig. Based upon the above observations it is possible to design eﬃcient algorithms to solve the following problems in a tree graph.1. 6. In a perfect binary tree graph an edge connecting a leaf vertex u with a non leaf vertex v (see Fig. Edges belonging to the edge cover are shown in bold in the bottom right diagram of Fig. .4. A near perfect matching requires that all vertices belonging to the smaller half are matched to vertices in the larger half in a bipartite graph. It also indicates matched and unmatched vertices and edges. If the two halves are not of the same size. How can we eﬃciently ﬁnd an edge cover in a perfect binary tree? Problem 6.1. 6. We shall observe later that in a bipartite graph (such as a tree) the size of a maximum matching is equal to the size of vertex cover (Konig’s Theorem).1.5. 6.

1. A concept map showing a number of relevant concepts and a number of theorems which relate diﬀerent concepts. .Deﬁnitions & Prior Knowledge 255 Concept Map 6.

where both s and t belonged to G. t) as the minimum number vertices which if removed from G. while a tree graph T has λ(T ) = 1. The edge connectivity for a completely connected graph (having p vertices) is equal to p−1. Thus λ(s. t) is the minimum number of edges which if removed will destroy all paths between vertices s and t in G. Problem 6. So our new requirement is that when G is disconnected (by removing certain edges) then vertices s and t should belong to diﬀerent connected components of G.1. Connectivity and Matching Problems Figure 6.8.256 Network Flows. the resulting graph will be a disconnected graph. vertices s and t of G would now belong to diﬀerent connected components. Vertex Connectivity κ(G) of a Graph G is the minimum number of vertices which if removed will disconnect the graph G (see Disconnected Graph). . will disconnect it so that all paths between vertices s and t are destroyed. A disconnected graph G has λ(G) = 0. Sometimes we not only want the graph G to be disconnected but also want to make sure that a special vertex s is separated from another special vertex t.2. By removing certain edges (or vertices) it is possible to remove all these paths between the two vertices. Similarly we deﬁne κ(s.3: There are several paths between vertices s and t in this graph. What are the necessary and suﬃcient conditions for a near perfect matching to exist in a tree graph? Edge Connectivity λ(G) of a Graph G is the minimum number of edges which if removed will disconnect the graph G (see Disconnected Graph).

See Fig. Problem Set 6.2 shortlist the ones that are edge-disjoint. Problem 6.3. Draw all 5. that is.2. Problem 6.2 short list the ones that are vertex-disjoint.2. Disconnected Graph: A graph G may simply be disconnected into two or more connected components.2.6.4.Deﬁnitions & Prior Knowledge 257 Edge-disjoint paths do not share any edge. 6.2. We intend to explore diﬀerent paths between these two vertices and see how we can destroy these paths in G. We are given a graph G with two special vertices s and t as shown in Fig. We have to remove a lot more than one vertex in order to disconnect G so as to destroy all paths between vertex s and t.and 6.2.2.2.2.2.2.4. 6.2.1 and Problem 6. Draw a 4-edge path between the two vertices such that not more than one additional edge-disjoint path is possible between the two vertices. if we remove this edge {s. Problem 6.1. See Fig.2. What is the maximum number of such paths? Problem 6. There is no cut vertex in this graph. Problem 6.2.edge paths between the two vertices.2. There is only one bridge edge in this graph. while vertex-disjoint paths do not share any vertex except the terminal vertices.3. Out of all paths that you have listed in Problem 6.2. it may be broken up into more connected components or we may require that G would be disconnected such that two special vertices s and t of G should lie in separate connected components.1 and Problem 6. then the graph G is disconnected but vertex s is still accessible to vertex t. Draw all 4-edge paths between vertex s and t. Draw more than one edge-disjoint paths between the two vertices such that at least one path should be of length six. Vertex-disjoint paths are also edge-disjoint but it may not be true the other way round.4. . What is the maximum number of such paths? Problem 6.5. a}. Out of all paths that you have listed in Problem 6. 6.

Connectivity and Matching Problems Four Edge and Six Edge Paths a g a g b s c e h t s b e h t f i s c f i d Ca l wn ra e d is? n b th ike j b c d d j e g h i i f j i f j t t t t t t t Figure 6. s a g Can be drawn like this? b b s c f i e h t g e i h i c d f j i f j d j t t t t t t t Figure 6.5: Some edge disjoint paths.258 Network Flows. these paths are not vertex disjoint? .2.2.4: 4-edge and 6-edge paths from vertex s to vertex t in graph G.

6. Why? What are its ramiﬁcations in designing an algorithm to ﬁnd all possible edge-disjoint paths in a graph? Problem 6. We know that there existed more than one path between the two vertices. Once these paths are selected.2.7. but only because we have selected one wrong path initially.Deﬁnitions & Prior Knowledge 259 Figure 6. Can you ﬁnd another subset of three edges which when removed will disconnect s and t? What is λ(s. Problem 6.2. 6.7 shows two edge disjoint paths of length 4 (shown in bold) between the vertices s and t.7 shows a 6-edge path (shown in bold) between vertices s and t in the same graph. The right diagram of Fig. List down these edges.2. t) for this graph? Problem 6.2.6: A 6-edge path and a couple of 4-edge disjoint paths. A minimal subset of these edges shown by a cut is suﬃcient to do the job. Note that if we remove all edges in this 6-edge path. it will no longer be possible to ﬁnd an extra edge-disjoint path between the two vertices.2. Draw a 6-edge path between the two vertices such that no additional edge-disjoint (or vertex-disjoint) path is possible between the two vertices. You can remove all edges belonging to the . that other possible paths have disappeared.2.9. 6.2. The left diagram of Fig.2. Problem 6.8.10. then all the paths between vertex s and t are destroyed.7 in order to destroy connectivity between s and t. In fact it is not necessary to remove all the edges in the single 6-edge path as shown in Fig. Do these three edges corresponds to a minimum number of edges which if removed will destroy all paths between vertices s and t.

The right diagram shows two 4 edge disjoint paths (shown in bold) between vertices s and t. 6. 6. . What is a minimal subset of these edges which will do the same job of destroying the connectivity between s and t? One such subset is shown in the right diagram of Fig. which if removed will destroy the connectivity between vertices s and t. the diagram also shows. The left diagram of Fig.11. two vertex-disjoint paths between s and t.2. This subset consists of two vertices. Does this mean that there will be three edge-disjoint paths in this graph? Find these three paths. Is this a coincidence that the (maximum) number of vertex-disjoint paths is exactly equal to the (minimum) number of vertices which if removed will disconnect s and t? The left diagram shows an edge cut of size three. The right diagram shows a minimum sized subset of vertices which if removed will disconnect s and t from each other.2. paths and see for yourself that the connectivity between s and t is destroyed.8 shows a minimum sized subset of edges. The blue (green) cut cuts those edges which.7: The left diagram shows a 6-edge path (shown in bold) between vertices s and t in the graph.2.2. e and f . This subset consists of four edges unlike three in the last part? Problem 6.7. 6. Be careful as this is the same cut shown in the left diagram of Fig. Connectivity and Matching Problems g a A Cut g b e h b e h s c f i t s c f i t d j d j Figure 6. Now we need to ﬁnd three edge-disjoint paths between the same vertices. in bold.7 where there existed a single path of six edges (with no room for additional paths).2.260 a A Cut Network Flows. if removed will disconnect s from t.

matching.3.1.3 Konig’s Theorem. if removed from the graph will disconnect s and t (see Concept Map 6. 6. The right diagram shows a minimum sized subset of vertices (shown by double circles) which if removed will disconnect s and t from each other.3. Konig’s Theorem tells us that the cardinality of a maximum matching in a bipartite graph is equal to the (minimum) size of the vertex cover (see Concept Map 6.8: The left diagram shows a minimum sized subset of edges (shown in bold) which. Menger’s Theorem & Hall’s (Marriage) Theorem a g h a 261 An Edge Cut g e h b e f b s c d i j t s c d f A Vertex Cut t i j Figure 6. How one theorem implies another and can be derived from each other.3. and the above theorems in detail in subsequent sections. The vertex cover in the bipartite graph (shown . 6. The left diagram of Fig.1). 6.Konig’s Theorem. 6. The right diagram of Fig. we shall ﬁrst provide a panoramic picture of how the diﬀerent concepts are interrelated.1 shows the same bipartite graph with two dummy nodes designated as s and t.2. will destroy the connectivity between vertices s and t.1 shows a bipartite graph with partite A and partite B. Menger’s Theorem & Hall’s (Marriage) Theorem Before discussing connectivity. if removed. The vertex cover of this bipartite graph is also indicated in this ﬁgure. All vertices in the ﬁrst partition of the bipartite graph are connected to s while all vertices in the second partition are connected to the dummy vertex t as shown in the right diagram of Fig. The right diagram of Fig.2. 6. it also shows a maximum matching with the maximum matching edges shown in bold.8 is an illustration of Menger’s Theorem. It states that the maximum number of vertex-disjoint paths between vertices s and t are equal to minimum number of vertices which.1).

t)) in the graph shown on the right side of Fig. b4 } N ({a1 }. 6. {a2 }. Connectivity and Matching Problems in the left diagram) becomes the minimum sized subset of vertices which.1 would be equal to the size of partition A (and B).3. while in the remaining two the said condition is violated. only three satisfy the condition that |N (S)| ≥ |S|.3. N ({a1 }. It states that a bipartite graph (of equal halves) has a perfect matching if and only if |N (S)| ≥ |S| for every S ⊆ A. You may have realized yourself that this necessary and suﬃcient condition (applicable to the bipartite graph shown on the left of Fig. 6. b3 . For a better understanding of the Marriage Theorem a few neighborhood subsets are indicated below for the bipartite graph of Fig. b2 } N ({a2 }. A relationship between (minimum) vertex cover and maximum matching in a bipartite graph (Konig’s Theorem) is transformed into a relationship between κ(s. Similarly each matched edge (in the left diagram) will correspond to a vertex-disjoint path between vertex s and t in the right diagram (why?). {a3 }) = {b2 } N ({a2 }. It is interesting to note that if we remove vertex a3 from A and vertex b3 from B then the condition |N (S)| ≥ |S| is true for every S ⊆ A. {a3 }) = {b1 . .1 (Menger’s Theorem). {a3 }. {a3 }.1) implies that the (maximum) number of vertex-disjoint paths (and κ(s.3. Had a perfect matching existed then the size of the vertex cover would have been equal to the size of A (or B). b2 .3. Note that all vertices in the set A are not matched to all vertices in the set B although the size of A is equal to size of B in the given bipartite graph. {a2 }. {a4 }) = {b1 . {a4 }) = {b2 . {a2 }) = {b1 . Under such conditions the size of the maximum matching and that of the vertex cover will be equal to the size of remaining set A which is equal to three. b2 } N ({a1 }. b4 } Out of the ﬁve neighborhood subsets N (S). In other words a perfect matching does not exist in this bipartite graph. What should be the size of the neighborhood N (S) for every subset S of A which will guarantee a perfect matching (or a vertex cover equal to the size of A) is the subject of Marriage (Hall’s) Theorem.1. t) and (maximum) number of vertex-disjoint paths between vertex s and t in the right diagram of Fig.262 Network Flows. 6. b3 . if removed will destroy all paths between vertex s and t in the right diagram (why?). 6.

.3.1: The top left diagram shows a bipartite graph with maximum matching edges shown in bold. and vertices belonging to the vertex cover highlighted by orange circles. Menger’s Theorem & Hall’s (Marriage) Theorem 263 Every Matching Edge a1 a2 A a3 a4 b3 b4 b1 b2 B Corresponds A Path from s to t a1 a2 b1 b2 B b3 b4 b1 b2 B b3 b4 s A a3 a4 a1 a2 t a1 a2 A a3 a4 b1 b2 B b3 b4 Corresponds s A a3 a4 t Every Node of Vertex Cover Maximum Matching Minimum Vertex Cover Konig’s Theorem A Node of Vertex Cut Maximum Paths Transforms Minimum Vertex Cut Menger’s Theorem Figure 6. The top right diagram shows the same bipartite graph with two dummy vertices s and t.Konig’s Theorem.

such that D − U does not contain any directed path from vertex s to t. how can we ﬁnd the maximum edge-disjoint (vertex-disjoint) paths from s to t in a directed graph D? 2. t). Menger’s Theorem equates the maximum number of edge disjoint (vertex disjoint) paths between vertices s and t to minimum number of edges (vertices) which if removed will disconnect s from t. (see Concept map 6. Thus the problem of ﬁnding maximum number of paths from s to t is.1 Maximum Edge-Disjoint Paths in Directed Graphs Given a directed graph D and two speciﬁc vertices s and t.4. Given a directed graph D containing two special vertices s and t. We shall also address the following algorithmic problems: 1. the maximum number of edge-disjoint paths from vertex s to t will be equal to λ(s.264 Network Flows. Connectivity of a directed graph D also poses similar problems. The size of U will obviously be represented by λ(s. Connectivity and Matching Problems 6. t). 6. how can we eﬃciently ﬁnd the maximum number of edge-disjoint paths from vertex s to vertex t? Let U be the minimum sized subset of the edge set of D. in fact. Then according to Menger’s Theorem. equivalent to ﬁnding a minimum sized edge set which if . Given an undirected graph how can we ﬁnd its connectivity: the minimum number of edges (belonging to Edge Cutset) or minimum number of vertices (belonging to Vertex Cutset) which if removed will disconnect the graph into two or more connected components? The graph theoretic aspects of the above problems and a proof for Menger’s Theorem will be presented after a better appreciation of the issues involved.1). We shall start this section with directed graphs and then generalize our results for undirected graphs. Given a directed graph D how can we ﬁnd the minimum number of edges (vertices) which if removed will destroy all paths from vertex s to t in D? 3.4 Menger’s Theorem Connectivity of an un-directed graph is expressed in terms of minimum number of edges or minimum number of vertices which if removed will disconnect the graph G.

A concept map showing a number of concepts related to vertex connectivity and edge connectivity and some important relationships that we shall explore in this section. .Menger’s Theorem 265 Concept Map 6.2.

Pick the initial path more intelligently . output: (Maximum) edge-disjoint paths from s to t in D. Let us apply this simple algorithm to solve the problem in the graph of Fig. Once we have selected an initial path P1 . Using any path ﬁnding algorithm. Do not delete the edges of the chosen path . and the other (s → b → d → t or s → d → t). It may be (s → a → c → t). If you are successful in ﬁnding a path then keep a record of this path. it has now become impossible to ﬁnd another path in this graph. What is that something else? Before we actually try something new consider the following: . we shall be able to ﬁnd the two edge-disjoint paths. How about devising the following common sense algorithm to ﬁnd the maximum number of edge-disjoint paths from vertex s to t in a directed graph D? Algorithm 36: Find Maximum edge-disjoint paths from s to t in D. Thus an initial wrong choice will make things hard for us.4. Let us look at what are diﬀerent possibilities for P1 . It cannot be (s → d → a → c → t) or (s → b → d → a → c → t) because on directed edge (a. 6. why? 2.266 Network Flows.1. Remove all edges in the path P and.but this may not be an eﬃcient solution. If path P1 = (s → a → d → t) (as shown by bold lines in Fig.and do something else with these edges.4. d) we can move from ‘a’ to ‘d’ but not from ‘d’ to ‘a’. and vertices s & t. But before ﬁnding another edge-disjoint path we should ﬁrst remove the edges of P1 (why?) and then ﬁnd another path P2 . one being (s → a → c → t). or (s → d → t). 1 2 Find a directed path P from vertex s to vertex t in D. we shall land in a diﬃcult situation as depicted in Fig.4. Connectivity and Matching Problems removed from D will disconnect t from s. from vertex s to t in D. 6. go to step 1 . (s → a → d → t). (s → b → d → t). 6. But if we are unlucky. If we are lucky.1. otherwise exit the algorithm. We are in dire need of some innovation? There are potentially two ways to ﬁx this problem: 1.1) then we are blocked. we can move forward in Algorithm 36. input : Directed graph D. we can ﬁnd a directed path P1 .

2 before arriving at a conclusion. 6. Is it possible to convert one class of graphs into another? If this is possible then after the conversion we can use our (stupid) Algorithm 36 to ﬁnd out maximum edge-disjoint paths in a graph? 5. How about if the directed graph D is cyclic but the in-degree as well as the out-degree of every node are equal? You should consider both cases: when vertices s and t are not part of any cycle and when they are also part of some cycles. See Fig. Show that if you apply Algorithm 36 to this graph then you will be able to ﬁnd the maximum number of edgedisjoint paths without any complication. We are given a directed acyclic graph D with a source vertex (a vertex with zero in-degree) s and a sink vertex (a vertex with zero out-degree) t. .4. Is this complication. Is there a class of directed or undirected graphs where an initial wrong selection would not create any complication? How is the class of graphs (where an initial wrong selection really matters) structurally diﬀerent from the other class (where an initial wrong selection does not matter)? 4. 1.Menger’s Theorem a c a c 267 s b d t s b d t Figure 6. 2. Algorithm 36 fails to ﬁnd the maximum number of edge-disjoint paths in a graph but it still ﬁnds maximal number of edge-disjoint paths in a graph.4. The in-degree is equal to the out-degree for every vertex i of D other than the vertices s and t. (where an initial wrong choice will make things hard) a general phenomenon in almost all graphs or is this a problem in a certain class of graphs? 3.1: If we initially select a path as shown by bold red lines (left diagram) and remove it from the graph (right diagram) then it becomes impossible to ﬁnd another path in this graph.

2: A directed graph D in which the in-degree of every vertex is equal to the out-degree of every vertex including vertices s and t. y). can be traversed by a new path from y to x and not from x to y. let us try to solve a simpler problem (ﬁnding pseudo edge-disjoint paths) and then use our newly found experience and conﬁdence to solve the harder problem (ﬁnding edge-disjoint paths). It is rule number 2. Please note that rule number 1 is common in pseudo edge-disjoint as well as edge-disjoint paths. y). A directed edge (x.4. not already in use by a path. We shall later show in this section that the number of pseudo edge-disjoint paths between two vertices in a graph is exactly equal to the number of edgedisjoint paths. given a set of pseudo edge-disjoint paths in a graph it is possible to ﬁnd an equal sized corresponding set of edge disjoint paths in the graph. which is traversed by two paths in opposite directions will be “not used by any path” or “unused”.268 Network Flows. Connectivity and Matching Problems a c a c s b d t s b d t Figure 6. in case of pseudo edge-disjoint paths we follow the following rules of the game: 1. This diagram is provided by Khawaja Fahd. y) cannot be shared by more than one path. . in fact. The status of such an edge when traversed by a single path from x to y will be “used”. expecting an innovation to achieve this objective may be unrealistic. A directed edge (x. In edge-disjoint paths an edge (x. already traversed by a path from x to y. Finding edge-disjoint paths in a general directed graph may be hard to ﬁnd. which makes the two categories different. can be traversed (or used) by a path from x to y and not from y to x. 2. The status of such an edge. Finding maximum number of pseudo edge-disjoint paths is a problem which can be solved using the exciting process of discovery based learning.

Algorithm 37 is based on this innovative idea. and vertices s & t.4. for every edge e in path P do set Status(e) = used if initially it was unused otherwise set Status(e) = unused.3.Menger’s Theorem 269 So the current problem is how to maximize the number of pseudo edgedisjoint paths in D? Instead of deleting all edges in a (recently found) path (as is done in step number 2 of Algorithm 36) we reverse the direction of each edge in the path.1. output: Maximum pseudo edge-disjoint paths from s to t in D and a Status(e) for every directed edge e of D. Algorithm 37: Find Maximum pseudo edge-disjoint paths from s to t in directed graph D. If you are successful in ﬁnding a path P then keep a record of the number of paths found so far otherwise exit with graph F as output. Initially no edge of D. We apply the above algorithms on the graph D shown in the same ﬁgure. Note that Algorithm 37 (unlike Algorithm 36) allows an edge to be used by two diﬀerent edge disjoint paths moving in opposite directions. is occupied by any path and thus the Status of every edge is unused. In step number 4 (instead of removing every edge in the path as was done in Algorithm 36) we reverse the direction of every edge in the path found in step number 1. We ﬁrst ﬁnd maximum pseudo edge-disjoint paths from vertex s to vertex t in this graph. 1 2 3 4 Copy Graph D into F .4. Status(e) = unused for every directed edge e in D. and then go back to step number 2. It also outputs the Status(e) of every edge e of D. Let us carefully look at this new algorithm which claims to ﬁnd the maximum number of pseudo edge-disjoint paths from s to t in a directed graph D. Find a directed path P from vertex s to vertex t in F . Example 6. As soon as an unused edge is occupied by a path its Status is changed from unused to used in step number 4. In step number 2 we ﬁnd a path from vertex s to t in D using any path ﬁnding algorithm. input : Directed graph D. Reverse the direction of edge e and then go back to step 2. 6. In this process (Algorithm 37) we convert graph . Let us execute this simple four line algorithm on the graph of Fig.

Let P be the set of vertices (of F ) reachable from vertex s in F . Minimum Cut will consist of edges (x.3: Original Graph D . Figure 6. 1 2 3 Convert D into F using Algorithm 37. input : Directed graph D. Connectivity and Matching Problems Algorithm 38: Find Minimum Cut in a graph D.4. output: Edges of D that belong to the Minimum Cut. and vertices s & t.270 Network Flows. y) of D Where x belongs to P and y belongs to V (D) − P .

Example 6. 6.Menger’s Theorem 271 D into F . 6. Let S be the set of vertices of D containing s but not t and let the subset T = V (D) − S. Then (S. Let us also consider the graph D (of Example 6.4. they both belong to a (desirable) class? You can apply (the very naive) Algorithm 36 to this class of graphs and you will ﬁnd maximum sized subset of edge-disjoint paths without any diﬃculty.4.4.4. 6. The diagram on the bottom right of Fig. The original graph D is shown in the bottom right diagram with used edges shown in bold. We execute Algorithm 37 once again on a directed graph D shown in Fig.4. P2 & P3 found by this algorithm are not edge-disjoint as shown in Fig.6. this new graph has some very desirable properties which we shall elaborate later. The set (S. The bottom left diagram shows the edges of the path P3 shown in bold.4. T ) will be a subset of E(D) and is known as a cut in the graph D (a cut signiﬁes edges which if removed from a graph will destroy all paths from vertex s to . 6.4. Graph F helps us identify the set P using Algorithm 38. Let us again consider graph D (of Example 6.4. The top right diagram shows the edges of another path P2 shown in bold. Before jumping to any conclusions and in order to gain more conﬁdence let us solve another example. The paths P1 (green) and P2 (blue) that we have found during the execution of this algorithm are not edge-disjoint paths (see Fig.1) minus the unused edges as shown in the bottom of Fig.6.2. Both these graphs share something in common.4 shows the original graph D with used edges only. 6.5. 6.2 The Concept of a Minimum Cut in Directed Graphs Let us deﬁne the concept of a cut more formally.6.2) minus the unused edges shown in Fig.4.4).4. yet this algorithm tells us the maximum number of possible edge-disjoint paths in D (why and how?). The Minimum Cut is found in Fig. 6. The top left diagram shows the directed graph D with a selected path P1 from vertex s to vertex t shown in bold. The most useful result of this algorithm is the Status of every edge e in D after its termination.4. Again Algorithm 37 provides the maximum number of edge-disjoint paths present in this graph although the paths P1 . T ) is a set of directed edges from a vertex in S to a vertex in T . After deleting unused edges (from D) we end up with this new graph. 6. Using this set P we identify edges of D which belong to the minimum cut.4.

4.272 Network Flows. . This Algorithm outputs maximum pseudo edge-disjoint paths and the Graph F .4: Graph D is the input to Algorithm 37. Connectivity and Matching Problems a c a Used c Used s b Graph D d t s b t Used d Initial Graph F a c Used a Used c Used n U s b d t s Used t Used U se d b d a U n c a c s Un Used t d s b d t d se U b Un Used Final Graph F Graph D without Unused Edges Figure 6.

5: The top left diagram shows the Original Graph D. the top right diagram shows the ﬁnal graph F with a couple of paths found and reversed.4. .Menger’s Theorem 273 a c a c s b Graph D d t s b Graph F d t a c a c s b Graph F d t s b d t Graph D Figure 6. The bottom left diagram shows the ﬁnal graph F where the Min Cut is found and then it is applied to the original graph D on the bottom right diagram.

The original graph D is shown in the bottom right diagram with used edges shown in bold. Connectivity and Matching Problems a g e f h a g e f h b b s c d a i j g e f h t s c d a i j g e f h t b b s c d i j t s c d i j t Figure 6.6: The top left diagram shows a directed graph D with a selected path P1 from vertex s to vertex t shown in bold.274 Network Flows. The top right diagram shows the edges of another path P2 shown in bold.4. . The bottom left diagram shows the edges of the path P3 shown in bold.

d) in the Cut C does not belong to the set (SC . TA ) is equal to U (which is the minimum sized subset of edges which. . Looking at this problem from a diﬀerent angle: In Cut B you have to remove all four edges present in this cut in order to destroy all paths from vertex s to t in D. t) = |(SA . TB ) = {(s. (d. t). 6. (a. 6. which is 2.4. 6. We shall provide a constructive proof. While in Cut C. We intend to prove Menger’s Theorem in terms of edge connectivity of a directed graph. d}. TC = {a. The size of Cut B is larger then the size of Cut A and that of Cut C. d)} For Cut C : SC = {s. c). Out of many possible cuts we show only three cuts in the directed graph shown in the top diagram of Fig. d) is physically cut by Cut B as well as Cut C but it is only included in the Cut B and not in Cut C. (SB . d). t}. (a. d). c.3 A Proof of Menger’s Theorem and Finding the Minimum Cut in Directed Graphs We are given a directed graph D and two special nodes s and t. b. While in Cut C you have to remove only two edges present in this cut and vertex s is disconnected from t. 6. 6.4. edge (a.4. TA = {c. TB = {c. (b. a).7. b. According to Menger’s Theorem the maximum number of edge-disjoint paths in this graph will equal λ(s.7.4. t)} It is interesting to note that the edge (a. Thus the edge (a. d) is not contributing to a path from s to t in D and is therefore not required to be removed. Please note that it is the same directed graph for which we have found maximum number of edge-disjoint paths as shown in Fig. if removed will destroy all paths from s to t in D). (SA . TA )| = 2. (SA . TC ) = {(s. d. (SC . This is because in Cut B vertex ‘a’ belongs to SB while vertex d belongs to TB as shown in the bottom left diagram of Fig. vertex ‘a’ belongs to TC and vertex d belongs to SC . t}. d}. How can we ﬁnd the minimum cut systematically? We shall discuss it in a proof of Menger’s Theorem. b}. c). (d. t)} For Cut B : SB = {s. Thus λ(s. For Cut A : SA = {s. a. TA ) = {(a. a. t}.Menger’s Theorem 275 vertex t). TC ) as shown in the bottom right diagram of Fig.4.7.1. The theorem states that the maximum number of edge-disjoint paths from vertex s to t is equal to the minimum number of edges of D which if removed will destroy all paths from s to t in D. By a little inspection in this graph it can easily be veriﬁed that Cut A is indeed one of the minimum cuts.

The top diagram also shows three cuts.276 Network Flows. Connectivity and Matching Problems Cut C a c a c Cut A s b Cut B d t Cut A s SA t b d a c a Cut C c s SB Cut B d t s b SC d t b Figure 6. .7: We are given a directed graph D and we intend to ﬁnd maximum number of edge-disjoint (directed) paths from vertex s to vertex t.4. The bottom right diagram shows the subset SC along with the Cut C edges shown in bold. The bottom left diagram shows the subset SB along with the Cut B edges shown in bold.

Algorithm 37 ﬁnds k pseudo edge-disjoint paths from s to t in D before it terminates. we should be able to ﬁnd the other). and go back to step number 2 to ﬁnd a new path (see Fig.7.2.1 & 6.. The maximum number of pseudo edge-disjoint paths from vertex s to t is equal to the minimum number of edges of D which if removed will destroy all paths from s to t in D. Please note that each (pseudo) path found in step number 2. Proof for Claim 6. Menger’s Theorem tells us that the two quantities (maximum number of paths and size of the minimum cut) are exactly equal. We shall make the following claims here: Claim 6. there can not be more than k pseudo edge-disjoint paths in D. If we try to maximize the number of paths from s to t they will only be limited by the bottleneck in the graph which will be the minimum cut. The maximum number of the two paths will be exactly equal (given one. TX ) where vertex s belongs to the subset SX while vertex t belongs to TX as deﬁned earlier in this section. 6. We know that number of edge-disjoint paths from vertex s to t in a graph cannot exceed the size of a cut (SX . T ) in D. the minimum cut. T )|min where the minimum is taken over all cuts (S. That means the maximum number of edgedisjoint paths from s to t in D will not exceed |(S. As we have seen before there may be diﬀerent cuts possible with diﬀerent sizes in the same graph as shown in Fig.4.Menger’s Theorem 277 Using this proof one can also ﬁnd the maximum number of edge-disjoint paths as well as the minimum cut.4.3. The number of real (not pseudo) edge-disjoint paths from s to t in D can not exceed the number of (pseudo) edge-disjoint paths from s to t in D.1. 6.4. Claim 6.2: In step number 2 of Algorithm 37 we ﬁnd a path from vertex s to t in D using any path ﬁnding algorithm.4). Claim 6. i.e.4. We then reverse the direction of each edge of the path just found. the minimum number of vertex-disjoint paths from s to t is equal to the cardinality of minimum sized vertex cut-set which will disconnect t from s in D. This proof technique can easily be adapted for undirected graphs and can also be used to prove the vertex form of Menger’s Theorem which states that.4.4.4. may consist of unused edges (not used by any path so far) or used edges (occupied by a previous path in the .

4. It is obvious that if there is a (pseudo) path left (in addition to the one’s that are already found) then Algorithm 37 will ﬁnd it before its exits.5 is duplicated in the top left corner. The bottom diagram shows the modiﬁed graph D with used edges shown in bold. Let us assume that while executing this algorithm we have reached a stage where we are no longer able to ﬁnd a new path and the Algorithm 37 terminates.4. We keep on doing this until we are no longer able to ﬁnd a path from s to t in D and then the algorithm terminates. The maximum number of pseudo edge-disjoint paths is shown in bold in the top right diagram. it shows the number of vertices (enclosed in the shaded area) which are reachable from s in D after the termination of Algorithm 37.8: The bottom left diagram of Fig. Q) will consist of edges such that each edge which is part of this cut will be occupied by a unique . Let P be a nonempty set (a subset of V (D)) containing vertex s and all other vertices which are reachable from s. 6. We deﬁne subset Q to be equal to V (D) − P .6. what we need to show now is that there will actually be a cut whose size will be equal to the maximum number of paths from s to t in D. The Cut (P. We have seen that the maximum number of pseudo edge-disjoint paths cannot exceed the size of a minimum cut. It is important to note that the vertex t will belong to Q otherwise it will be in P and then we can ﬁnd an extra path from vertex s to vertex t in D. 6.278 Network Flows. Although no (additional) path from vertex s to t exists anymore. but it still may be possible to reach a number of vertices in the modiﬁed graph D from the vertex s. a c 1 a 2 2 1 2 c 2 Pseudo Paths 1 s b P d t s b a c Edge-Disjoint Paths t Min Cut d s unused unused t b unused d Figure 6. Connectivity and Matching Problems opposite direction) as shown in the top right corner of Fig.4.

The Cut (P.4 & Fig. The above three properties guarantee that the modiﬁed graph D has as many (real) edge-disjoint paths from s to t as the number of pseudo edgedisjoint paths in the original graph D. In fact it is possible to ﬁnd the (real) edge-disjoint paths from the modiﬁed graph D (as shown in the bottom of Fig.5. 2. 6. The out-degree of s will be equal to the in-degree of t in D.5.) but also the status of every edge is provided by it. 6. When Algorithm 37 is unable to ﬁnd an extra path it terminates as shown in the bottom left corner of Fig.5. The number of paths cannot be larger than the size of this cut as discussed before.4. Thus each edge of the Cut (P. y) which is part of the cut but not part of any path from s to t in D.4. It will be a directed acyclic graph.Menger’s Theorem 279 path from vertex s to t in D. 6. Q) consists of edges all of which are already occupied by existing paths as shown in the bottom right corner of Fig.4) using (the very simple) Algorithm 36. Can the number of paths be smaller than the size of this cut? If the number of paths is smaller than the size of the cut then you can identify at least one edge (x. The Cut (P.4. Under such conditions vertex y will also be reachable from vertex s which contradicts our initial assumption.4. The set of vertices which are reachable from s (known as P ) are shown shaded in this diagram. 3. Proof for Claim 6. 6. The in-degree of every node other than the vertices s and t will be equal to its out-degree.4. 6.4.3: We have seen that the Algorithm 37 not only provides maximum number of pseudo edge-disjoint paths (see Fig.4. Q) will be part of exactly one pseudo path from vertex s to t in D. 6.4. If we remove all edges of D which have a Status = unused from D then the resulting graph D would have the following properties: 1.4 Finding Maximum Vertex-Disjoint Paths & Minimum Vertex Cut in Directed Graphs We have shown earlier that the maximum number of edge-disjoint paths (from vertex s to vertex t) in a directed graph is equal to the minimum . 6. Q) is in fact the Minimum Cut equal to the maximum number of edge-disjoint paths from vertex s to t in D.6. This situation is depicted in Fig.

9 shown below shows a directed graph H in the top left diagram. An eﬃcient algorithm to ﬁnd maximum number of vertex-disjoint paths from vertex s to t and a minimum cut in terms of vertex cut-set. A proof that maximum number of vertex-disjoint paths (from vertex s to vertex t) is equal to the minimum number of vertices which if removed will destroy all paths from vertex s to t in a directed graph. Connectivity and Matching Problems number of edges (which if removed will destroy all paths from vertex s to t).4.9: Various vertices are removed to show that the graph does not necessarily become disconnected by their removal and only speciﬁc ones make the graph disconnected. It also shows how this graph would look like if we remove a number of vertices. The Fig. There are basically two issues that we would like to tackle: 1. a s b Graph H c t d s b c t d Graph H after removing vertex a c s d Graph H after removing vertex a & b c t s b Graph H after removing vertex a & d t Figure 6.280 Network Flows.4. Please note that removal of certain vertices does not destroy all paths from vertex s to vertex t in this graph (see the top right and bottom left diagrams) while the removal of some other vertices does indeed destroy the s − t connectivity in this graph. 6. 2. . The vertex form of Menger’s Theorem equates maximum number of vertexdisjoint paths (from vertex s to vertex t) to minimum number of vertices which if removed will destroy all paths from vertex s to t in a directed graph.

For every edge (s. Similarly for every edge (x.Menger’s Theorem 281 Interestingly both these problems can be resolved using our prior experience provided we make a couple of transformations on a given directed graph H (left diagram) and convert it into another directed graph D (right diagram) as shown in Fig.4. Once the directed graph H is transformed into D it has now become possible to appreciate the following: . Algorithm 39: Transform directed graph H into directed graph D. We insert an extra edge between x1 and x2 in D for every vertex x in H except for s and t as shown here. In addition to these edges we have edges of the form (x1 . 6. a c a1 a2 c1 c2 s b Graph H d t s b1 b2 Graph D t d1 d2 Figure 6.10. there will be a corresponding edge in D as shown in brown color in the right diagram of Fig. We split each vertex x (excluding vertex s and t) of directed graph H into x1 and x2 in D. output: Directed graph D with internal & external edges marked 1 2 Convert H into D by splitting all the vertices (except s and t) as described. input : Directed graph H with special vertices s & t. 6. Thus for the new graph D we have V (D) = 2V (H) − 2 and E(D) = E(H) + V (H) − 2. Identify internal and external edges of the graph D. t) in H insert a directed edge from x2 to t in D. y1 ) in D. External edges are shown in brown color while internal edges are shown in bold orange color. each directed edge (x.10: Each vertex of the directed graph of shown in the left diagram is split up into two vertices.4. Thus for every edge in H.10 using Algorithm 39. x) in H insert a directed edge from s to x1 in D. we call these edges internal edges. Let us call these edges external edges. x2 ).4. y) in H is transformed into a directed edge (x2 . as shown in the right diagram.

6.11. The corresponding path in D passes through external as well as internal edges as shown in Fig. may pass through some of the external edges as shown in the middle right diagram in Fig. 3. There is a path from vertex s to t in D corresponding to any path from s to t in H. Connectivity and Matching Problems 1. If it passes through (some of the) external edges then the minimum cut will not correspond to a minimum vertex cut. the Minimum Cut as found by the original Algorithm 37. 6. We can use Algorithm 39 to convert graph H into graph D and then use Algorithm 37 without any change to ﬁnd the maximum edge-disjoint paths and the Minimum Cut. the corresponding path in D will pass through k internal edges. 6. 6. A Minimum (edge) Cut in graph D will correspond to a Minimum (vertex) Cut in graph H provided the Minimum (edge) Cut in D passes through internal edges only. 6. The above observations provide us enough insight to ﬁnd maximum edgedisjoint paths in the directed graph D which will correspond to maximum vertex-disjoint paths in H. We ﬁrst add the external edges of graph D in graph F and then ﬁnd the appropriate cut as shown in the bottom diagrams of Fig. the working of this approach on the directed graph D of Fig. It is important to appreciate that the minimum cut should (be forced to) pass through internal edges only.4.10 is shown in Fig.11. There is just one problem to be resolved. In order to do so we make a one line modiﬁcation in our earlier approach in terms of Algorithm 40 as described below. and thus any number of edge-disjoint paths in D will correspond to the same number of vertexdisjoint paths in the directed graph H.4. Every path going from vertex s to t in H has to pass through a number of k intermediate nodes (nodes other than s and t).11 (top left corner).11 (thereby forcing the entire cut to pass through internal edges alone).282 Network Flows. We can construct (an almost) similar constructive proof that the maximum number of vertex-disjoint paths from s to t in H is exactly equal to the minimum number of vertices which if removed from H will destroy all paths from s to t in H.4.4.4. 6.4.5 Menger’s Theorem for Undirected Graphs We shall consider Menger’s Theorem in terms of edge connectivity (Menger’s Theorem in terms of vertex connectivity can also be derived from in a similar . 2.

The reason for the step in the bottom right diagram is to ensure the Minimum Cut passes through internal edges only. to which we add the external edges of Graph D and ﬁnd the Minimum Cut. We again ﬁnd a path (blue) as shown in the middle left diagram.11: The top left diagram shows a directed graph with a selected c a path P1 from vertex s to vertex t shown in pink. Now when we reverse selected edges of this path then it is no longer possible to ﬁnd a path from vertex s to t as shown in the middle right diagram.Menger’s Theorem 283 a1 a2 c1 c2 a1 a2 c1 c2 s t s t b1 b2 d1 d2 b1 b2 d1 d2 Graph D and initial Graph F Graph F a1 a2 c1 c2 a1 a2 c1 c2 s t s t b1 b2 d1 d2 b1 b2 d1 d2 Final Graph F: Cut passing through an external edge a1 a2 c1 c2 a1 a2 c1 c2 s t s t b1 b2 d1 d2 b1 b2 d1 d2 Graph F plus External Edges of D: Cut passing through internal edges only Graph D Figure 6. The top right diagram Graph H shows selected edges of the path P1 reversed.4. This is the ﬁnal Graph F . The minimum (vertex) cut is indicated by a bold line. .

Add all the external edges of Graph D to F . The minimum cut corresponding to minimum number of edges required for destroying all paths between s and t can also be found using similar techniques as shown in the bottom left diagram of Fig. 6. It states that the maximum number of edge-disjoint paths between two speciﬁc nodes in an un-directed graph G is equal to minimum number of edges needed to destroy all paths between the two speciﬁc vertices. Minimum Cut will consist of edges (x. It is reasonable to assume that any directed path from s to t in D will consume either (x.284 Network Flows. 6.4. y) and (y. Connectivity and Matching Problems Algorithm 40: Find a Minimum Cut in a directed graph D passing through internal edges only.4. The path between s and t in G (Fig. fashion). Maximum Vertex-disjoint Paths & Minimum Vertex Cut in un-directed graphs Now considering Menger’s Theorem in terms of vertex connectivity of a graph where s and t are already given. y) of D Where x belongs to P and y belongs to V (D) − P . y} of G is thus transformed into two directed edges (x.12 is transformed into a directed graph D as shown in Fig. We can in fact use Algorithm 37 without any changes to ﬁnd maximum number of edge-disjoint paths from s to t as shown in Fig.4. An un-directed graph G is shown in Fig.13. Each undirected edge {x. input : Directed graph D with special vertices s & t and internal & external edges marked output: Internal Edges of D that belong to the Minimum Cut. The maximum number of directed edge-disjoint paths from s to t in D will be equal to the maximum number of un-directed edge-disjoint paths between s and t in G. 1 2 3 4 Convert D into F using Algorithm 37.12 along with two vertices s and t and a path from s to t shown by bold lines. 6. The undirected graph G of Fig. 6. Menger’s Theorem states that the maximum . x) in D. 6. 6.4.13. For every un-directed path between vertex s and t in G there is a corresponding directed path from s to t (or from t to s) in D.13.4. Let P be the set of vertices (of F ) reachable from vertex s in F .4. x) but not both.4.12) is also shown in bold in the top left diagram of Fig. 6.13. y) or (y.

for every vertex x there is a corresponding two vertices {x1 . We then apply the standard algorithm for ﬁnding edgedisjoint paths from vertex s to vertex t as shown in the top-right diagram of Fig. 6. The only diﬀerence from the previous procedure is that we apply Algorithm 39 to ﬁnd the Minimum Cut for vertexdisjoint paths.4. x) in D. 6. y} of G is transformed into two directed edges (x.6 Edge Connectivity and Vertex Connectivity for Undirected Graphs Edge Connectivity λ(G) of an undirected graph G is the minimum number of edges which if removed will disconnect graph G.12: This is Graph G (left diagram).14.14 is transformed into a directed graph D as shown in the middle diagram of Fig. 6. number of vertex-disjoint paths between two speciﬁc nodes in an un-directed graph G is equal to minimum number of vertices needed to destroy all paths between the two speciﬁc vertices.14 and reverse the edges. 6. 6.15 the external edges of Graph D of Fig. Thus each un-directed edge {x.4. Vertex Connectivity κ(G) of a Graph G is the minimum number of vertices which if removed will . y) and (y.14.4.4. This way in the bottom-left diagram of Fig. Then all the vertices except for s and t are split into two as shown in the bottom diagram of Fig. if we initially select a path as shown by bold red lines and then remove its edges from G then it becomes impossible to ﬁnd another path in the remaining un-directed graph (right diagram).4.14 along with two vertices s and t.4.14 are added where they do not exist in graph F (not shown in the Figure) and the minimum cut is found and applied to Graph G. |V (D)| = 2|V (G)| − 2 and |E(D)| = 2|E(G)|. The un-directed graph G of Fig. Thus the total number of vertices and edges are almost doubled. An un-directed graph G is shown at the top of Fig.4. 6. x2 }.4. 6.4.Menger’s Theorem 285 a c a c s b d t s b d t Figure 6. 6.

Connectivity and Matching Problems a c a c s b Graph D d t s b d t Initial Graph F a c a c Min Cut s b d t s b d t a c a c s b d t s b Graph D d t Final Graph F Figure 6.4. Now when we reverse the edges of this path then it is no longer possible to ﬁnd a path from vertex s to t as shown in the middle right diagram.13: The top left diagram shows an un-directed graph with a selected path P1 from vertex s to vertex t shown in bold. The minimum cut is indicated by a shaded region in the bottom diagrams.286 Network Flows. We again ﬁnd a path as shown in the middle left diagram. . The top right diagram shows the edges of the path P1 reversed.

.14: The top diagram is an undirected graph G. Each edge of this graph (is split to indicate directed edges going both ways) is replaced by two directed edges as shown in the middle diagram.4. Then each vertex other than vertex s and t is split and the graph G is transformed into a directed graph D shown in the bottom diagram.Menger’s Theorem a c 287 s b d t Un-directed Graph H a1 a a2 Directed Graph D before vertex splitting s1 c1 c c2 s s2 t1 b1 b b2 d1 d d2 t t2 a1 a2 c1 c2 s1 s s2 t1 t t2 Directed Graph D after vertex splitting b1 b2 d1 d2 Figure 6.

The middle diagram shows another path P2 (blue) found and its edges are reversed in the middle-right diagram. 6. Hence we apply Algorithm 39 and ﬁnd the minimum cut for the vertex-disjoint paths in the bottom-left diagram and that cut is applied to original Graph G of Fig. as can be seen no more paths can be found.4. Connectivity and Matching Problems a1 a2 c1 c2 a1 a2 c1 c2 s1 s2 t1 t2 s1 s2 t1 t2 b1 b2 d1 d2 b1 b2 d1 d2 Graph F a1 a2 c1 c2 a1 a2 c1 c2 s1 s2 t1 t2 s1 s2 t1 t2 b1 b2 d1 d2 b1 b2 d1 d2 Final Graph F a1 a2 c1 c2 a s1 s2 t1 t2 c s b Graph H t d b1 b2 d1 d2 Final Graph F with External Edges Figure 6. where path P1 (pink) is found and the edges of the path are reversed as shown in the topright diagram.288 Network Flows.14.4.15: The top-left diagram shows the initial graph F . .

that is. What is then the way out? Perhaps we should consider all possible (s − t) pairs in the graph G? As the graph G consists of p vertices. (We actually do it by ﬁnding maximum number of edge-disjoint paths from vertex s to t in a graph G). There is a possibility that a wrong choice for vertex s and vertex t may give you an incorrect result as shown in the following diagrams.4. t) and claim that λ(s. there could be O(p2 ) distinct pairs of vertices. The top graph shows its edge connectivity. λ(s. The bottom diagram shows the vertex connectivity of the bottom graph.4. t) is equal to the edge connectivity of graph G. t) which is equal to minimum number of edges which if removed will disconnect vertex s from vertex t in G.4. ﬁnd λ(s. Edge Connectivity a p b f g i m c e h j n d Vertex Connectivity k Figure 6. Is it possible to arbitrarily select s and t in the graphs below.Menger’s Theorem 289 disconnect graph G.16 show two undirected graphs. 6. t) = λ(G)? The problem may not be that simple as it is evident from the diagram below (Fig. We know that the maximum number of edge disjoint . For each such pair (we call it an s−t pair) we ﬁnd the maximum number of edge-disjoint paths from vertex s to vertex t in the undirected graph G. Our prior knowledge and expertise tells us that given an undirected graph G and two already selected special vertices s and t we can eﬃciently ﬁnd λ(s. The problem is to eﬃciently ﬁnd both edge connectivity and the vertex connectivity of an undirected graph G.16: The top diagram shows the edge connectivity of the top graph and the bottom one shows the vertex connectivity of the bottom graph.17). The diagrams in Fig. 6.

We select a diﬀerent vertex t in each of the p − 1 graphs and in each such graph we ﬁnd the maximum number of edge-disjoint paths from vertex s to vertex t in time equal to O(pq). t) for every diﬀerent value of t in the undirected graph as shown in the ﬁgure below. We thus have to apply the maximum edge-disjoint paths ﬁnding algorithm for all possible p − 1 pairs where s is ﬁxed while t takes on every possible value as shown in Fig. paths is equal to λ(s. Edge Connectivity of an undirected Graph We have already hinted before that in order to eﬃciently compute edge connectivity of an undirected graph.4. The problem of eﬃciently ﬁnding vertex connectivity is slightly more complex as we shall explain in the coming section.19. The next logical step should be to ﬁnd ways to reduce this complexity. t) (because of O(p2 ) distinct pairs of s−t vertices) we select the one with the minimum value and that will be the edge connectivity λ(G) of the graph. . It will be a useful experience to derive the overall time complexity of this simple algorithm. 6. Connectivity and Matching Problems 8 8 8 t t 2 1 7 6 2 7 6 2 7 6 3 4 5 1 3 4 5 s 1 4 3 5 s The Min-Cut from s to t is 2 s t The Min-Cut from s to t is 2 The Min-Cut from s to t is 1 Figure 6. You may have realized that there is no need to consider all O(p2 ) distinct pairs of vertices. we may ﬁx s arbitrarily but then compute λ(s. only O(p) pairs will be suﬃcient for calculating edge connectivity as shown in Fig. This intelligent observation will certainly cut down the time complexity of our earlier technique as described in the algorithm given below. Out of all the O(p2 ) values for λ(s.17: Various Min-cuts in the same graph. Out of all results we select the minimum. 6.4.18.290 Network Flows.4. We select a vertex s and keep it ﬁxed throughout the working of the algorithm. We repeat this process as many number of times as the number of graphs. t).

or 8 will provide the optimal answer If s is fixed at 1 then t=5.2.4.18: When does vertex s moves from one place to another? Algorithm 41: Find edge connectivity of an un-directed graph G.3. 1 2 3 4 Construct p − 1 copies of graph G numbered from 2 to p. . Ouput the minimum value of all Max-Paths.7. input : Undirected Graph G with vertices numbered from 1 to p. Find Maximum Number (Max-Paths) of edge-disjoint paths from s to t in each copy of graph G.6.7.6. or 4 will provide the optimal answer Figure 6. or 8 will provide the optimal answer If s is fixed at 8 then t=1. output: Edge Connectivity of graph G.Menger’s Theorem 291 2 3 4 5 6 8 7 Edge Connectivity 1 8 8 s 6 2 7 8 7 6 2 7 6 s 1 2 3 4 5 1 3 4 5 1 4 3 5 s If s is fixed at 2 then t=5. In the j th copy of graph G select vertex j as t where 2 ≤ j ≤ p. In every copy of graph G select vertex 1 as s.

3. We now know how to ﬁnd the magnitude of λ(G). Problem Set 6. Problem 6. Once we have solved the decision problem it becomes almost trivial to solve the corresponding optimization problem of ﬁnding the (minimum) edge connectivity of a graph.3. In every . of Max-Paths from s to t is 1 Figure 6. In fact the problem becomes a search problem in a ﬁnite search space.1. We make p − 1 copies of graph D numbered 2 to p and then ﬁx vertex s and t in each copy. of Max-Paths from s to t is 2 s t No.19: When is vertex s ﬁxed and when does vertex t change its position? The total time complexity will thus be O(p2 q).3. How about ﬁnding the actual edges belonging to the minimum sized set of edges which if removed will disconnect graph G? Problem 6. You have the option of making a linear search or a more eﬃcient binary search in order to ﬁnd the edge connectivity of a graph. of Max-Paths from s to t is 2 No.4. Try to derive the time complexity of this algorithm. So let us design an eﬃcient algorithm to solve this problem. Let us now try to make the previous algorithm more eﬃcient. In the j th copy of graph G we select vertex j as t where 2 ≤ j ≤ p. Assume that instead of ﬁnding edge connectivity (which is an optimization problem) we intend to solve the corresponding decision problem: Is the edge connectivity of graph G less than or equal to k where k is an arbitrary number and is always less than p (why?)? Of course you can use the edge-connectivity ﬁnding algorithm to solve this problem but then it will be an overkill. Connectivity and Matching Problems 8 8 8 t t 2 1 7 6 2 7 6 2 7 6 3 4 5 1 3 4 5 s 1 4 3 5 s No.2.292 Network Flows.

4.20: We make p − 1 copies of graph D numbered 2 to p and then ﬁx vertex s and t in each copy. . If we can ﬁnd k edge-disjoint paths in all copies then we move forward otherwise we exit out with the edge connectivity of the graph G.Menger’s Theorem 293 8 8 8 7 2 1 6 2 7 6 2 7 6 t t 3 5 1 3 4 5 s 1 4 3 5 s 4 s t Copies of graph G with s fixed at 1 and a different t 8 8 8 6 t 7 2 1 6 2 7 6 2 7 t 3 5 1 3 4 5 s 1 4 3 5 s 4 s t Find only One (Edge-Disjoint) Path from s to t in each graph 8 8 8 6 t 7 2 1 6 2 7 6 2 7 t 3 5 1 3 4 5 s 1 4 3 5 s 4 s t Find another (Edge-Disjoint) Path from s to t in each graph (if possible) Figure 6. Now instead of ﬁnding Max-Paths or the Min-Cut in each graph we ﬁnd k edge-disjoint paths in each copy of graph G starting from k equal to 1.

that is the minimum number of vertices which if removed will destroy all paths between vertex s and t in a given undirected graph G. input : Un-directed Graph G with vertices numbered from 1 to p. 1 2 3 4 Construct p − 1 copies of graph G numbered from 2 to p. If we can ﬁnd k edge-disjoint paths in all copies then we move forward otherwise we exit out with the edge connectivity of the graph G. t) for every possible pair of vertices in the graph G and then select the minimum (out of all O(p2 ) possible values). Algorithm 43: Find edge connectivity λ(G) of graph G. Find k edge-disjoint path from vertex s to vertex t in each of the p − 1 graphs. Try to derive the time complexity of this algorithm. Now instead of ﬁnding Max-Paths or the Min-Cut in each graph we ﬁnd k edge-disjoint paths in each copy of graph G starting from k equal to 1. Let k = 1. select s arbitrarily but allow t to have all possible values? Please concentrate on the following algorithm (Algorithm 44) . we shall get the vertex connectivity κ(G) for graph G. Increment k and go to step 3. If you can not ﬁnd k edge-disjoint paths in any one of p − 1 graphs then exit with edge connectivity λ(G) = k − 1. The modiﬁed Algorithm 43 is described below. Vertex Connectivity of an undirected Graph We know how to ﬁnd κ(s.294 Network Flows. How about if we use the same complexity cutting strategy used in ﬁnding the edge connectivity. In the j th copy of graph G select vertex j as t where 2 ≤ j ≤ p. output: Edge Connectivity λ(G) of graph G. Connectivity and Matching Problems Algorithm 42: Find if the edge connectivity λ(G) of a graph G less than or equal to k? input : An un-directed graph G output: Yes/No 1 ? copy of graph G we select vertex 1 as s. In every copy of graph G select vertex 1 as s. If we ﬁnd a κ(s. t).

6. That means we should change s and again apply this algorithm but we need not do this repetition more than the latest output of our algorithm. The output of the above algorithm will not be equal to the vertex connectivity of the given graph but it will still give us an upper bound on vertex connectivity. Assume that the algorithm (Algorithm 44) is applied to the graph shown below.21: Original Graph G The ﬁgure shows that if s is initially selected as g (or h) in this graph then the output of this algorithm will be 3 which is a wrong answer for vertex connectivity. input : Undirected Graph G with vertices numbered from 1 to p. The vertex connectivity κ(G) of this graph is also indicated here.21) is shown in Fig.4. a p b f g s i m e h s j n d k Figure 6. output: Vertex Connectivity κ(G) of graph G? 1 295 2 3 Construct p − 1 copies of graph G numbered from 2 to p. t)’s .4. 6. The outcome of the above algorithm when applied to this graph (Fig. t) in every graph.4. In the j th copy of graph G select vertex j as t where 2 ≤ j ≤ p. In every copy of graph G select vertex 1 as s. You can easily generalize these observations. Output the minimum value of all κ(s. if we select s among the vertices which belong to the minimum sized vertex set (which if removed will disconnect graph G) then our algorithm will provide an incorrect estimate for vertex connectivity.Menger’s Theorem Algorithm 44: Find vertex connectivity κ(G) of graph G. Any other choice for vertex s will always provide us the correct answer in this graph. How this intelligent strategy cuts down the . Find κ(s.22.

.296 Network Flows. Connectivity and Matching Problems time complexity will be interesting to explore.

n or p then κ(s.4.c.t) will not provide the Optimal answer f e p s g s h i j s g s h i j k m n t t a p f e a m n b c d If s = g and t = h then κ(s.Menger’s Theorem 297 a Min-Cut p g h i j t k m n b c a f e Min-Cut p s g h i j k m n s b c d f e t d If s is fixed at a.m.e.k. or f then κ(s.b.k.c.t) will provide the Optimal answer a b c f e d If s = g and t = c then κ(s.e.b.j. or f and t = i.n or p and t = a.j.t) will not provide the Optimal answer p If s is fixed at i.d.t) will not provide the Optimal answer Figure 6.22: The arbitrary pair s and t are used to ﬁnd the Min Cut for vertex-disjoint paths between each pair of s and t and then the minimum value of those p cuts is chosen to ﬁnd Vertex Connectivity of the graph as a whole.d.m.t) will provide the Optimal answer a m n k b c d If s = g and t = e then κ(s.t) will not provide the Optimal answer f e p t b c d s g s h i j k s g t h i j k m n If s = g and t = b then κ(s. .

6. We ﬁnd maximum edge-disjoint paths from s to t in the graph D as shown in the bottom right diagram of this ﬁgure. We transform this graph into a directed graph D after adding vertices s and t as shown in the left diagrams in Fig. Menger’s Theorem & Hall’s (Marriage) Theorem Revisited We have earlier proved Menger’s Theorem which states that the maximum number of edge-disjoint (vertex-disjoint) paths from vertex s to t in a directed graph D is equal to the minimum number of edges (vertices) of G which need to be removed in order to disconnect vertex t from s. The directed graph D with maximum number of edge-disjoint paths is transformed into a directed graph F after the direction of each path in D is reversed as shown in the top left diagram of Fig.1. We shall. Each path from vertex s to vertex t in this diagram corresponds to a matching edge in the bipartite graph B as shown in the top right diagram of this ﬁgure. This theorem is applicable to any graph while the other two theorems (Hall’s Theorem and Konig’s Theorem) are applicable to bipartite graphs only.5. Let us now start with an (undirected) bipartite graph B. 6. Every edge-disjoint path from vertex s to t in the graph D is in fact a vertex-disjoint path between the same two vertices. . The following observations will help us in proving the remaining two theorems. If you cannot ﬁnd an additional path from vertex s to vertex t in graph D then it means that you can not improve the size of the existing matching in the bipartite graph. Thus the maximum number of paths between vertex s and t in G will be equal to the size of the maximum matching in the bipartite graph. refer to these paths as paths only and not vertex-disjoint or edgedisjoint paths. 2.298 Network Flows. Thus maximizing number of paths in D is equivalent to ﬁnding maximum matching in B. The minimum cut in terms of number of edges will be equal to the minimum cut in terms of minimum number of vertices. therefore. 3.5 Konig’s Theorem. Connectivity and Matching Problems 6. 1. namely Konig’s and Hall’s Theorem.2.5. There will be a path between vertex s and t in D corresponding to every matching edge in the bipartite graph B.

5.Konig’s Theorem.1: The top left diagram shows a bipartite graph B. Maximizing number of paths in D is equivalent to ﬁnding maximum matching in B. The bipartite graph is transformed into a directed graph D with additional vertices s and t as shown in the bottom left diagram. Corresponding to each edge-disjoint path from vertex s to vertex t in the directed graph D. We ﬁnd maximum number of edgedisjoint (or vertex-disjoint) paths in graph D as shown in the bottom right diagram. Menger’s Theorem & Hall’s (Marriage) Theorem Revisited 299 a1 a2 A a3 a4 b1 b2 B b3 b4 A a1 a2 a3 a4 b1 b2 B b3 b4 Bipartite Graph B Transforms Maximum Matching in Graph B Transforms Directed Graph D with nodes s & t Maximum Paths in Graph D a1 a2 b1 b2 B b3 Find Max-Paths a1 a2 b1 b2 s A a3 a4 t s A a3 a4 b3 b4 t b4 Figure 6. . there is a matching edge in the bipartite graph as shown in the top right diagram.

The bottom left diagram shows the set Y containing (minimum number of) vertices which if removed will destroy all paths from vertex s to t in the directed graph. these vertices form the set P .300 Network Flows. The set Y is in fact the vertex cover in the bipartite graph shown in the bottom right diagram. Connectivity and Matching Problems P a1 a2 b1 b2 B b3 b4 a1 a2 b1 b2 s A a3 a4 t s a3 A a4 b4 b3 t Graph F: Nodes Reachable from s are in P Partition P in Graph D P a1 X N(X) b1 b2 a1 a2 b1 b2 a2 s a3 A a4 b4 Set X: Vertices common in A & P t b3 s a3 Min-Cut A-X t b3 b4 a4 Neighborhood of X & the Min-Cut a1 X Y b1 b2 a1 a2 b1 b2 B b3 b4 a2 s a3 a4 b3 b4 t A a3 a4 Set Y= Minimum Vertex Cut in D Set Y= Minimum Vertex Cover in B Figure 6. The middle right diagram shows the minimum cut.5. . However it is still possible to reach some vertices from s.2: The top left diagram shows directed graph D where it is no longer possible to ﬁnd an additional path from vertex s to t. The set X contains those vertices which are common in the set P and the partite A.

The minimum cut in terms of edge-disconnecting set will be edges from s to A − X and from N (X) to t as shown in the middle right diagram of Fig. This set (A-X +N(X)) is denoted by Y in the bottom left diagram of Fig.3. 5.5. Problem Set 6.1. It is ﬁrst transformed into a directed graph D as described earlier.2. 6. The neighborhood N (X) of X is shown in the middle right diagram of this ﬁgure. If the set P does not contain any vertex of A then it implies that the number of paths from s to t is equal to the degree of node s in the graph. Let X represents vertices which are common between P and the partition A as shown in the middle left diagram of the same ﬁgure. The same set Y is in fact the vertex cover in the bipartite graph in the bottom right diagram.4.4 below shows a bipartite graph B in the top left diagram. Under such conditions the size of the maximum matching will be (at least one) less than the size of partition A. The size of the minimum cut will thus be equal to the size of A − X and N (X). The minimum sized vertex-disconnecting set in the graph D will correspond to the vertex cover in the bipartite graph B. It also implies that every vertex belonging to A is matched to a vertex in B in the corresponding bipartite graph.4. 6. we ﬁnd maximum edge-disjoint paths in D. 6. 8. There are two major cases to be considered as shown in Fig.2.5. 7. If the set P contains a vertex x belonging to A then obviously vertex x is not matched to a vertex in the B in the maximum matching of the bipartite graph.Konig’s Theorem. then reverse the direction of each path. 6.5. Each matching edge in the bipartite graph corresponds to a .5. 6. 6. The size of the minimum cut in terms of vertex-disconnecting set will be A − X + N (X) .5. Let P represent the vertices which are reachable from vertex s once we have found maximum number of paths and it is no longer possible to ﬁnd an additional path from s to t in D as shown in the top left diagram of Fig.2. the resulting directed graph F is shown in the top right diagram of this ﬁgure. Obviously P will not contain t (why?). Problem 6. 9. Menger’s Theorem & Hall’s (Marriage) Theorem Revisited 301 4. The Fig.

302 Network Flows.3: Hints for a proof of Hall’s Theorem .5. Connectivity and Matching Problems All vertices of A not matched in the Bipartite graph Implies Number of Paths less than size of A a1 a2 A a3 a4 b1 b2 B b3 b4 a1 a2 b1 b2 B b3 b4 s A a3 a4 t Case 1: From s you can reach a vertex of A Partite but not to a vertex of B Partite in the graph F a1 a2 A a3 a4 b1 b2 B b3 b4 a1 a2 P b1 b2 B s A a3 a4 b3 b4 t Case 2: From s you can reach a vertex of A Partite as well to a vertex of B Partite in graph F Figure 6.

5. there is a directed path from vertex t to vertex s corresponding to each matching edge in B. For each bipartite graph (with a maximum matching indicated) draw the corresponding graph F . . It further implies that we have found the maximum matching in the bipartite graph B. A − X. N (X). Also ﬁnd the minimum cut in terms of vertices as well as edges. The ﬁgure shown above (Fig. X.4) shows two diﬀerent maximum matchings of the same bipartite graph B in the bottom diagrams.4. It is interesting to note that all vertices belonging to P . Menger’s Theorem & Hall’s (Marriage) Theorem Revisited 303 directed path from vertex t to s in F .4: Problem 6. It is quite obvious that now it is no longer possible to ﬁnd an additional path in the graph F . are part of a directed cycle containing vertex s. a1 a2 A a3 a4 b1 b2 B b3 b4 Transforms a1 P a2 b1 b2 s a3 a4 b3 b4 t a1 a2 A a3 a4 b1 b2 B b3 b4 A a1 a2 a3 a4 b1 b2 B b3 b4 Figure 6.Konig’s Theorem. Find the set P.5. You know that in graph F . All vertices which are still reachable from vertex s belong to the set P which is also indicated in the right diagram. Find the minimum cut in terms of edges as well as vertices of F . 6.2. and A − X in the graph F . Find the sets X. and N (X).

The ﬁgure shown below (Fig.4. The left diagram of Fig.5: Problem 6.7) shows a bipartite graph B with maximum matching edges shown in diﬀerent colors.3.5. Under such conditions vertex s will be part of a directed cycle. The right diagram shows the same bipartite graph with two extra vertices s and t added to it.4. Connectivity and Matching Problems Problem 6. The corresponding graph F showing reversed paths is shown on the right side of each bipartite graph. Is this a coincidence in this bipartite graph or will it always be true. Prove or give a counter example.304 Network Flows. 6. known as the set P is also indicated in each graph F .4. such that the number of vertices of partition A in the cycle will always be one larger than the number of vertices of partition B belonging to the same cycle. We show a bipartite graph with two diﬀerent maximum matchings in Fig.4. Note that the bipartite graph B in this problem is transformed into an un-directed graph G instead of a directed graph D.5. Problem 6. It is obvious that corresponding to every matching edge in this bipartite graph.5.5. 6.5 shows a bipartite graph with maximum matching edges indicated in diﬀerent colors.6. It is obvious that the maximum matching in this bipartite graph is not a perfect matching – all vertices of partition A are not matched. The set of vertices reachable from vertex s. there is a path from .5. 6. It is quite evident from these diagrams that for diﬀerent maximum matchings in the same bipartite graph we get the same set P . Can we prove this observation in general or is this localized to this graph only? What are the implications of this observation? Is this something to do with the proof of Hall’s Theorem? a1 a2 a3 a4 b1 b2 a1 a2 b1 b2 s b3 b4 a3 a4 b3 b4 t Figure 6.

6: .5. Menger’s Theorem & Hall’s (Marriage) Theorem Revisited 305 a1 a2 a3 a4 b1 b2 a1 a2 b1 b2 s b3 b4 a3 a4 b3 b4 t a1 a2 a3 a4 b1 b2 a1 a2 b1 b2 s b3 b4 a3 a4 b3 b4 t Figure 6.Konig’s Theorem.

6. Do you think that corresponding to every edge-disjoint path between vertex s and t in this undirected graph.5.1 Network Flows Finding Maximum Edge-Disjoint Paths in MultiGraphs We consider here the problem of ﬁnding maximum number of edge-disjoint paths (and a minimum cut in terms of edges) from a vertex s to a vertex .6 6. there will be a corresponding matching edge in the bipartite graph B? Either prove or give a counter example. Assume that we convert a bipartite graph (any bipartite graph – not necessarily the one shown in Fig. a1 a2 a3 a4 b1 b2 a1 a2 b1 b2 s b3 b4 a3 a4 Graph G t b3 b4 Bipartite Graph B Figure 6. Connectivity and Matching Problems between vertex s and vertex t in the graph G (Is this one to one correspondence between a matching edge in the bipartite graph and an edge-disjoint path in graph G a general phenomena or is it restricted to this bipartite graph? We shall address this issue in the next problem). We ﬁnd maximum edge-disjoint (or vertexdisjoint) paths between vertex s and vertex t in graph G.4.6.6.306 Network Flows. Find the minimum edge cut & minimum vertex cut in graph G and show that it is equal to the size of the vertex cover in this bipartite graph B.7) into an undirected graph G as shown in the ﬁgure above. 6.5.7: Problem 6.

6. For example if P = (s → a → d → t) as shown in the top left diagram of Fig. for every edge e in path P do set Status(e) = used if initially it was unused otherwise set Status(e) = unused. Status(e) = unused for every directed edge e in D. It will be useful if we spend some time on the selection of a suitable data structure to represent . If you are successful in ﬁnding a path P then keep a record of the number of paths found so far otherwise exit with graph F as output. and vertices s & t. We designed this algorithm to ﬁnd maximum edge-disjoint paths in a directed graph. Reverse the direction of edge e and then go back to step 2.1 then we have not one but three edgedisjoint paths passing through the same vertices.6. This may be possible without damaging the original character of our algorithm. How this will cut down the time complexity of our modiﬁed approach? We have asked you to derive the time complexity of this algorithm (with or without modiﬁcation) when applied to Multi-graphs. calculating the resulting time complexity would be interesting? We can certainly make adjustments in order to increase the eﬃciency of our earlier approach. We assume that there are no self loops but parallel edges are allowed in the directed multi-graph. We can use our earlier algorithms to solve this problem. Find a directed path P from vertex s to vertex t in F . Algorithm 45: Find Maximum pseudo edge-disjoint paths from s to t in directed graph D. Whenever we ﬁnd a path P from vertex s to a vertex t according to step number 2 of this algorithm we ﬁnd the vertices through which P passes. 1 2 3 4 Copy Graph D into F . output: Maximum pseudo edge-disjoint paths from s to t in D and a Status(e) for every directed edge e of D.Network Flows 307 t in a directed multi-graph. input : Directed graph D. We reproduce an earlier algorithm below for a ready reference. all paths parallel to P (that means passing through the same set of vertices) can be discovered right away. Instead of ﬁnding these paths sequentially (strictly according to this algorithm) we should be able to do it in one go as shown in the same ﬁgure.

1: The top left diagram shows a multi-directed graph with three selected paths from vertex s to vertex t shown in bold. Connectivity and Matching Problems a c a c s b Graph D a c d t s b d t Initial Graph F a c s b d t s b d t a c a c s b a d c t s b d t a c s b d t s b Graph D d t Final Graph F Figure 6. .6. The minimum cut is also indicated in the bottom diagrams. The bottom right diagram shows a stage when it is no longer possible to ﬁnd an additional path from s to t in this graph.308 Network Flows. We then ﬁnd another path and reverse the direction of its edges. The top right diagram shows the edges of these paths reversed.

Network Flows 309 a multi-graph.1. The left diagram of Fig. That is in fact a more serious problem (than having a less eﬃcient algorithm). The weight of each edge (x.6. The right diagram shows how it can be represented by a weighted graph. Why has this happened? How can we over come this shortcoming? a c 3 a 4 c 2 3 s b d t s 1 3 t d 4 b 1 Figure 6. it implies that your algorithm is no longer an algorithm but a technique? Remember that in an algorithm the complexity depends upon the number of vertices and edges of a graph and does not depend upon the edge weights in the graph while in a technique it may depend upon edge weights as well. y) in this weighted graph corresponds to the number of edges from vertex x to vertex y in the un-weighted multi-directed shown in the left diagram. y) in this weighted graph corresponds to the number of edges from vertex x to vertex y in the un-weighted multi-directed graph shown in the left diagram. Note that this graph (shown in the right diagram) is a simple graph with no parallel edges. .6.2: The left diagram shows the un-weighted multi-directed graph of Fig. the weight of each edge (x. 6.6. and can conveniently be represented by a weighted adjacency list or adjacency matrix data structure. 6. The right diagram shows how it can be represented by a simple weighted graph.2 reproduces the multi-directed graph of Fig.1.6. How can we exploit this data structure in order to use Algorithm 45 (eﬃciently) to solve the edge connectivity problem? When you derive the time complexity of Algorithm 45 (or its modiﬁed version) you may realize that the complexity expression may depend upon the graph edge weights in addition to the size of the problem (that means number of vertices and edges). Please note that it is an un-weighted graph. 6.

The maximum ﬂow in a . which means that whatever ﬂow goes into an intermediate vertex is equal to the ﬂow coming out of that vertex and no new ﬂow is generated by the vertex itself. If (u. The network ﬂow problem is to ﬁnd the maximum ﬂow which can take place from the source vertex to the sink vertex such that the ﬂow f (u. v). T ) and some ﬂow in the direction from t to s which is represented by f (T. v) is a directed edge then the capacity of this edge is denoted by c(u. v) taking place in any edge (u.2 The Maximum Flow & the Minimum Cut We are given a network which is essentially a weighted directed graph with two special vertices (a source vertex) s and (a sink vertex) t as shown in Fig. whereas in the case of s and t the ﬂow going out of s is absorbed by the ﬂow going into t. v). T ) − f (T. S). 6.6. All vertices other than the source or the sink (known as intermediate vertices) can neither generate any ﬂow nor consume any ﬂow. that is.3. Each directed edge is weighted with a positive integer. Let us assume that (S. Then the ﬂow taking place on the cut from S to T will be donated by (S. 3. v) does not exceed the capacity of the edge. c(u. T ) while the ﬂow taking place from T to Swill be represented by (T < S). T ) is a cut in the network such that the source vertex s belongs to set S while the sink vertex t belongs to set T . Thus the network ﬂow f (N ) is given by the equation: f (N ) = f (S. The network ﬂow f (N ) taking place in a network graph N is equal to the net ﬂow coming out of the source vertex s or the net ﬂow consumed in the sink t. The net ﬂow coming in or going out of a vertex other than s to t is zero.6. 2. There are a number of following related problems and issues with network ﬂows: 1. the network ﬂow f (N ) is the diﬀerence between the two. Hence every cut will have some ﬂow in the direction from s to t represented by f (S. the weight of the edge is known as the capacity of the edge.310 Network Flows. S) . The net ﬂow coimng out of the source verex s is greater than zero while the netﬂow sinking in the sink vertex t is also ﬁnite. We assume that ﬂow can originate from the source vertex and can be consumed by the sink vertex. It means that the incoming ﬂow through an intermediate vertex is exactly equal to the outgoing ﬂow through that vertex. Connectivity and Matching Problems 6.

The Fig. the curious reader may have realized that the algorithm for ﬁnding maximum edge-disjoint paths for multi-graphs can be used to ﬁnd maximum ﬂow as well the minimum cut in the network.Network Flows 311 network is achieved through maximizing the ﬂow in one direction (that is f (S. In every network the value of the maximum ﬂow is equal to the capacity of a minimum cut. Given a network it is possible to eﬃciently ﬁnd the maximum ﬂow and the minimum cut in the network. 4. The ﬂow f (N ) in the network is bounded by the expression: f (N ) ≤ min{c(S. Here we apply our earlier techniques of ﬁnding maximum edge-disjoint paths in a . 6. 5.6. a 3 4 c 2 3 3/3 a 1/4 c 1/2 s 1 3 t d 4 s 1/1 1/3 2/3 t d 4/4 b 1 b 1/1 Figure 6. we have brieﬂy talked about this issue before and shall try to settle it now.4 shows a network graph with upper bounds on edge ﬂow. T )} where the minimum is taken over all cuts (S. It also shows the maximum ﬂow and the minimum cut.6. 6. and minimizing the ﬂow in the opposite direction (that is f (T. T ) in N .6. 6. one serious problem regarding (the complexity of) this algorithm.3: The left diagram shows a network ﬂow graph with the capacity of each directed edge shown. This relationship is described by the famous MinCut-MaxFlow Theorem. The right diagram shows the actual ﬂow taking place in an edge divided by the capacity of that edge. T )). S)).3 Algorithmic Issues & Complexity Calculations Although we have not formally described an algorithm to ﬁnd a maximum ﬂow in a network in the last section. There is however.

Let us ﬁrst ﬁnd out what extra price we have to pay if we do not use BFS. every cut cuts a number of edges which if removed will destroy all paths from vertex s to vertex t. The path goes from s to 1 to 2 and then to t. We apply our earlier technique of ﬁnding any path (not necessarily shortest) from vertex s to vertex t in this network. Here the time complexity has become dependent not only on the size of the problem but the magnitude of the numbers involved.6. In other words the time complexity does not depend upon the magnitude of the upper bound on ﬂow at least in this example. Please note that if the upper bound on ﬂow in every edge is 3000 instead of 3 – even then we have to apply the same number of steps to ﬁnd the maximum ﬂow.5 shows various stages of the working of our algorithm while it is trying to ﬁnd a maximum ﬂow in the network. We reverse its edges and then take another path – this time it goes from vertex s to 2 to 1 to t. we use breadth ﬁrst search – thus ensuring that we ﬁnd a shortest path in terms of number of edges. 6.5 below shows the same network graph. We also show a number of cuts in this graph. therefore rely on our earlier techniques. The maximum ﬂow and the minimum cut are found after applying BFS twice in this graph. 6. 6.6. Connectivity and Matching Problems directed graph with just one important diﬀerence – whenever we ﬁnd a path from vertex s to vertex t. The Min-Cut passes through minimum number of edges while the .312 Network Flows. In fact. it can be proved that application of BFS (a minor change in our algorithm) ensures (something really big) that the time complexity of the resulting algorithm will not depend upon the magnitudes of the upper bounds on ﬂow – it will only depend upon the size of the problem. The Fig.4 Lower Bounds on Edge Flows and the Max-Cut We show a directed graph with two special vertices known as s and t in the Fig.6. Fig. 6.6 below. We ﬁnd another shortest path from s to 2 to t in the second step – again a ﬂow of 3 units is possible in this path. This time we take a longer path from vertex s to vertex t. The algorithm ﬁnally converges and we get the correct answer but after passing through a number of iterations proportional to k where k is an upper bound on ﬂow in the network.6. In the shortest path we move from vertex s to 1 and then to t – thus ensuring a network ﬂow of 3 units from the source to the sink as shown in the top right diagram of this ﬁgure. Unfortunately the said proof and the resulting time complexity calculations are beyond the scope of this book – we.

6.Network Flows 313 3 3 1 3/3 3/3 0/1 s 3 t 3 s 0/3 t 0/3 3/3 3/3 0/1 3/3 3/3 0/1 s 3/3 t 3/3 s 3/3 t 3/3 Figure 6. .4: While ﬁnding a path from vertex s to vertex t we do use BFS. we show the resulting repercussions.

6.314 Network Flows.5: While ﬁnding a path from vertex s to vertex t we do not use BFS. . it shows the resulting repercussions. Connectivity and Matching Problems 1 3 3 1 2 1 3 s 3 t 3 s 3 1 t 2 2 2 2 2 2 1 1 2 s 1 t s 1 t 2 2 2 2 2 2 1 2 2 3 1 2 s 2 1 t 2 s 2 1 t 3 2 2 3 1 3 3/3 1 3/3 s 1 t 3 s 0/1 t 3 2 Min-Cut 3/3 2 3/3 Figure 6.

Food for thought If we intend to ﬁnd a Max-Cut in a network ﬂow graph then why not remove all edges of the graph .7). Interestingly the Max-Cut in a graph ia also important.6: The left diagram shows various cuts which disconnect graph and the right diagram shows the Min-Cut for this graph.6. Please note that we have already described an eﬃcient algorithm to ﬁnd a Min-Cut or maximum edge-disjoint paths in a graph. Remember the (size of the) Min-Cut speciﬁes the maximum number of (edge-disjoint) paths where each edge is traversed at most once. As it is clear from its name Max-Cut passes through maximum number of edges which if removed will destroy all paths between vertex s and t in the graph. 6.6). The (size of the) Max-Cut speciﬁes the minimum number of paths from vertex s to t where each path passes through every edge of the graph at least once (see the right diagram of Fig. The Max-Cut is indicated in the diagram above and is replicated again in Fig.the source vertex will certainly be separated from the sink vertex and the size of the cut will be maximum? Please think about this strategy and ﬁnd what is wrong with this otherwise simple approach? We now address the problem of how to ﬁnd Max-Cut and minimum number .Network Flows 315 Max-Cut passes through maximum number of edges. Min-Cut Figure 6.6.6.7.6. 6. 6. The size of the Min-Cut in this graph is only two and thus there are only two edge-disjoint paths in this graph (between s and t) which are also indicated in the right diagram shown below (Fig. The size of the MinCut speciﬁes the maximum number of edge-disjoint paths between s and t in a graph (according to Menger’s Theorem).

The maximum ﬂow and the corresponding minimum cut are shown in the right diagram of the same ﬁgure. In other words we need to ﬁnd the maximum cut in the network graph D that will disconnect vertex t from vertex s in D.6.6. 6.9 except that each weight associated with an edge in this network graph signiﬁes not the upper bound but a lower bound on the ﬂow that can take place through that edge. and we need to maximize the total ﬂow taking place in the entire network. We have earlier discussed the network ﬂow problem where each edge has an upper bound on the amount of the ﬂow that can take place. It may have become obvious now that if we can solve the problem of ﬁnding a Max-Cut and Min-Flow in a network graph with lower bounds on edge . of paths between vertex s and vertex t in a given directed acyclic graph. Instead of devising an entirely new algorithm let us explore if we can solve the problem using existing or modiﬁed algorithms.6.7: The left diagram shows the Max-Cut for the graph and the right diagram shows the minimum number of paths where each path passes through every edge of the graph at least once.6. The Fig. The minimum ﬂow and the corresponding maximum cut are indicated in the right diagram of Fig. The intellectual exercise of reducing one problem into another is always an exciting venture – especially when the similarity between the two problems is not so obvious. where each edge is traversed at least once.8 shows a network graph D with the maximum capacity of each edge indicated. 6. We show the same network graph with the same edge capacities in Fig. 6.316 Network Flows. Connectivity and Matching Problems Max-Cut Max-Cut Figure 6.9. The problem is to ﬁnd a minimum ﬂow in this graph such that the ﬂow taking place through any edge does not go below the lower bound of that edge.

6.Network Flows 317 4 3 2 3 1 1 3/3 1/4 1/2 Min-Cut 1/1 1/3 1/1 Size of the Maximum Flow and Minimum Cut in the Network = 5 2/3 4/4 s 3 t 4 s t A Network Graph D with Upper Bounds on Edge Flow Figure 6.9: The left diagram shows the lower bound for the capacity of each edge and the right diagram shows the Minimum Flow and Max-Cut for the same graph. 4 3 2 3 1 1 A Network Flow Graph D with Lower Bounds on Edge Flow 4 7/3 4/4 4/2 Max-Cut 3/3 1/1 3/1 Size of the Minimum Flow and Maximum Cut in the Network = 11 s 3 t s 3/3 7/4 t Figure 6.8: The left diagram shows the capacity of each edge and the right diagram shows the corresponding Maximum Flow and Min-Cut for the graph. .6.

Then we try to increase and maximize the ﬂow from vertex s to vertex t in the network. The weight of any edge signiﬁes the lower bound of ﬂow that can take place through that edge. y) for every edge (a. Algorithm 46 ﬁnds an acceptable ﬂow through the network D. Now when we have lower bounds on ﬂow that can take place through any edge then we should start with a large acceptable ﬂow – large enough that the lower bound (or limit) on ﬂow through any edge is not violated. b) in path P do Push an additional ﬂow in the entire path P equal to the lower bound on edge (x.318 Network Flows. It requires that the total ﬂow coming towards a vertex should be exactly equal to the total ﬂow going out of that vertex (except for vertices s and t in the network). The weight of each edge signiﬁes an actual and acceptable ﬂow taking place through that edge. 6. Please note that an acceptable (or legal ﬂow) shown in the right diagram of Fig. 1 2 3 4 for every directed edge (x. we assume that the lower bound on ﬂow through each edge is equal to 1. Connectivity and Matching Problems capacities then we can also solve the problem of ﬁnding minimum number of paths between vertex s and vertex t in a given directed graph where each edge is traversed at least once. input : A weighted directed network graph D with vertices s and t.10 is not a minimum ﬂow taking place from vertex s to t in the network.10. A zero ﬂow through every edge is a possible answer. y) in graph D do Find a path P from vertex s to vertex t in graph D passing through edge (x.6. y) . We should be careful about one thing – the conservation of the ﬂow taking place in the network. Remember when we have (only) an upper bound on ﬂow that can take place through any edge in a network then we start with a small acceptable ﬂow – so small that it can take place through every edge without violating any bounds. The input as well as the output networks of this algorithm is shown in Fig.6. Algorithm 46: Find an acceptable (not necessarily minimum) ﬂow from vertex s to vertex t in a given network graph D. 6. output: A weighted network graph D.

Instead of minimizing this ﬂow directly we do so indirectly – by pushing an opposite ﬂow taking place from vertex t to vertex s in D as shown in the Fig. The maximum ﬂow taking place through any edge (y. The . 6. We start with an acceptable ﬂow in the network graph D as shown in the top left diagram of Fig.11.6. We ﬁnd the maximum ﬂow in graph F taking place from vertex t to vertex s as shown in the middle left diagram.6. x) in graph F with a weight equal to w −c(x.Network Flows 319 1 1 1 3 2 2 1 2 s 1 1 1 1 t 1 s 2 2 t 5 Given Directed Graph D with Lower Bounds on Edge Flow An Acceptable Flow: the weight w of an edge shows how much actual flow is taking place Figure 6. x). It means that all vertices as well as directed edges of D are copied in directed graph F . For every edge (x. 6.6.6. now we need to minimize it. x) in this graph is represented by m(y. y).10: The left diagram shows the input graph to Algorithm 46 and the right diagram shows one of the possible output for the algorithm.11. We copy graph D into graph F without any edge weights. there is an additional directed edge (y. After we have found an acceptable ﬂow from vertex s to vertex t in the network graph D. y) in the graph D. The resulting graph F is shown in the top right diagram of Fig. The network graph D is converted into a directed graph F as follows: 1. y) in D with a weight equal to w. The Min-Cut in graph F from vertex t to vertex s is shown in the middle right diagram. 2. The weight of each edge in this diagram shows how much actual ﬂow is taking place in this network without violating any lower bound on ﬂow taking place in any edge.11 below. 6. y) is the lower bound on ﬂow that can take place in the edge (x. where c(x.

11: The diagram shows the entire process of ﬁnding the MaxCut for the graph by minimizing the ﬂow(middle left diagram) after the acceptable ﬂow (left-right diagram) which eventually leads to ﬁnding the Max-Cut for the graph (in the bottom-right diagram). Minimum Flow from s to t in D = 4 Size of the Max-Cut from s to t in Graph D = 4 Figure 6.320 Network Flows.6. . Connectivity and Matching Problems x 3 2 y 2 2 x 1 y 1 s 2 2 2 1 5 t s 1 1 0 4 1 t An Acceptable Flow in D: the weight w of an edge shows how much actual flow is taking place through this edge Directed Graph F: the weight of a black edge shows an upper bound on edge flow x 1/2 1/1 y 1/1 1/2 1/1 1/1 Min-Cut s 1/1 1/1 0 2/4 1/1 t s 1/1 1/ 1 0 2/4 1/1 t Maximum Flow from t to s in Directed Graph F = 3: Size of the Min-Cut from t to s in Graph F = 3 x 2 1 y 1 Max-Cut s 1 1 1 t 3 s t 1 The weight of an edge is equal to the Acceptable Flow in D minus the Maximum Flow in F in that edge.

y) is equal to w(x. . 6. The Max-Cut in the graph D from vertex s to vertex t is shown in the bottom right diagram. Here the weight of an edge (x. y) − m(y.6. the size of the two cuts are however diﬀerent as is evident from Fig.11. x). Please note that the Max-Cut in D from s to t cuts the same edges as the Min-Cut in graph F from vertex t to vertex s.Network Flows 321 corresponding minimum ﬂow in the graph D is shown in the bottom left diagram.

Network Flows.5. Connectivity and Matching Problems Problem 6. Problem 6.5. . We are given a directed network graph D with special vertices s and t. 6.3. prove that this algorithm always ﬁnds the correct result or ﬁnd a counter example.6. (b) An acceptable ﬂow exists if and only if the ﬂow through any edge does not exceed its upper bound. We are given a network graph D with special vertices s and t as in Fig. Problem 6. Problem 6.5. How can you design an eﬃcient algorithm which will output either yes or no. we assume that the lower bound as well as upper bound is the same for each edge although the two bounds may be diﬀerent from each other.322 Problem Set 6. We need to ﬁnd minimum number of paths from vertex s to vertex t such that each vertex of D is traversed at least once by any of the s − t paths.5.5. (b) If an acceptable ﬂow is possible and is provided to you then ﬁnd a maximum ﬂow in this network.5. Such graphs (where an acceptable ﬂow) is possible have a special structure as we shall study in coming chapters. Now Musharraf insists that his algorithm will ﬁnd an optimal answer for the ﬁrst problem in this problem set.12.6. We are given a network graph D with special vertices s and t.4. We need to make sure that a same ﬁxed amount of ﬂow should take place through every directed edge in that graph. How about if the lower bound is a positive number (it may be diﬀerent for diﬀerent edges) while the upper bound on ﬂow is the same for all edges? Repeat the earlier problem for this new situation.2. Either prove that Musharraf is right or ﬁnd a counter example. (c) If an acceptable ﬂow is possible then ﬁnd a minimum ﬂow in this network.1. Each edge in this network has a lower as well as an upper bound on edge ﬂow.12. Kashif ﬁnds the following counter example for the above problem as shown in the ﬁgure below (Fig.5.6. 6. Problem 6. (a) Design an eﬃcient algorithm to ﬁnd if an acceptable ﬂow is possible in this network. Musharraf designed the following intelligent algorithm to ﬁnd an acceptable ﬂow provided it exists in the network graph of the above problem: (a) Initially ignore the upper bound on each edge and ﬁnd a minimum ﬂow in the network (from vertex s to vertex t) keeping into account the lower bounds on ﬂow through each edge.5. Problem 6. yes in case an acceptable ﬂow is possible and no in case it is not possible? A special case of this problem is when the ﬁxed ﬂow through every edge is exactly one. Once we ﬁnd an acceptable ﬂow – it can always be maximized or minimized.

6.12: Upper/Lower limit for ﬂow in each edge is shown.6. classify used and unused edges and then redraw the directed graph .13).8.6 (also shown below Fig. shown in red color.4. Please recall the directed graph D shown in top left diagram of Fig. Problem 6. We need to ﬁnd if there is a feasible ﬂow in this network graph? Can we design an eﬃcient algorithm to solve this problem? If the in-degree of any node (other than vertex s and t) is more than two times the out-degree of that node in this graph then it will not be possible to ﬁnd a feasible ﬂow in the graph (why?).6.7. 6. The ﬂow. 6. however. The lower limit for ﬂow is 1 while the upper limit is 2 for each edge of this graph. If. this condition is false in a network graph (that means the in-degree is at most two times the out-degree of any vertex other than vertex s and t) then a feasible ﬂow will exist in the network graph? Can you counter this argument? Can you now design an eﬃcient algorithm to ﬁnd a feasible ﬂow in the graph? a g e f h a g e f h b b s c d i j t s c d i j t Graph D with Used and Unused edges Graph D without Unused edges Figure 6.5. violates the upper limit.13: Problem 6. We apply Algorithm 45 on this graph.Network Flows 323 6/6 6 6/1 7 s 6/4 t 4 6/1 3 Figure 6. We are given a network graph D with special vertices s and t.5.

Here we shall address the matching problem in un-weighted and then weighted . Connectivity and Matching Problems D without the unused edges.14: 6.6.324 Network Flows.5. The two graphs are reproduced in the ﬁgure below for ready reference. We claim that in any network graph D without the unused edges. Problem 6. & (b) We can use (the so called stupid) Algorithm 36 to ﬁnd maximum edge-disjoint paths in this graph.10. (a) Is it possible to push a ﬂow of exactly one unit through every directed edge in this graph? (b) If it is possible then does it mean that every edge in this graph will be part of a directed path from vertex s to vertex t in this graph? (c) If (a) is possible then can we ﬁnd maximum edge-disjoint paths from s to t in this graph using the stupid Algorithm 36? Vertex 1 is s and 7 is t Any vertex is s and also t Figure 6.7 The Matching Problem in Bipartite Graphs We have already talked about the Matching problem in diﬀerent contexts. Can you think of a directed graph where property (a) is applicable but (b) is not? Can you think of a graph where (b) is applicable but (a) is not? Problem 6. it is possible to push a ﬂow of exactly one unit in every directed edge. Consider a directed graph D where the in-degree of every vertex (other than s and t) is equal to the corresponding out-degree. either prove this or give a counter example.5. A directed network graph D without unused edges has two important properties: (a) every edge is part of a directed path from vertex s to vertex t in D.9.

Once we ﬁnd the maximum number of paths in the directed graph (see the bottom left diagram of Fig. 6.6.7. As explained before each matched edge in the bipartite graph (top left corner) corresponds to a path in the directed graph (top right corner). 6. We.1 Maximum Matching in Un-weighted bipartite graphs Given a maximal matching. this completes the transformation from a bipartite graph of the top left corner into the directed graph shown in the top right diagram. Unfortunately it is diﬃcult to adapt this algorithm to ﬁnd a maximum weighted matching in a weighted bipartite graph. The algorithm described above works well for ﬁnding a maximum matching in an unweighted bipartite graph. 6. We shall devise eﬃcient algorithms to ﬁnd maximum matching in un-weighted bipartite graphs and weighted maximum matching in a weighted bipartite graph. please note that the direction of each such edge is from the partition A to partition B.1. The problem of ﬁnding maximum matching in a bipartite graph is thus transformed into the problem of ﬁnding maximum number of edge-disjoint (or vertex-disjoint) paths in the directed graph. We convert undirected edges of the bipartite graph (top left diagram) into directed edges as shown in the top right corner. The matching problem is converted into a connectivity problem by adding two dummy vertices s and t as shown in the top right corner of Fig.1. We add directed edges from vertex s to every vertex in partite A.7.The Matching Problem in Bipartite Graphs 325 bipartite graphs. An edge between a boy and a girl shows a degree of compatibility. present (in the coming sub-section) a slightly diﬀerent version of this algorithm to ﬁnd maximum matching in an unweighted bipartite graph? Problem Set 6. We are given a bipartite graph having a partition B (consisting of a number of boys) and a partition G (consisting of a number of girls). therefore.1) we can ﬁnd the corresponding matched edges in the bipartite graph as shown in the bottom right diagram of the same ﬁgure.7. in fact any two matched edges in the bipartite graph will correspond to two edge-disjoint directed paths from vertex s to vertex t in the corresponding directed graph. We need to ﬁnd maximum pairs of boys and girls such that the boy and girl .7. how can we ﬁnd a maximum matching in a bipartite graph? A maximal matching in a bipartite graph is shown by bold lines in the top left corner of Fig. We also add directed edges from every vertex of the partition B to vertex t. 6.

The top right diagram shows a path from vertex s to vertex t corresponding to each matching edge in the bipartite graph. . This diagram is converted into the middle left diagram by reversing every edge in each path. Connectivity and Matching Problems a1 a2 A a3 b1 b2 B b3 a1 s a2 a3 b1 b2 b3 t Directed Graph F a1 s a2 a3 b1 b2 b3 a1 t s a2 a3 b1 b2 b3 t a1 s a2 a3 b1 b2 b3 a1 t A a3 a2 b1 b2 B b3 Figure 6. The middle right diagram shows maximum number of pseudo edge-disjoint paths from vertex s to t.326 Network Flows.7. The bottom left diagram shows maximum number of edge-disjoint paths in the directed graph while the bottom right diagram shows the corresponding maximum matching in the bipartite graph.1: The top left diagram shows a maximal matching in a bipartite graph.

Problem 6. each girl can marry a single boy. it can be modeled by an un-weighted bipartite graph as shown below (Fig. Assume that we are required to solve the marriage problem: namely we intend to marry maximum number of girls.1.6. The problem can be solved by techniques similar to the ones that we have just studied.2). How will you model this problem in terms of a known graph problem? Under what conditions it will be possible? Problem 6. a set of girls.7. each boy can marry a single girl and each girl can marry a single boy. a partition G showing. 6.The Matching Problem in Bipartite Graphs 327 in every pair are compatible. Assume that we are required to solve the marriage problem: namely we intend to marry maximum number of boy. Compatibility between a boy and a girl is indicated by an edge between the corresponding vertices.7. Assume that we intend to solve the decision problem in which we intend to ﬁnd a yes/no answer corresponding to the question: Is it possible to marry all boys? (Or is it possible to marry all girls?) .6. 2 3 Figure 6.2.3.2: A bipartite graph showing a partition B consisting of a set of boys. How will you model this problem in terms of a known graph problem? Under what conditions it will be possible? Problem 6.6. This problem is also known as the Marriage Problem.

Connectivity and Matching Problems Problem 6. A maximum matching in this graph is also shown in this . Assume that a boy can marry four girls and each girl can marry a single boy. Discuss with the help of an example. we intend to maximize the number of boys who are married. Discuss how you will solve this problem eﬃciently using similar techniques. We need to ﬁnd maximum weighted matching in this weighted bipartite graph. How about if we remove all directions from the directed graph D.3. We are given a bipartite graph with edge weights equal to either zero or one. 6. How will you model this problem in terms of a known graph problem? Under what conditions will it be possible? Problem 6. The maximum matching in a bipartite graph is equal to the maximum number of edge-disjoint paths in a directed graph D. thus converting it into an undirected graph.6.6.7. Assume that a boy can marry four girls.4. we intend to maximize the number of girls who are married. Problem 6. we intend to maximize the number of marriages taking place.7. How will you model this problem in terms of a known graph problem? Under what conditions will it be possible? Problem 6.2 Maximum Matching in Complete (Binary) Weighted Bipartite Graphs We are given an unweighted balanced bipartite graph as shown in left diagram of Fig. Problem 6. Problem Set 6.6.6.7. Can we still claim that the maximum matching in the bipartite graph is equal to the maximum number of edge-disjoint paths between vertex s and vertex t in the undirected graph D.7.2.328 Network Flows.6.7.7. How will you model this problem in terms of a known graph problem? Under what conditions will it be possible? Problem 6.1. 6. We intend to maximize the number of married boys and girls subject to the condition that a boy can marry four girls while a girl can marry a single boy. In other words the problem of ﬁnding maximum matching in a bipartite graph is transformed into the problem of ﬁnding maximum number of edge-disjoint (or vertex-disjoint) paths in a directed graph D. Assume that a boy can marry four girls.5.

6. We start with a complete weighted bipartite graph G of size k (it means there will be k vertices in A as well as k vertices in B).The Matching Problem in Bipartite Graphs 329 diagram. A maximum weighted matching in the right graph of this ﬁgure will be a maximum matching in the original bipartite graph. The results of this algorithms can be used to ﬁnd maximum matching in a bipartite graph. The bipartite graph is converted into a completely connected binary weighted bipartite graph as shown in the right diagram.7. It can handle (with or without minor modiﬁcation) the more general problem of ﬁnding maximum weighted matching in a bipartite graph. a1 a2 A a3 b3 b1 a1 1 1 b1 1 b2 B Convert into completely connected bipartite graph a2 A a3 1 b2 B b3 1 Weight of Maximum Matching = 3 Weight of existing edge is 1 and weight of new edge is 0 Figure 6. Here we shall describe another algorithm to ﬁnd the maximum mathing this new algorithm may not be as eﬃcient as the one described before but it has the added advantage of being ﬂexible.3 we convert this bipartite graph into a complete weighted bipartite graph . As shown in Fig.3: A balanced bipartite graph G with maximum matching of size 3 is shown in the left diagram. We convert the bipartite graph into a weighted directed graph D after adding vertices s and t according to the rules described previously. An edge in the original bipartite graph has a weight of 1 in the complete bipartite graph while every other edge has a weight equal to zero. Edge weights not shown in the right diagram are equal to zero. Thus the complete bipartite graph has binary weights.see the right diagram of this ﬁgure. We describe in the following paragraphs a useful algorithm to solve the maximum weighted matching problem in a complete bipartite graph with binary weights.7. We now describe a (not very . The algorithm can also be used to ﬁnd maximum weighted in a complete bipartite graph with non binary weights as described in the next section. It can be found using our expertise gained in the last section.

Find a longest path P from vertex s to t with a weight equal to or larger than zero. . also it is applied p (number of vertices) times on the graph until all the paths have been found.3.1. y) of path P in graph D do Reverse the direction of edge (x. Whereas in the case of Algorithm 47 for a complete weighted bipartite graph. 1 2 3 4 5 Transform the bipartite graph G into a directed graph D after adding vertices s and t to G according to the rules already deﬁned.8. y) with a negative sign and go back to Step 2 Problem Set 6. the modiﬁcations should be such that the maximum matching in the new bipartite is equal to the maximum matching in the original graph D. If you can not ﬁnd such a path then terminate.8. output: A maximum weighted matching in G.8.8. for each edge (x. Problem 6. What is the time complexity of Algorithm 47 and the previous algorithm described for unweighted graphs in the last section? Note that we are applying a simple path ﬁnding algorithm for un-weighted edges in the previous algorithm of the last section and its time complexity was O(p + q).330 Network Flows. Would we be able to get the maximum matching in a bipartite graph if the graph is neither complete nor balanced by applying Algorithm 47? Problem 6. Algorithm 47: Find a maximum weighted matching in a complete balanced bipartite graph G.2. y) Multiply the weight of edge (x. Problem 6. How is Algorithm 47 applicable to ﬁnd maximum matching in a general weighted graph D with weights greater than 1? Discuss the possible modiﬁcation that need to made to the general graph D before we can use it as input for the Algorithm. the Bellman-Ford algorithm is applied and its time complexity is O(p3 ) and again it is applied p number of times on the given network graph. Connectivity and Matching Problems eﬃcient but useful algorithm) which works on the directed graph D and outputs the maximum weighted matching in the bipartite graph. input : A complete balanced (binary) weighted bipartite graph.

we then ﬁnd the longest path in terms of weight and reverse the edges of that path. by adding dummy vertices s and t and add zero weight edges from s to A partite and B partite to t.4: We convert a bipartite graph into a maximum edge-disjoint path problem.7. .The Matching Problem in Bipartite Graphs 331 a1 1 b1 1 a1 1 b1 1 a2 A a3 1 b2 B b3 s a2 a3 1 b2 b3 t 1 1 Directed Graph F a1 1 b1 1 a1 1 b1 -1 s a2 a3 1 b2 b3 t s a2 a3 1 b2 b3 t 1 1 Weight of the Longest Path = +1 a1 1 b1 -1 a1 1 b1 1 s a2 a3 1 b2 b3 t s a2 a3 -1 b2 b3 t 1 -1 Weight of the Longest Path = +1-1+1=+1 a1 1 b1 1 a1 1 b1 1 s a2 a3 -1 b2 b3 t A a2 a3 1 b2 B b3 -1 1 Weight of the Longest Path = 0 Figure 6.

. Graph consisting of First 2 Layers a1 6 13 15 b1 B a1 6 13 15 b1 A a2 10 4 8 16 17 9 b2 a2 10 4 8 17 b2 16 a3 b3 a3 9 b3 Weight of Maximum Matching is 15+16+8 = 39 Graph consisting of first two layers is shown in circle Figure 6. . b3 .5: A complete balanced bipartite graph G is shown with positive edge weights. . bk . and all edges between these vertices as shown in Fig. The partition A as well as the partition B is indicated in the left diagram. perfect matching in a weighted complete and balanced bipartite graph G. are similar in some respects and diﬀerent in others.7.3 Maximum Weighted Matching in Complete Weighted Bipartite Graphs Problem: We need to ﬁnd a maximum. b2 . Input: A weighted complete & balanced bipartite graph G with positive edge weights. We deﬁne layers in the graph G: layer 1 contains a1 and b1 . a2 . it will be interesting to make a . The algorithms. assume that vertices in the A partite are numbered as a1 . that we describe. layer x contains vertices ax and bx . a3 . Output: A maximum weighted perfect matching. All edge weights are positive. ak . Connectivity and Matching Problems 6. Maximum weighted matching is shown in red color. 1.5.7. The ﬁrst two layers of bipartite graph G are shown in the right diagram. A Comparison of Two Algorithms: We shall describe two algorithms to solve the above problem.332 Network Flows. 6. . while vertices in the B partite are numbered as b1 . The graph consisting of ﬁrst x layers contains ﬁrst x vertices from both the partitions A & B. The weight of the maximum matching is equal to 15 + 8 + 16 = 39.7. See Fig. weighted.

6.The Matching Problem in Bipartite Graphs comparison between the two. Do not move forward before understanding Fig. 333 Algorithm 48: Find maximum weighted matching in a complete bipartite graph G input : A weighted complete bipartite graph G output: maximum weighted matching 1 2 for x = 1 to k do Find maximum weighted matching in the ﬁrst x layers of bipartite graph G. Algorithm 49: Find maximum weighted matching in a complete bipartite graph G input : A weighted complete bipartite graph G output: maximum weighted matching 1 2 for x = 1 to k do Find maximum weighted matching of size x in bipartite graph G. The working of the two algorithms is shown in Fig. Similarly in order to implement Algorithm No. 6. In order to implement this algorithm eﬃciently we need to design an eﬃcient procedure which performs the following function: Procedure No. It is obvious from these diagrams that the intermediate results may be diﬀerent but the end results are same for the two algorithms.7.6. 2: Given a maximum weighted matching of size x in G it ﬁnds the maximum weighted matching of size x + 1 in G.6. 49 eﬃciently we need to design an eﬃcient procedure which performs the following function: Procedure No. 48 requires us to ﬁnd the maximum weighted matching in the ﬁrst x layers.7. Before discussing the details of the two procedures we ﬁrst need to transform the weighted bipartite undirected graph G into a directed graph D with . Algorithm No. 1: Given a maximum weighted matching in the ﬁrst x layers of G it ﬁnds the maximum weighted matching in the ﬁrst x + 1 layers of G.

. The right diagrams show the working of Algorithm No. 48 when applied to a bipartite graph G.6: The left diagrams show the working of Algorithm No. 49 when applied to the same bipartite graph G. Connectivity and Matching Problems Maximum Matching in the first layer: Value = 13 Maximum Matching of size one: Value = 17 a1 6 13 15 b1 Different a1 6 13 15 b1 a2 10 4 8 16 9 17 b2 a2 10 4 8 16 9 17 b2 a3 b3 a3 b3 Maximum Matching in the first two layers: Value = 6+15 = 23 Maximum Matching of size 2: Value = 15+16=31 a1 6 13 15 b1 a1 6 13 15 b1 a2 10 4 8 16 9 17 b2 Different a2 8 4 b2 16 a3 b3 a3 9 17 b3 Maximum Matching in all layers: Value = 8+16+15 = 39 Maximum Matching of size 3: Value = 8+15+16=39 a1 6 13 15 b1 a1 6 13 15 b1 a2 10 4 8 16 9 17 b2 Same a2 10 4 8 16 9 17 b2 a3 b3 a3 b3 Figure 6.334 Network Flows. Please note that intermediate results may be diﬀerent but the end result is the same for the two algorithms.7.

1. Every directed edge from B partite to A partite in D corresponds to a maximum weighted matching in the ﬁrst x + 1 layers of G. . 1. Add vertex s to G such that in the resulting graph D there is a directed edge from vertex s to every unmatched vertex in A with a weight equal to 0. The sign of every weight w for every matched edge in G is changed to a minus sign in the directed graph D. b) in bipartite graph G add a direction going from vertex b to a in the directed graph D. Algorithm 50: Procedure 1: Transform maximum weighted matching in the ﬁrst x layers into a maximum weighted matching in the ﬁrst x+1 layers in a bipartite graph input : Maximum weighted matching in the ﬁrst x layers of bipartite G output: Maximum weighted matching in the ﬁrst x + 1 layers of bipartite G 1 2 3 Transform the weighted bipartite graph into a directed graph D. 3. b) in G add a direction going from vertex a to b in the directed graph D. All other edge weights retain their original signs in D as there are in G.7. For every matched edge (a. We shall now discuss the details of Procedure No. 4. Now add another vertex t such that there is a directed edge from every unmatched vertex in B to vertex t with a weight equal to 0. The weight of the longest path from vertex s to t in D is equal to the gain in the weight of maximum matching when the size of matching is increased from x to x + 1 in the bipartite graph G. Claim 6. Note that vertex a belongs to A while b belongs to B in the bipartite graph G. 2. Find a longest path from vertex s to t passing through the ﬁrst x + 1 layers of D and now reverse the edges in this path. 1 & 2. For every unmatched edge (a.The Matching Problem in Bipartite Graphs 335 additional vertices s and t according to the following rules as shown in the diagram below.

7. Maximum weighted matching in the ﬁrst two layers in a bipartite graph G is converted into a maximum weighted matching in the ﬁrst three layers of the same bipartite graph.7: The diagrams show the working of Procedure No.336 Network Flows. . 1. Connectivity and Matching Problems Maximum Matching in First 2 layers a1 6 Transform -10 5 b1 -4 8 17 a1 6 10 5 b1 4 8 17 a2 s 16 b2 10 t b3 a2 16 b2 10 a3 9 a3 9 b3 a4 b4 a1 6 -10 5 b1 -4 8 17 a4 b4 a2 s 16 b2 10 25 t b3 a3 a1 6 10 5 9 b1 a4 a1 b2 10 17 -6 10 5 b4 a2 16 4 8 b1 4 8 a3 a2 b3 s -16 b2 10 9 t 25 a3 a4 b4 Transform -17 9 b3 Maximum Matching in First 3 layers a4 b4 Figure 6.

2. Every directed edge from B partite to A partite in D corresponds to a maximum weighted matching of size x + 1 in G.8: The diagrams show the working of Procedure No.The Matching Problem in Bipartite Graphs 337 Algorithm 51: Procedure 2: Transform maximum weighted matching of size x into a maximum weighted matching of size x + 1 in a bipartite graph input : Maximum weighted matching of size x in bipartite graph G output: Maximum weighted matching of size x + 1 in bipartite graph G 1 2 3 Transform the weighted bipartite graph into a directed graph D.7. . Maximum weighted matching of size 1 in a bipartite graph G is converted into a maximum weighted matching of size 2 in the same bipartite graph. Maximum Matching of size One a1 6 13 15 b1 a1 6 13 15 b1 s a2 10 4 8 16 -17 9 b2 t a2 10 4 8 16 9 17 b2 Transform a3 b3 b3 a1 6 13 15 a3 b1 14 Convert s a2 10 4 8 16 9 -17 b2 t a1 6 13 15 b1 a1 13 6 Transform -15 a3 b1 b3 Find Longest path a2 8 4 b2 16 a3 9 17 s a2 10 4 8 -16 17 9 b2 t b3 a3 Maximum Matching of size Two b3 Reverse Longest path Figure 6. Find a longest path from vertex s to t in D and now reverse the edges in this path.

9: The diagrams illustrates that every path from s to t in the directed graph D passing through the ﬁrst three layers corresponds to a matching in the ﬁrst three layers of the bipartite graph G. The longest path corresponds to a perfect matching of maximum weight. .7. Connectivity and Matching Problems a1 6 10 5 b1 a2 l= tia Ini 14 4 8 17 b2 10 16 a3 6 9 b3 b4 a1 6 -10 5 b1 16 a4 8 17 -4 8 a1 6 10 5 b1 4 8 17 4 a2 16 b2 10 s 0 t 9 Increase by 9 a2 16 b2 10 a3 9 b3 a3 a4 6 9 b3 b4 -10 6 5 a1 b1 -4 8 17 16 a1 8 10 6 5 b1 4 8 17 a2 16 b2 10 12 s 0 t 21 Increase by 21 a2 16 b2 10 a3 9 b3 a3 a4 6 9 b3 b4 -10 6 5 a1 b1 16 -4 8 17 12 a1 6 10 5 b1 4 8 17 8 a2 16 b2 10 a2 t Increase by 25 16 b2 10 s 0 25 a3 9 b3 a3 a4 9 b3 b4 a4 b4 Figure 6.338 Network Flows.

We transform the bipartite graph into a directed graph also shown in Fig.2.7. If we select Path 1 (as dictated by Procedure No. 6. Suppose we have found two paths (one longest and one relatively shorter) from vertex s to vertex t.9. .The Matching Problem in Bipartite Graphs 339 Claim 6.7. 1) then we need to reverse edges belonging to Path 1. Then the reversed edges of Path 1 plus edges belonging to Path 2 will form a cycle in the graph with a net negative value at most equal to y − z.7. If on the other hand we reverse edges in Path 2 then a cycle with a net positive value at most equal to y − z will be formed as shown in Fig. 6 a1 6 -10 5 b1 16 -4 8 17 12 6 a1 6 -10 5 b1 16 -4 8 17 8 8 a2 16 b2 10 4 a2 16 b2 10 s 0 t 25 s 0 t 9 a3 9 b3 a3 9 b3 a4 b4 a1 6 -10 5 a4 b1 -4 8 17 b4 a2 s 16 b2 10 t b3 e rs ve Re Ed s ge a3 -9 a4 b4 Figure 6.10: The top left diagram shows the longest path from s to t in D while the right diagram shows a relatively shorter path. we now need to extend this maximum matching in the ﬁrst x + 1 layers of G as shown in Fig. Path 1 is the longest path and has a weight equal to y and Path 2 is a relatively shorter path and has a weight equal to z.7.7.10. If we reverse edges of the shorter path then a cycle of net positive value will be formed. Assume that we have already found a maximum matching in the ﬁrst x layers of graph G. 6.9. 6.

Discuss brieﬂy if your algorithm is a greedy algorithm or does it use dynamic programming. We shall never encounter a situation where there will be a positive weight cycle in D (provided we follow steps given in Procedure No.2. be present in the directed graph D. Assume that we have found a 3-edge longest path from vertex s to vertex t in a directed graph consisting of the ﬁrst x + 1 layers of graph D (see right diagram of Fig. We are working under the assumption that there are no positive weight cycles in the directed graph D.9.4.7. Problem Set 6.13 shows a directed graph in which there is only one edge going from a vertex b to a vertex a. Please note that there are 2k + 2 vertices in this directed graph and your answer should be independent of edge weights in the graph. 2). 6. Assume that we are given a complete balanced weighted bipartite graph with positive edge weights. 6.9.7.3. We need to ﬁnd what will be the maximum length (in terms of number of edges) of the longest path passing through the ﬁrst x + 1 layers of the graph. Design an eﬃcient algorithm to solve this problem.13). Connectivity and Matching Problems Claim 6. Someone thinks that the longest path problem is NP-Complete. Negative weight cycles will.1 or Procedure No. Problem 6. The left diagram of Fig.5. We need to ﬁnd what will be the maximum length (in terms of the number of edges) of the longest path passing through the ﬁrst two layers of the graph.7. The right diagram of Fig. Now we need to ﬁnd a 5-edge longest path from s to t in the same graph consisting of ﬁrst x + 1 layers of graph D.13 shows a directed graph in which there are x edges going from a b vertex to an a vertex. Problem 6. however.3. Carefully derive the time complexity of this algorithm. Carefully derive the time complexity of this algorithm in terms of the size of the problem.9. we need to ﬁnd a longest path from vertex s to vertex t. 1 (and Procedure No.9. Problem 6.340 Network Flows. In Procedure No.7. Please comment.9. Please note that there are 2k + 2 vertices in this directed graph and your answer should be independent of edge weights in the graph.1. 2). Describe an eﬃcient algorithm to ﬁnd a maximum matching in the very ﬁrst layer of the bipartite graph. . 6.9. Problem 6. Problem 6.

7.11: The diagrams show the working of Algorithm No.The Matching Problem in Bipartite Graphs 341 Finding Maximum Matching in the First layer a1 0 6 10 5 b1 4 8 17 10 a2 s 16 b2 10 t b3 a1 10 a3 9 b1 a4 b4 a1 6 Finding Maximum Matching in First 2 layers 10 5 b1 4 -5 a2 a1 6 0 -10 5 0 b1 4 8 17 5 -5 b2 a1 6 -10 5 b1 4 8 17 5 a2 s 16 b2 10 4 a2 t s 16 b2 10 4 t b3 a1 6 10 5 b1 4 8 17 a3 9 b3 a3 9 a2 a4 b4 a4 b4 16 b2 10 a3 9 b3 6 a1 6 -10 5 b1 16 -4 8 17 8 Finding Maximum Matching in the First 3 layers 6 a1 6 -10 5 b1 16 -4 8 17 12 4 a2 16 b2 10 6 a1 6 -10 5 b1 -4 8 17 16 8 a2 16 b2 10 s 0 t 9 8 s a2 16 0 t 25 a3 9 b3 s b2 12 10 0 a3 t 9 b3 a4 b4 a3 9 21 b3 a4 b4 a4 b4 Figure 6. 48 on a bipartite graph which is already been transformed into a directed graph D. .

7.342 Network Flows. . 49 on a bipartite graph which is already been transformed into a directed graph D. Connectivity and Matching Problems Finding Maximum Matching of size one a1 6 13 15 b1 15 a1 6 13 15 b1 s a2 10 4 8 16 9 17 b2 8 t a2 10 4 8 16 9 17 b2 a1 6 13 15 17 a3 b3 a3 b3 b1 a2 Finding Maximum Matching of size 2 8 13 6 8 15 4 b2 16 0 a1 6 13 15 b1 13 0 a1 b1 8 14 a3 9 17 b3 s -1 a2 10 4 8 16 9 -17 b2 16 t s -1 a2 10 4 8 16 9 -17 b2 16 t a1 6 13 15 b1 0 a3 b3 0 a3 b3 a2 10 4 8 16 9 17 b2 a3 Finding Maximum Matching of size 3 b3 -7 a1 6 13 -15 b1 10 -4 a1 6 13 -15 b1 10 s -5 a2 10 4 8 17 b2 8 t a1 -4 6 13 -15 b1 10 s -5 a2 10 4 8 17 b2 8 t -16 9 9 -16 12 9 a3 b3 s a2 -5 10 4 8 17 b2 8 t a3 b3 -16 12 9 a3 b3 Figure 6.12: The diagrams show the working of Algorithm No.

Assume that the time complexity of Procedure No. 1 is bounded by O(x · k 2 ).9. The right diagram shows another directed graph D where there are x edges going from a vertex b to a vertex a. Problem 6.9.10. Carefully derive the time complexity of this algorithm. 48.9.9. Assume that we are given a complete balanced weighted bipartite graph with positive edge weights. 6. Is it possible to use an existing textbook algorithm (without any modiﬁcation) in order to solve the previous problem? Discuss brieﬂy.9.12). Carefully derive the time complexity of Procedure No.6.7. Find the actual longest path in each of the directed graphs shown in Fig.7. 49 (see Fig. Problem 6.14.13: The left diagram shows a directed graph D in which there is only one edge going from a vertex b to a vertex a. Problem 6. 1 and then the time complexity of Algorithm No. Consider the working of Procedure No. Problem 6.8.11).9. Problem 6.7.9. Describe an eﬃcient algorithm to ﬁnd a maximum matching of size 1 in this bipartite graph. Now derive the time complexity of Algorithm No. Problem 6.11. 6. What would be the maximum value of the length (in terms of number of edges) of the longest path from vertex s to vertex t in D? Discuss brieﬂy. Problem 6.7. 48 (see Fig.The Matching Problem in Bipartite Graphs Only 1 edge is reversed 343 a1 6 -10 5 b1 4 8 17 First layer Only x edges are reversed a1 6 -10 5 b1 First x Layers 8 17 -4 a2 s 16 b2 10 a2 t s 16 b2 10 t b3 a3 9 b3 a3 9 ak bk ak bk Figure 6. Carefully derive the time complexity of Procedure No. .12.9. 6. 2 and then the time complexity of Algorithm No. 2.7.

9. Problem 6. Discuss if we can use Algorithm No.48 and 49 may be the same in terms of the Big O notation yet one algorithm is considerably faster than the other. Although the worst case time complexity of Algorithm No. Problem 6. Suppose we need to ﬁnd a best possible matching for the ﬁrst x members of partite A in a given complete balanced weighted bipartite graph G.14. Discuss if we can use Algorithm No. Problem 6.14: We need to ﬁnd longest path from vertex s to t in the directed graphs shown here. Problem 6. Suppose we need to ﬁnd a best possible matching for the ﬁrst x members of partite B in a given complete balanced weighted bipartite graph G.344 a1 6 13 15 Network Flows.7. Discuss how you will solve this problem and carefully derive the time complexity of your algorithm in terms of x and k.15. 48 or 49 to solve this problem? How can you design a better algorithm to solve this problem? Discuss brieﬂy. Discuss brieﬂy. 48 or 49 to solve this problem? How can you design a better algorithm to solve this problem? Discuss brieﬂy. Connectivity and Matching Problems b1 a1 6 13 15 b1 15 s a2 10 4 8 16 -17 9 b2 t s a2 10 -17 8 16 4 9 b2 8 t ak bk ak bk a1 6 13 15 b1 a1 6 13 15 b1 s a2 10 -4 8 16 17 9 b2 t s a2 10 -4 8 16 17 -9 b2 t ak bk ak bk Figure 6. Suppose we need to ﬁnd a best possible matching of size x in a given complete balanced weighted bipartite graph G of size k and x is much smaller than k.9.13.9. .16.9.

2 Finding a Maximum Flow or Finding a Shortest Path? Before answering the above question it is important to revise the relevant prior knowledge. The problem is to eﬃciently ﬁnd maximum ﬂow at minimum cost in a given network graph. The maximum ﬂow at minimum cost is indicated by colored lines in the right diagram. A possible solution of this network graph is shown in the right diagram of the same ﬁgure. It is interesting to note . We assume that the capacity as well cost per unit ﬂow through every edge is a positive integer.8. The capacity/cost of an edge is shown along with each edge.8. We need to push the maximum ﬂow in this network graph (starting from vertex s and ending at vertex t) at a minimum cost.1. 6.8. we are pushing a maximum ﬂow of 3 units at a total cost of 19. We need to ﬁnd maximum ﬂow coming out of vertex s and being absorbed by vertex t.8 6. We also need to make sure that the maximum ﬂow is taking place at minimum cost. and also remind ourselves of some of the powerful techniques which will be useful in solving this problem. 1/8 2/8 2/8 a 2/0 b 1/4 3/5 8/2 1/0 2/0 a 1/4 6/9 1/4 1/5 3/5 b 8/2 1/0 1/2 2/0 s 1/0 6/9 t 2/0 s 2/0 t c 1/9 d c 1/9 d The Max-Flow Min-Cost Problem (Category 1) Maximum Flow (3 units) at Minimum Cost (8+5+4+2) Figure 6.The Max-Flow Min-Cost Problem 345 6. 6.1: We show a directed graph D (left diagram) having two special vertices s and t.8. it is indicated with each edge in the ﬁgure below.1 The Max-Flow Min-Cost Problem Introduction We consider the Maximum Flow at Minimum Cost problem in a network graph as shown in Fig.

It is certainly a very exciting mixture of two important problems. We need to maximize the ﬂow and we already know how to do it (but we should also remember our shortcomings and limitations). 6. So let us list down the general problem (once again) and its special cases: Category 1: Given a network ﬂow graph as shown in Fig. Please note that this problem is equivalent to ﬁnding the maximum edge-disjoint paths from vertex s to vertex t at minimum cost. 2. We know how to solve the above two problems in isolation but how can we fulﬁll the two requirements simultaneously? If we start ﬁnding ﬂows without looking at costs then we may end up with a maximum ﬂow but at higher cost.1 how can we ﬁnd maximum ﬂow at minimum cost from a source vertex s to a sink vertex t? We assume that edge capacities are integers while per unit cost of ﬂow through any edge may be any non-negative real number.8. We need to minimize the cost of (unit) ﬂow starting from vertex s and ending at vertex t. Category 2: Given a network ﬂow graph as shown in Fig. the sum of edge costs in all edge-disjoint (shortest) paths should be as small as possible.8.346 Network Flows. ﬁnding shortest paths without considering capacities will create complications.e. and this somehow looks like ﬁnding a shortest path from vertex s to t (we are aware of a number of simple and eﬃcient algorithms to solve shortest path problems). Before we solve this general problem we shall try to reﬂect on similar problems we have already solved and what are some of the special cases of this general problem which can be resolved using our prior knowledge? We shall then extend or modify specialized solutions to solve this general problem. If we start minimizing the cost by ﬁnding shortest paths. Category 3: The network ﬂow graph is derived from a complete balanced and weighted bipartite graph. i. Connectivity and Matching Problems that this challenging problem (which we call a Category 1 problem) has two requirements: 1. 6. Here we add a source vertex s to the A and . then how will we be able to tackle the problem of maximizing the ﬂow? Diﬀerent edges have diﬀerent capacities.2 how can we ﬁnd the maximum ﬂow at minimum cost from a source vertex s to a sink vertex t? We assume that the capacity of each edge is exactly 1 while per unit cost of ﬂow through any edge may be a real number.

2: A Category 2 problem is equivalent to ﬁnding maximum edgedisjoint paths at minimum cost as shown in the top diagram. A special case of this category is shown in the bottom diagram An i nt p r o er es t bl e i n g m t Reduced to .8.The Max-Flow Min-Cost Problem 347 a 1/0 1/9 b 1/0 1/5 1/2 s 1/0 1/4 1/9 t 1/0 Equivalent to c 1/3 d The Problem of finding Max edge-disjoint paths at Min Cost Category 2 The Max-Flow Min-Cost Problem Binary Costs a 1/0 1/0 1/0 1/0 1/1 b 1/0 1/1 1/0 1/1 s c 1/0 d Special case of Category 2 The Max-Flow Min-Cost Problem When costs are binary Figure 6.

8.8.348 Network Flows.3: In a Category 3 problem a network ﬂow graph is derived from a weighted bipartite graph by inserting a source vertex and a sink vertex. We assume that the capacity of each edge is one in the network ﬂow graph.8.3. a1 6 13 15 b1 a1 6 13 15 b1 a2 4 8 16 17 9 b2 s B a2 10 4 8 16 17 9 b2 t A 10 a3 b3 a3 b3 A Bipartite graph with a weight or cost on each edge.4. It is possible to recognize that ﬁnding maximum ﬂow (or maximum edge-disjoint paths) at minimum cost in the right diagram is equivalent to ﬁnding a minimum cost perfect matching in the bipartite graph shown in the left diagram.8. Figure 6. Both problems have their applications in graph theory and elsewhere. All edge capacities are 1. A related problem in a bipartite graph would be to ﬁnd a maximum cost perfect matching . All edge weights associated with source vertex s and sink vertex t are zero 6. Here the problem is to ﬁnd maximum ﬂow at minimum cost in the network ﬂow graph shown in the right diagram. Similarly while we were solving the minimum weighted perfect matching . 6.8. A curious reader might have noticed that while solving the maximum cost perfect matching problem in the bipartite graph shown in Fig.that would require us to ﬁnd maximum ﬂow (or maximum edge-disjoint paths) at maximum cost. 6. 6. Connectivity and Matching Problems a sink vertex t to B as shown in Fig.3 we were essentially solving the maximum ﬂow at maximum cost problem as shown in a network ﬂow graph in Fig. We need to recall our expertise of ﬁnding maximum cost perfect matching in a weighted bipartite graph discussed in earlier sections.3 Category 3 network ﬂow Problems We shall now try attacking these problems starting from Category 3. costs not shown are equal to 1 Category 3: The network flow graph is derived from a bipartite graph.

What we essentially do here is to ﬁnd a longest path P from vertex s to vertex t in the given graph. The problem is how to recover maximum ﬂow at minimum cost from this (ﬁnal) graph F . We reverse the direction of each edge in path P and also multiply weight of each edge in the path by negative 1. It is slightly modiﬁed as shown below (Algorithm 52).3. 6. The algorithm terminates when it is no longer possible to ﬁnd a path from the source to the sink as shown in the bottom right diagram of Fig. We have in fact solved the Category 3 network ﬂow problem without explicitly saying so as our primary objective was to ﬁnd a perfect matching of maximum (or minimum) cost.8. problem in a bipartite graph we are essentially solving the minimum cost maximum ﬂow problem. The step by step working of this algorithm is shown in Fig. We apply this algorithm to the network ﬂow graph shown in the right diagram of Fig.8. Maximum Flow at Maximum Cost in Category 3 problems Please recall Algorithm 47 which was designed to ﬁnd a maximum weighted matching in a complete bipartite graph. As we shall show later this algorithm is powerful enough to handle Category 2 and 1 network ﬂow problems.8. 6.5.4: A maximum weighted perfect matching in bipartite graph (left diagram) corresponds to a maximum ﬂow at maximum cost in the right diagram.5. We then again ﬁnd a longest path from the source vertex to the sink vertex in the modiﬁed graph.The Max-Flow Min-Cost Problem 349 a1 6 13 15 b1 a1 6 13 15 b1 a2 4 8 16 9 17 b2 s B a2 10 8 4 16 b2 t A 10 a3 17 9 b3 a3 b3 Maximum Weighted Perfect Matching in a Bipartite Graph Category 3: Maximum Flow at Maximum Cost Figure 6. . 6.8.

By deleting these edges it is possible to ﬁnd maximum ﬂow at maximum cost in a Category 3 problem as shown in Fig.8. 6. and vertices s & t.8.6. The unused edges in ﬁnal graph F are those which have positive weights as shown in Fig.350 Network Flows. 6. y) Multiply the weight of edge (x.6. y) with a negative sign and go back to Step 2 The solution to this problem is again consistent to our earlier approach of deleting unused edges from the network ﬂow graph. But in order to do that we need . We intend to solve the maximum ﬂow at minimum cost problem using multiple algorithms in order to provide a better insight to the problem and its possible solutions.8. Connectivity and Matching Problems Algorithm 52: Find a Maximum Flow at maximum cost from vertex s to vertex t in a directed network graph D belonging to Category 3 input : Directed & Weighted graph D. One would like to compare this answer with the one obtained while ﬁnding a maximum weighted perfect matching in a bipartite graph shown in Fig. Maximum Flow at Minimum Cost in Category 3 Problems The above algorithm can easily be adopted to ﬁnd maximum ﬂow at minimum cost or in other words maximum edge-disjoint paths at minimum cost in a Category 3 network ﬂow graph. output: Maximum Flow at minimum cost from s to t in D 1 2 3 4 5 Copy Graph D into F . If you are successful in ﬁnding a ﬂow then keep a record of the path found otherwise exit with graph F as output. Find a ﬂow of one unit through a longest path P (in terms of edge costs) from vertex s to t in F . 6.4.4 Category 2 (and 1) network ﬂow Problems Here we shall consider Category 2 (and Category 1) network ﬂow problems. We shall ﬁrst show that Algorithm 53 can be used solve these problems without any modiﬁcation. 6. y) of path P in graph F do Reverse the direction of edge (x.8. for each edge (x. The only change that we need to do is to replace longest path in line 2 of this algorithm by shortest path as shown in the following algorithm (Algorithm 53).

8.The Max-Flow Min-Cost Problem 351 Find a longest path from s to t a1 6 13 15 Reverse the edges of the longest path a1 6 13 15 b1 b1 s a2 10 4 8 16 17 9 b2 t s a2 10 4 8 16 9 -17 b2 t a3 b3 a3 b3 Find another longest path from s to t a1 6 13 15 Reverse the edges of the longest path a1 6 13 -15 b1 b1 s a2 10 4 8 16 -17 9 b2 t s a2 10 4 8 17 9 b2 -16 t a3 b3 a3 b3 Find another longest path from s to t a1 6 13 -15 Reverse the edges of the longest path a1 6 13 -15 b1 b1 s a2 8 10 4 b2 -16 t s a2 10 -8 4 b2 -16 t a3 17 9 b3 a3 17 9 b3 Final graph F: No more paths left from the source to the sink vertex Figure 6. Please note that in this graph it is no longer possible to ﬁnd another path from the source vertex to the sink vertex. The ﬁnal graph F is shown in the bottom right corner.8.5: The step by step working of Algorithm 52 is shown here on the network graph of Fig.3. 6. .

6: Final graph F taken from the last ﬁgure is shown in the top left diagram. If you are successful in ﬁnding a ﬂow then keep a record of the path found otherwise exit with graph F as output. We can recover maximum ﬂow at maximum cost by removing edges with positive weights in this ﬁnal graph F . and vertices s & t.352 a1 6 13 -15 Network Flows. Connectivity and Matching Problems b1 a1 -15 b1 s a2 10 -8 4 b2 -16 t Remove +ive edges from graph F s a2 -16 b2 t a3 17 9 -8 b3 a3 b3 Final graph F: No more paths left from the source to the sink vertex Maximum Flow at Maximum Cost in the apposite direction Re gra mov ph e +i F f ve rom ed gra ges i ph n D a1 15 b1 s a2 8 16 b2 t a3 b3 Maximum Flow at Maximum Cost in the normal direction Figure 6.8. y) of path P in graph F do Reverse the direction of edge (x. Find a ﬂow of one unit through a shortest path P (in terms of edge costs) from vertex s to t in F . y) Multiply the weight of edge (x. y) with a negative sign and go back to Step 2 . Algorithm 53: Find a Maximum Flow at minimum cost from vertex s to vertex t in a directed network graph D belonging to Category 3 input : Directed & Weighted graph D. for each edge (x. output: Maximum Flow at minimum cost from source vertex s to sink vertex t in D 1 2 3 4 5 Copy Graph D into F .

2. Claim 6.8. It contains a source vertex s and a sink vertex t.8. We now reverse the direction of each edge in path P in graph F . We copy this graph in graph F .1. Such a scenario is shown in Fig. We ﬁnd a shortest path P from source vertex s to the sink vertex t in directed graph F . If there is a negative weight cycle in graph F with a net weight equal to -k (graph F is derived from a network graph D after reversing the edges in the direction of the ﬂow and multiplying the costs in . Now we claim that as directed graph D does not contain any negative weight cycle then graph F will also not contain any negative weight cycle. We also multiply the weight of each edge in path P by negative one in graph F .8.3. We ﬁnd a shortest path P from source vertex s to the sink vertex t in directed graph F . We reverse the direction of the edges used by the ﬂow and multiply the cost of these edges by negative 1 as shown in graph F (see top right diagram). Given a network ﬂow graph D. We are given a directed & weighted graph D. 6.8.8. Claim 6. 6. The graph D may contain cycles but it does not contain any negative weight edge. We are given a directed & weighted graph D with no negative weight cycles but it may contain negative weight edges. If on the other hand there are no negative weight cycles then it is not possible to reduce the cost of existing ﬂow. Please note that this ﬂow of one unit is not taking place on a shortest path from vertex s to vertex t. We now reverse the direction of each edge in path P in graph F . We copy this graph in graph F .The Max-Flow Min-Cost Problem 353 to do some serious graph theoretic work in terms of claims and some hints for their proofs. It contains a source vertex s and a sink vertex t. Claim 6. By redirecting the ﬂow in the negative weight cycle it is possible to reduce the cost of ﬂow by an amount exactly equal to 2 as shown in the bottom diagram of this ﬁgure.7. Negative Weight Cycles & Improvement in Cost of Flow We show a ﬂow of one unit in the network D shown in the top left diagram of Fig. We also multiply the weight of each edge in path P by minus one in graph F . Now we claim that as directed graph D does not contain any negative edges therefore graph F will not contain any negative weight cycle.8. The value of net weight in this cycle is -2. We ﬁnd a ﬂow of one unit from vertex s to vertex t. We then ﬁnd a negative weight cycle in this new graph F highlighted by orange color.

7: We show a ﬂow of one unit in the network shown in the top left diagram. .8. If there is a negative weight cycle (after reversing the edges in the direction of the ﬂow) then the cost of ﬂow can be further reduced. Connectivity and Matching Problems 2/8 a 2/0 b 1/0 2/0 1/4 3/5 8/2 2/8 a 3/5 6/9 1/0 1/4 b 1/0 8/2 s 1/0 6/9 t 2/0 s t 1/0 c 1/9 d c 1/-9 d One edge-disjoint path or a flow of 1 unit in a Category 1 Problem An Improvement is possible as there is a negative cycle 2/8 Reverse the edges in the path shown earlier There is a negative cycle of value = -2 a 2/0 b 1/0 1/4 3/5 8/2 s 1/0 6/9 t 2/0 c 1/9 d Cost can be improved by 2 units by redirecting the flow in the direction of negative cycle Figure 6.354 Network Flows.

4.8.8. .8. If (after reversing the edges in the direction of the ﬂow) there are no negative weight cycles then the cost of ﬂow can not be further reduced. 2/8 2/8 a 2/0 b 1/0 1/4 3/5 8/2 1/0 1/0 a 6/9 1/-4 1/-5 2/5 b 8/2 1/0 s 1/0 6/9 t 2/0 s 1/0 t 2/0 c 1/9 d c 1/9 d A flow of 2 units in a Category 1 Problem Reverse the edges in the paths shown earlier 2/8 1/0 1/0 2/8 a 6/9 1/-4 1/-5 2/5 b 8/2 1/0 1/0 1/0 a 1/-5 6/9 1/-4 2/5 b 8/2 1/0 s 1/0 t s 1/0 t 1/0 c 1/9 d The cycle is of net positive weight en t a em l e f o r v 1/0 p ro si b ni ts o Imis pos 2 u N t of os ow n C ed f l i x fi c 1/9 d The cycle is of net positive weight Figure 6. Claim 6. we keep a record of the length of each such path and call these paths existing paths in D. If there is no negative weight cycle in graph F (derived from a network graph D after reversing the edges in the direction of the ﬂow and multiplying the costs in these edges by negative 1) then it is not possible to reduce the cost of the existing ﬂow by re-adjusting the ﬂow in any direction. 6. Given a graph D and a ﬁnite ﬂow taking place from vertex s to vertex t.9.The Max-Flow Min-Cost Problem 355 these edges by minus 1) then it is possible to reduce the cost of the existing ﬂow by k by re-adjusting the ﬂow in the direction of the negative cycle.5.8: We show a ﬂow of two units in the network shown in the top left diagram. We know the path taken by each unit of ﬂow from vertex s to vertex t in D. Please see Fig.8. Claim 6. If there is no improvement possible in the cost of existing ﬂow then there will be no negative weight cycle in graph F (derived from a network graph D after reversing the edges in the direction of the ﬂow and multiplying the costs in these edges by negative 1).

9: We show two existing paths from s to t in graph D (top left diagram).8. Connectivity and Matching Problems 2/8 2/8 a 2/0 b 1/0 1/4 3/5 8/2 1/0 1/0 a 6/9 1/-4 1/-5 2/5 b 8/2 1/0 s 1/0 6/9 t 2/0 s 1/0 t 2/0 c 1/9 d Convert c 1/9 d A flow of 2 units in graph D The red path has length equal to 4. .356 Network Flows. The paths are reversed in graph F as shown in the top right diagram. the green path has length equal to 5 Graph F: we have reversed the edges in the direction of the flow in graph D and have multiplied the edge costs by -1 If there are no improvement possible in existing flow in graph D then there will be no negative cycles in F Figure 6.

output: Maximum Flow from s to t in D at Minimum Cost 1 2 3 4 Copy graph D into a graph F . now go to step 3. The process of ﬁnding maximum ﬂow at minimum cost may be accelerated if we some how ﬁnd a negative weight cycle of higher value and remove it as shown in Fig.10. Reverse the edges in the path of every ﬂow. we then reverse the edges in the direction of the ﬂow. the removal of a negative weight cycle will certainly reduce the cost of ﬂow by at least one unit. We now describe an alternate algorithm (Algorithm 54) to ﬁnd a maximum ﬂow at minimum cost for Category 1 problems. multiply the costs corresponding to these edges with negative 1.10. 6. Our last three claims support the argument that the following algorithm would be able to correctly solve maximum ﬂow at minimum cost problem in Category 1 network ﬂow graphs.8.8.The Max-Flow Min-Cost Problem Finding Maximum Flow at Minimum Cost 357 In view of the above claims it is obvious that Algorithm 53 can be used to ﬁnd maximum ﬂow at minimum cost in Category 2 as well as Category 1 network ﬂow problems. .8. If there are any negative weight cycles in the graph then we have to remove every negative weight cycle. It will be interesting to derive the time complexity of that algorithm for both these categories. Find if there is a negative weight cycle in graph F. multiply the cost of these edges with minus one. 6.10. 6. Algorithm 54: Find Maximum Flow at Minimum Cost from s to t in a directed graph D in a Category 1 problem input : Directed & Weighted graph D.1. Problem 6. Problem Set 6.4. The process is repeated until there are no more negative weight cycles left in the graph. We have demonstrated the working of an algorithm (to ﬁnd maximum ﬂow at minimum cost in Category 3 problems) in Fig.11. Remove the negative weight cycle by adjusting the ﬂow accordingly. If you ﬁnd one then go to step 4 else output the maximum ﬂow at minimum cost and exit. but it may give rise to another negative weight cycle. and vertices s & t. Find Maximum Flow from vertex s to t in F (ignoring costs). The step by step detailed working of the above algorithm on a Category 1 problem is shown in Fig. First we ﬁnd maximum ﬂow.

We ﬁrst ﬁnd maximum ﬂow ignoring costs (cost comes out to be = 27). Connectivity and Matching Problems 2/8 2/ a 2/0 b 1/0 1/4 3/5 8/2 2/ a 6/ 1/ 3/ b 8/ 1/ s 1/0 6/9 t 2/0 s 1/ t 2/ c 1/9 d c 1/ d Integer Capacity Integer Cost in graph D 2 2 2/ Forget the Costs in D for the time being 2 2/ a 6/ 1/ 3/ b 8/ 2 1/ 2/0 2/8 a 6/ 1/4 3/5 b 8/2 1/0 s 1/ t 2/ s 1/0 t 2/0 c 1/ d c 1/9 d Find the Max Flow in D 2 0/ 2 0/ Find the Cost of Max flow 2×8+2×1+9×1=27 2/-8 0/8 a 6/ 1/ 3/ b 7/ 0/ 0/0 a 1/4 6/9 3/5 b 7/2 0/0 1/-2 0/0 s 0/ t 0/ s 0/0 t c 0/ d c 0/9 1/-9 d Reverse the Flow in graph F 2/-8 0/8 Reverse the Costs also in F 2/-8 0/8 0/0 a 1/4 3/5 6/9 b 7/2 0/0 1/-2 0/0 0/0 a 3/5 6/9 1/4 b 7/2 0/0 1/-2 0/0 s 0/0 t s 0/0 t c 1/-9 0/9 d c 1/-9 0/9 d There is a negative cost cycle of value = -8 in F There is a negative cost cycle of value = -6 in F Figure 6.358 Network Flows.8.10: We show diﬀerent steps in ﬁnding maximum ﬂow at minimum cost in a Category 1 problem. We then remove negative weight cycles and subsequently reduce cost. .

A maximum ﬂow of 3 units can pushed in this network at an optimal cost of 8+4+5+2 = 19.11: We show diﬀerent steps in ﬁnding maximum ﬂow at minimum cost in a Category 1 problem. The cost is thus reduced from 27 to 19 for the same amount of ﬂow.The Max-Flow Min-Cost Problem 2/-8 359 0/8 2/-8 0/8 0/0 a 3/5 6/9 1/4 b 7/2 0/0 1/-2 0/0 0/0 a 3/5 6/9 1/4 b 7/2 0/0 1/-2 0/0 s 0/0 t s 0/0 t c 1/-9 0/9 d c 1/-9 0/9 d There is a negative cost cycle of value = 6 in F 2/-8 0/8 Circulate a unit flow in the direction of the negative cycle and the cost will decrease by 6 1/-8 1/8 0/0 1/-2 0/0 0/0 0/0 a 3/5 6/9 1/4 b 7/2 a 0/4 6/9 1/-4 3/5 b 8/2 0/0 s 0/0 t s 0/0 t 0/0 c 1/-9 0/9 d c 0/9 1/-9 d Reverse the direction of the edges in the Cycle in graph F 1/-8 1/8 0/0 Make corresponding adjustments in graph F 1/-8 1/8 a 0/4 6/9 1/-4 3/5 b 8/2 0/0 0/0 a 0/4 6/9 1/-4 3/5 b 8/2 0/0 s 0/0 t 0/0 s 0/0 t 0/0 c 1/-9 0/9 d c 0/9 1/-9 d A newly formed negative cycle Circulate a unit flow in this cycle 1/-8 1/8 0/0 Reverse the direction of the edges in the Cycle in graph F 1/8 2/8 a 0/4 6/9 1/-4 1/-5 2/5 b 0/0 2/0 a 1/4 6/9 1/4 1/5 3/5 b 8/2 1/0 1/2 2/0 s 0/0 7/2 1/-2 0/0 t s 1/0 t c 1/9 d c 1/9 d Make adjustments in graph F Now No more Negative Cycles Maximum Flow at Minimum Cost (8+5+4+2) in the original Graph D Figure 6.8. .

12: Removing a negative weight cycle of a relatively higher value may speed up the process of ﬁnding a maximum ﬂow at minimum cost.8. Connectivity and Matching Problems 2/-8 0/8 2/-8 0/8 0/0 a 1/4 3/5 6/9 b 7/2 0/0 1/-2 0/0 0/0 a 1/4 3/5 6/9 b 7/2 0/0 1/-2 0/0 s 0/0 t s 0/0 t c 1/-9 0/9 d c 1/-9 0/9 d There is a negative cost cycle of value = 8 in F Circulate a flow of 1 unit 1/-8 1/8 0/0 Reverse the direction of the edges in the cycle 1/8 2/8 a 0/4 6/9 1/-4 1/-5 2/5 b 0/0 2/0 a 1/4 6/9 1/4 1/5 3/5 b 8/2 1/0 1/2 2/0 s 0/0 7/2 1/-2 0/0 t s 2/0 t c d 1/9 c 1/9 d Make corresponding adjustments in graph F Maximum Flow at Minimum Cost in the original Graph G Figure 6.360 Network Flows. .

8.13: We show diﬀerent steps in ﬁnding maximum ﬂow at minimum cost in a Category 2 problem by removing negative weight cycles. Please note that in this category all edge capacities are equal to one .The Max-Flow Min-Cost Problem 361 a 1/0 1/2 b 1/0 1/8 a b 1/9 s 1/0 1/7 t 1/0 s t c d c 1/5 d Category 2 Category 2: Forget Capacities & ignore Costs a b 0 a 2 b 0 -8 -9 -7 s d t c s 0 t 0 c 5 d Find max edge-disjoint paths Reverse the edges in the paths and multiply edge costs in the paths by -1 a 0 2 b 0 0 a -2 b 0 -9 9 -8 s 0 -7 0 t s 0 8 7 0 t c 5 There are -ive cost cycles d 2 c -5 Reverse the edges in the cycles d a 0 Max Edge-Disjoint Paths at Min Cost b 0 8 9 7 s 0 t 0 c 5 d Figure 6.

Problem 6.10. Carefully derive the time complexity of this algorithm.10. 6. Connectivity and Matching Problems Describe this algorithm (known as Algorithm 53) in your own words and carefully derive its time complexity. In this special category of graphs the sum of capacities of all edges coming out of s is equal to the sum of capacities of all edges going into vertex t. We need to ﬁnd maximum ﬂow at minimum cost using an eﬃcient algorithm.14.10. Problem 6.3. You may design a better algorithm if you want and if you can? a 4/0 ∞/8 ∞/3 ∞/7 b 5/0 s 3/0 t d 2/0 c ∞/6 Figure 6.8. Algorithm 54 can be used to ﬁnd maximum ﬂow at minimum cost in Category 1 problems. Find if you can use any earlier techniques (Algorithm 53) to solve this interesting problem. Is this possible to use this technique (without any appreciable change) to ﬁnd the minimum cost for a ﬁxed ﬂowthe amount of ﬁxed ﬂow may not be the maximum ﬂow in the network.14: We show a special network graph D. The cost of every edge coming out of s and going into t is zero. The sum of capacities of all edges coming out of source s is exactly equal to the sum of capacities of edges going in sink t while the costs of these edges are zero.8. The capacity of every edge in the D − s − t graph is inﬁnite while the cost is a positive integer indicated in the diagram.2. The step by step working of this algorithm is demonstrated in Fig.8. Here edge capacities in graph D − s − t are all inﬁnite. Discuss brieﬂy. Is it possible to solve problems belonging to this category using Algorithm 53 even if the cost of a unit ﬂow in an edge is a real number? Discuss brieﬂy. We show an interesting special case of Category 4 in Fig. 6. .362 Network Flows.

10.6. .8.The Max-Flow Min-Cost Problem 363 Problem 6. Now consider a special case of this category where costs are expressed by binary numbers. Describe an eﬃcient algorithm to handle Category 2 problems. We have applied Algorithm 54 to solve a Category 2 problem as shown in Fig.12.6. Design a (very) eﬃcient algorithm to ﬁnd a maximum ﬂow at minimum cost in this special category. On the other extreme Category 2 & 3 problems can be solved using very eﬃcient algorithms. 6. 6. a1 1/0 1/7 b1 1/4 1/5 1/0 s 1/0 t b2 1/0 Source/sink edge costs are integers a1 1/3 1/7 b1 1/4 1/5 1/4 s 1/2 t b2 1/7 a2 1/3 a2 1/3 Equivalent Category 3 The Max flow Min-Cost Problem Category 3 The Max flow Min-Cost Problem Figure 6.8.8.15: We show that a Category 3 problem (where edges adjacent to s and t have non-zero cost) is as diﬃcult (or as easy) to solve as a Category 3 problem where the s and t edges have zero costs (top diagram). The bottom diagram shows an interesting variation of Category 3 problem where we need to minimize cost not for a maximum ﬂow but for a ﬁxed ﬂow in the network. In this category all edge capacities are equal to 1. Because of its restricted nature. thus maximum ﬂow here corresponds to maximum edge-disjoint paths as shown in Fig. we expect to solve it using a simple and a very eﬃcient algorithm.8.4. applying Algorithm 54 seems to be overkill. 6. Some of these problems were addressed in the last problem set. We have not yet devised an exact algorithm to ﬁnd maximum ﬂow (even if we ignore costs) in such problems. In between these two extremes there is an exciting range of problems to be explored. 6.5 A Panoramic Picture of Similar Problems & Solutions (once again) Please note that Category 1 problems are the most general.8. this special case is shown in the bottom diagram of Fig.

9.9.1). The right diagram shows the maximum ﬂow and the minimum cut in the network shown in the left diagram. Connectivity and Matching Problems 6. 6. a 3 4 c 2 3 3/3 a 4/1 c 2/1 s 1 3 t d 4 s 1/1 3/1 3/2 t d 4/4 b 1 b 1/1 Figure 6. We provide a systematic and step by step treatment of a number of theorems and algorithms. We shall also list down the speciﬁc problems that we shall address here. a ﬁnite . We are given a network ﬂow graph with zero lower bound. maximum ﬂow and minimum cut. These theorems as well as algorithms depend upon a number of powerful transformations. maximum ﬂow at minimum cost. 6. Please note that the ﬂow is conserved at every vertex except the source and the sink vertex. It is interesting to note that this section relies on old concepts like network ﬂows.9.1 Prior knowledge: 1. Given a network ﬂow graph with zero lower bound and a ﬁnite upper bound on ﬂow in each edge. Understanding of these transformations is a must for appreciating the new knowledge described here. etc. We shall introduce one new concept and that is of a Circulation graph. We start this section with the required prior knowledge which is essential to understand the theory and the practice described here. The lower bound on ﬂow through every edge is zero. 2.364 Network Flows.1: Left diagram shows a network ﬂow graph with upper bound on ﬂow in each edge.9 Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem We shall discuss the Circulation Problem and the related problems of ﬁnding feasible ﬂow in network ﬂow graphs. how can we ﬁnd a maximum ﬂow from a source vertex to a sink vertex? The maximum ﬂow as well as the minimum cut is indicated in the graph shown below (Fig.

the source vertex has the capability to produce an inﬁnite ﬂow while the sink vertex has .9.2) the minimum cost of a ﬂow of one unit from the source to the sink vertex is 4.2: A network ﬂow graph with upper bound on ﬂow in each edge as well as per unit cost of ﬂow through that edge. 6. shown in Fig.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 365 upper bound on ﬂow in each edge. and now we need to ﬁnd a maximum (or a ﬁxed) ﬂow at minimum cost from a source vertex to a sink vertex in the network.9.that means the actual ﬂow entering a vertex is equal to the actual ﬂow coming out of it. in contrast. In a Circulation Graph the law of conservation of ﬂow should hold for every vertex. For the rest of the vertices the law of conservation of ﬂow holds . For example in the following network ﬂow graph (Fig. We are also given a cost per unit ﬂow in each edge of the network graph. Please note that the ﬂow is conserved at every vertex except the source and the sink vertex.9. 6. it is possible to push a ﬂow of 2 units from the source vertex to the sink vertex. we should also be able to solve a slightly diﬀerent problem in which we can ﬁnd in terms of yes or no if a ﬁxed ﬂow of k units can be pushed in a network ﬂow graph from a source vertex and taken back into a sink vertex from the network. The problem is to ﬁnd maximum ﬂow at minimum cost. 6. For example in the graph. Using our prior knowledge. 3. 2/8 a 2/0 b 1/4 3/5 8/2 1/0 s 1/0 6/9 t 2/0 c 1/9 d Figure 6. In a network ﬂow graph.9.1. The lower bound on ﬂow through every edge is zero.2 New concepts In a network ﬂow graph we assume that there is a single source vertex and a single sink vertex.

5 t 5. Every edge has a lower bound as well as an upper bound on ﬂow (see Fig. 6.4). Every edge in a circulation graph may have a nonzero lower bound and an upper bound on ﬂow through this edge. 2.3: A Circulation graph with lower as well as upper bound on ﬂow in each edge.9.7 a 5 3. 3.9.9.7 b Figure 6. Every edge has an associated lower bound. We need to ﬁnd a feasible ﬂow in a network graph with a source and a sink vertex. For example a feasible ﬂow of 5 is possible in the circulation graph shown below (Fig. A feasible ﬂow in the graph is also indicated.5). Thus in a circulation graph there is no source and no sink vertex. Connectivity and Matching Problems the capability to sink an inﬁnite ﬂow. We need to ﬁnd a minimum cost feasible ﬂow in a Circulation graph. 6.9. Please note that the ﬂow is conserved at every vertex without any exception. There may also be per-unit cost associated with each edge.3). Usually this problem is known as the minimum cost Circulation Problem or the Circulation Problem. Please note that if the lower bound on ﬂow in each edge is zero then a zero ﬂow will always be a feasible ﬂow from the . 6. an upper bound. Please see the solution of the Circulation problem in the following diagram (Fig. We need to know how to ﬁnd a feasible ﬂow in a Circulation Graph where every edge has a lower bound as well as an upper bound on ﬂow. 6. and perunit cost on ﬂow through that edge.3 New Problems 1.9 s 4.366 Network Flows.9. 2.

We need to ﬁnd a maximum or a ﬁxed ﬂow at minimum cost in a network graph with a source and a sink vertex.4: A Circulation graph (left diagram) with lower bound equal to 1 and upper bound equal to ﬁve on ﬂow in each edge. source to the sink.9.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 2 367 a e d b 4 a 2 b e 3 3 a 2 b e 2 c d 3 c d 2 c Figure 6.9. 6. 4. A minimum cost feasible ﬂow is indicated in the right diagram. and per unit cost on ﬂow through this edge. an upper bound. the lower bound on ﬂow in any edge is nonzero then ﬁnding a feasible ﬂow is not a trivial problem as the zero ﬂow is not a correct answer. Please see the solution of this problem in the diagram below (Fig.6). A feasible ﬂow in the circulation graph is indicated in the middle diagram. Please note that the ﬂow is conserved at every vertex without any exception. . however. If. Every edge has an associated lower bound. The cost of a unit ﬂow through every edge is equal to one in this graph.

Each edge has an associated lower bound. A ﬂow of 4 units is a feasible ﬂow but it is taking place at a higher cost in the left diagram.9/2 2.6/3 t Figure 6. per unit cost on ﬂow.6/2 t s 2.7/3 x 3.2.taking place at minimum cost.5/5 3.3. and actual ﬂow in each edge is indicated in the respective order. The right diagram shows the same amount of ﬂow .8/2 z Figure 6. and actual ﬂow taking place in that edge.9.4/2 t 2.15/2 1.4.that is 4 units .2. .5/3 a 1.5/2 a 1.9.15/1 s 2. an upper bound. Connectivity and Matching Problems w 1.5/3 s 0.3. 1.6: Left graph is a network ﬂow with a ﬂow of 4 units taking place from the source to the sink vertex.368 Network Flows. Also note that the feasible ﬂow taking place may not be a maximum ﬂow (or a minimum ﬂow) from the source to the sink vertex. Please note that the ﬂow is conserved at every vertex except the source and the sink vertex.4. upper bound.5: A network ﬂow graph with lower bound.6/4 y 2.

Thus it may be possible that a feasible ﬂow does not exist in a Circulation graph (see the right diagram of Fig.9 s 0.5 t b 0 0.7. It will be interesting to formally prove this claim.7: Left graph is a network ﬂow graph with a source and sink vertex.9. The edge (s. 6.9. .9. here a feasible ﬂow does not exist because of obvious reasons.9. here a feasible ﬂow exists. Here all edges except one have a lower bound equal to zero. 6.5 t 0. a) has a lower bound equal to the upper bound on ﬂow and they are both equal to 2.2 a 2 0.7) while a feasible ﬂow exists in the same graph having a source and sink vertex as shown below in the left diagram of Fig.2 a No Feasible Flow 0.9. We transform the left circulation graph into the right network ﬂow graph and then claim that a feasible ﬂow exists in the circulation graph if and only if we can push a speciﬁed ﬂow (equal to 2 in this case) from the source vertex x and pull the same amount of ﬂow from vertex y in the network ﬂow graph.9 2. 6. Obviously a feasible ﬂow does not exist in this example because of obvious reasons. Right graph is a circulation graph. 6.1 s 0. 2.8.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 369 Before ﬁnding feasible ﬂow in a Network graph and in a Circulation graph we should again note that in a Circulation graph the ﬂow is conserved at every vertex while in a network ﬂow graph it is not conserved at the source as well as the sink vertex.4 Finding a feasible ﬂow in a Circulation graph with one special edge Consider the graph shown in the left diagram in Fig.1 b Figure 6.

Here the source vertex x is trying to push a ﬂow of 2 units in the network graph while the sink vertex y is trying to pull 2 units from the network graph. Please note that except for one edge all edges have lower bounds equal to zero.9. 6.9. The Circulation graph is converted into a network ﬂow graph shown in the right diagram.9 y 2 a s 0.9.9. 6.5 0. The edge (s.10. Connectivity and Matching Problems x 2 2.9 s 0. It will be interesting to formally prove this claim. 6.2 a 0.5 Finding a feasible ﬂow in a network ﬂow graph with one special edge Consider the network ﬂow graph shown in the left diagram with a designated source and a sink vertex (Fig.9).5 t b 0. .8: Left graph is a Circulation graph with associated lower bound and upper bound on ﬂow in each edge. We transform this network ﬂow graph into a circulation graph as shown in the middle diagram.1 Figure 6. Once this relationship is established then we can use earlier results to ﬁnd a feasible ﬂow provided it exists as shown in Fig.1 t b 0. We claim that a feasible ﬂow exists in the network ﬂow graph (left diagram) if and only if a feasible ﬂow exists in the circulation graph shown in the middle.370 Network Flows. a) has a lower bound equal to upper bound equal to 2.

We ﬁnd a feasible ﬂow in the Circulation graph and then convert it into a feasible ﬂow in the original network ﬂow graph shown in the bottom diagram.1 0.2 a 0.1 t Figure 6.9 y t 2 a s 0.9 s 0. First it is converted into a Circulation graph (middle diagram) and then we ﬁnd a feasible ﬂow in the circulation graph.2 a 2 0.1 Figure 6.10: Top left diagram is a network ﬂow graph with associated lower bound and upper bound on ﬂow in each edge.5 t b 0.∞ b 0.9 2.9: Left diagram is a network ﬂow graph with associated lower bound and upper bound on ﬂow in each edge.1 0.∞ 0.9 y t 2 a s 0.5 2 b 0.9. First it is converted into a Circulation graph (top right diagram).1 2.1 t b 0.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 371 x 2 2.2 a 0.9.1 s 0.9 s 0.2 a 0.1 0. x 2 2.∞ b 0. .5 0.5 t b 0.9 s 0 0.

9 2.9.9 a 0. Please note that except for one edge all edges have lower bounds equal to zero.7 t Figure 6.7 s 0.7 t b 0.9 s 0. Connectivity and Matching Problems 6. Once this relationship is established then we can use earlier results to ﬁnd a feasible ﬂow provided it exists as shown in Fig. 2 2.9.11.9 0.6 When upper bound is higher than a non zero lower bound We again consider a circulation graph (shown in the left diagram) where every edge has a lower bound equal to zero except for one special edge .5 a 0. It will be interesting to formally prove this claim. Here the source vertex x is trying to push a ﬂow of 2 units in the network graph while the sink vertex y is trying to pull 2 units from the network graph. .372 Network Flows. 6. We transform this circulation graph (left diagram) into another circulation graph shown in the middle diagram and claim that a feasible ﬂow in the left circulation graph exists if and only if a feasible ﬂow exists in the middle circulation graph.9.2 0.5 y a 0.11: Left graph is a Circulation graph with associated lower bound and upper bound on ﬂow in each edge.5 2 b 0. The edge (s.7 s 0. This edge is split into two edges as shown in the middle graph.7 a 0. The Circulation graph is converted into a network ﬂow graph shown in the right diagram.5 2 b 0. a) has a lower bound equal to 2 and an upper bound equal to 7.7 x 2.but now the upper bound is higher than a non zero lower bound on ﬂow through this edge.5 t b 0.5 t s 0.

Here the source vertex x is trying to push a ﬂow of number of units in the network graph while the sink vertex y is trying to pull the same amount of units from the network graph.6 1 a 0.2 4 5 x 2 3 2 1 x Figure 6. The Circulation graph is converted into a network ﬂow graph shown in the middle diagram. We claim that a feasible ﬂow in the circulation graph exists if and only if we can push a speciﬁed amount of ﬂow from vertex x in the middle or the right diagram.1 t b 0. y 2 2.7 s 0. Using earlier transformations we convert the circulation graph shown in the left diagram into a network ﬂow graph shown in the middle diagram.2 s 0.5 s 4.9 0.6 2 a 3.7 y 5 0. .1 t b 0. The middle network ﬂow diagram is in turn transformed into another simpliﬁed network ﬂow diagram shown in the right diagram.5 t b 5.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem Finding feasible ﬂow in a general Circulation graph 373 Here we consider a circulation graph where each edge may have a nonzero lower bound and a diﬀerent upper bound on ﬂow through this edge.12: Left graph is a Circulation graph with associated lower bound and upper bound on ﬂow in each edge.9.5 3 a 4 0.

7 a 3. Connectivity and Matching Problems y 1 2 2. We need to ﬁnd a feasible ﬂow of minimum cost in this circulation. How to solve the minimum cost Circulation Problem Consider the following circulation problem where the lower bound for each edge is 1 while the upper bound on ﬂow through each edge is 3.in this example it is equal to 1.1/1 0. In addition to lower and upper bounds we have a cost associated with each edge. This is per unit ﬂow cost for each edge .9 a 0.5 t b 5.6/2 2+3 2.7 0.7 s 0.374 Network Flows. The middle diagram shows an intermediate stage.13: Left graph is a Circulation graph with associated lower bound and upper bound on ﬂow in each edge.5 t b 5+0 5.9.7 2 1 x Figure 6.9 3+2 s 4.2/0 t b s 4+1 4. .5/3 a 3. The right diagram shows a feasible ﬂow in the circulation graph.

6. The Circulation graph is converted into a network ﬂow graph shown in the right diagram.9. The cost of per-unit ﬂow through each edge is equal to 1.15.9. But we know that this feasible ﬂow may not be the minimum cost feasible ﬂow.14: The left diagram is a Circulation graph with associated lower bound and upper bound on ﬂow in each edge. If we just want to ﬁnd a feasible ﬂow (not the minimum cost feasible ﬂow) then we know what to do. Such a feasible ﬂow is shown in the left diagram of Fig. We convert the circulation (left diagram) into a network ﬂow graph as shown in the right diagram. . Here the source vertex x is trying to push a ﬂow of 2 units in the network graph while the sink vertex y is trying to pull the same amount of units from the network graph.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 375 x Find a Feasible Flow 1 1 Push 2 units of Flow -1 +1 -1 +1 1 Upper Bound is 3 while Lower bound is 1 Upper Bound is 2 while Lower bound is 0 for black edges 1 y Figure 6. We try to push 2 units of ﬂow from vertex x. If we are successful then it means that a feasible ﬂow exists in the circulation.

9. Connectivity and Matching Problems x 1 1 Push 2 units of Flow at any Cost x 1 1 Push 2 units of Flow at Minimum Cost -1 +1 -1 +1 -1 -1 +1 1 Upper Bound is 2 while Lower bound is 0 for black edges 1 Upper Bound is 2 while Lower bound is 0 for black edges 1 +1 1 y y Figure 6.9. we should push 2 units of ﬂow from vertex x at a minimum cost as shown in the right diagram of Fig. 6.9. This provides us a solution to the (minimum cost) Circulation Problem.16. In order to ﬁnd a feasible ﬂow at minimum cost in the circulation graph of Fig.15.15: The left diagram shows that it is possible to push 2 units of ﬂow from the source vertex x at some cost. 6.9. 6. The right diagram shows that it is possible to push the same amount of ﬂow from vertex x at a lower cost in fact at a minimum cost.14.376 Network Flows. This ﬂow of 2 units at minimum cost is then translated into a feasible ﬂow at minimum cost as shown in the right diagram of Fig. .

9. We call this Problem 2. Here the ﬂow in each edge is 1 except for the red bold edges where the ﬂow is 2 units. 6. We call this Problem 1.9. The cut should separate vertex s from vertex t. We know that minimum ﬂow from vertex s to vertex t is equal to max cut in a network . Our Strategy of Solving the Circulation & other related problems Our strategy of solving the Circulation and other related problems are summarized in the following four ﬁgures which are self explainatory.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 377 x 1 1 Push 2 units of Flow at Minimum Cost Minimum Cost Feasible Flow -1 +1 -1 +1 1 Upper Bound is 2 while Lower bound is 0 for black edges 1 y Upper Bound is 3 while Lower bound is 1 Figure 6.7 Is it possible to solve the Circulation Problem for un-directed graphs? We need to ﬁnd a (or size of) maximum cut in an undirected network ﬂow graph having vertices s and t. The right diagram shows the resulting solution of the minimum cost Circulation Problem. But we know that this problem is a hard problem? Assume that we need to ﬁnd minimum ﬂow from vertex s to vertex t in a network ﬂow graph which is un-directed.16: The left diagram shows the source vertex x pushing two units of ﬂow at minimum cost.

17: Finding a feasible ﬂow in a Circulation with non zero lower bounds.18: Finding a minimum cost feasible ﬂow in a Circulation. Find Feasible Flow Network Flow Problem? (non zero lower bounds) Find Feasible Flow Circulation Problem? (non zero lower bounds) Network Flow Problem (Zero lower bounds) Figure 6.9. Find Feasible Flow at Min Cost Circulation Problem? (non zero lower bounds) Network Flow at Min Cost (Zero lower bounds) Figure 6.19: Finding feasible ﬂow in a network with non zero lower bounds.9. Connectivity and Matching Problems Find Feasible Flow Circulation Problem? (non zero lower bounds) Network Flow Problem (Zero lower bounds) Figure 6. .9.378 Network Flows.

8 z Find Maximum Flow at Minimum Cost The Circulation Problem Figure 6.3 5.7 x 3. The top ﬁgure shows that if we need to ﬁnd max cut in this directed graph (Problem 1) then we should ﬁnd the min ﬂow from vertex s to vertex t (Problem 2).5 1.3 w t 2.6 5. . The minimum ﬂow is 5 and thus the max cut will also have same size.∞ y 2.but instead a negative result.8 z y 2.7 x 3.9 2.5 1.20: The network ﬂow problem is ﬁrst converted into a circulation problem.6 0.that will give us a minimum ﬂow from s to t in the network ﬂow graph as shown below.9 2.4 t 2.3 1. In order to ﬁnd minimum ﬂow we need to make it a circulation as shown above and then ﬁnd a minimum cost circulation (Problem 3) in this graph .4 s 0.Network ﬂows with lower & upper bounds on ﬂow and the Circulation Problem 379 ﬂow graph? Suppose we can solve the circulation problem (Problem 3) at minimum cost in an un-directed graph? Then we can use the solution of Problem 3 in order to solve Problem 2? We can then use this solution to ﬁnd a solution to Problem 1? w 1.3 s 0. Thus we moved in the following fashion to ﬁnd the max cut in a network ﬂow graph? In case of un-directed graphs we have the same sort of strategy .9.

The maximum cut can now be found.22: Solving one problem solves another.9. Solve Problem 3 Solve Problem 2 Solve Problem 1 Figure 6. It essentially means that we cannot ﬁnd a minimum cost circulation in an un-directed graph while we can solve this problem in a directed graph? .9/2 2.4/2 t 2.5/3 s 0. Connectivity and Matching Problems 5.3/3 1.6/2 y 2.9.8/4 z Figure 6.380 Network Flows.3/2 x 3.7/5 w 1.21: Finding minimum ﬂow at minimum cost in a network ﬂow problem.

5 A Special Class of Graphs Eulerian Circuits and Graphs Eulerian Trails and Related Problems Eulerian Walk and the Chinese Postman Problem The Chinese Postman Problem for Directed Graphs .2 7.1 7.4 7.Chapter 7 Eulerian Graphs & the Chinese Postman Problem 7.3 7.

We make a number of inter-related claims about such graphs and then show how the proof of one claim can lead to the proof of another. Thus we start with a panoramic picture. We have claimed earlier that there is a class of graphs where even an unintelligent algorithm (like Algorithm 36) can eﬃciently ﬁnd the maximum edge-disjoint paths. Eulerian graphs belong to one of these categories which we discuss in detail. In this graph vertex a is a source vertex having only out-degree while the vertex d is a sink vertex . 7. Consider the directed graph D shown in Fig. If you are successful in ﬁnding a path then keep a record of this path otherwise exit the algorithm. Please recall Algorithm 36 which is reproduced below. We shall study this and similar classes of graphs in detail in this chapter. Exploiting our prior knowledge about this category we deﬁne a number of new categories of graphs which are to some extent similar and at the same time diﬀerent from the graphs we have seen previously. and then come back to the panoramic picture with new tools and techniques. and vertices s & t.382 Eulerian Graphs & the Chinese Postman Problem Introduction We shall start with a special category of graphs which was earlier discovered in the last chapter. Remove all edges in the path P and go to step 1.1.1 A Special Class of Graphs We have studied the problem of ﬁnding the maximum number of edge-disjoint paths from a source vertex to a sink vertex in a graph in the last chapter.1. 7. move in depth with one category. for a directed graph we shall assume that the underlying undirected graph is connected. We then come back to our categories of graphs and look at these in the light of our newly acquired experience about Eulerian graphs. We end this chapter with a detailed study of the Chinese Postman problem for both directed as well as undirected graphs. output: (Maximum) edge-disjoint paths from s to t in D 1 2 Find a directed path P from vertex s to vertex t in D. Algorithm 55: Find Maximum edge-disjoint paths from s to t in D input : Directed graph D. We shall consider connected undirected graphs.

2. The maximum number of edge-disjoint paths from the source vertex to the sink vertex is equal to the out-degree of the source vertex or the in-degree of the sink vertex. We can use Algorithm 55 to ﬁnd maximum number of edge-disjoint paths from vertex a to d in this graph (there is no need to use the more sophisticated Algorithm 37). Please note that we can use any traversal algorithm (Breadth First Search. . Every edge of the graph is covered by one of the edge-disjoint trails (or paths) from the source vertex to the sink vertex. We can ﬁnd maximum edge-disjoint paths from vertex a to d in this class of directed graphs using Algorithm 55. All directed graphs fulﬁlling the above properties are known as Class A graphs. 2. 7.A Special Class of Graphs 383 having only in-degree. z e f y d a b x c Figure 7. The maximum (number of) edge-disjoint paths in the directed graph D are shown in the left diagram of Fig.1. for the rest of the vertices of D. Please note that each edge of this graph is covered either by the trail or by the path as shown in this diagram.1: A directed graph D with two special nodes a and d. Depth First Search.1. The indegree is equal to the out-degree for every node in this graph except a and d. In this special class of graphs the in-degree of vertex d is always equal to the out-degree of vertex a (why?). the in-degree is equal to the corresponding out-degree. In fact all class A directed graphs possess the following properties: 1. The right diagram shows the same graph with one trail and one path from vertex a to vertex d in the given graph. etc) in order to execute the ﬁrst step of this algorithm.

1. We also assume that vertex a has an out-degree larger than the in-degree. There are two edgedisjoint paths from vertex a to vertex d in the graph D as shown in the left diagram. Thus the vertex a resembles a source vertex while vertex d resembles a sink vertex. Class E deals with undirected graphs where the degree of every vertex is even except for two special vertices a and d where the degree is an odd number. There are two edge-disjoint trails in this graph such that each edge of the graph is covered exactly once by either of the two trails as shown in the right diagram. Again we shall discuss the proofs later. How is this class B diﬀerent from class A and in what respect are they similar? Try to answer this question before moving forward.2: We show a directed graph of Class A: Vertex a has only outdegree while vertex d has only in-degree. Let us now deﬁne a Class B category of graphs: In this category of directed graphs we again have two special nodes a and d. For the rest of the vertices in D the in-degree is equal to the respective out-degree. an important diﬀerence this time: Vertex a has an out-degree but also an indegree while the vertex d has an in-degree but also an out-degree. the in-degree of every vertex is equal to the corresponding out-degree. The maximum number of edge-disjoint paths from the source vertex to the sink vertex can be found by Algorithm 55.384 Eulerian Graphs & the Chinese Postman Problem 3. Class C deals with directed graphs in which there are no special vertices. Class F deals with a more general category of undirected graphs in which . We shall prove these properties later in this chapter. however. Class C may also include undirected graphs where the degree of every vertex is even. There is. while the vertex d has an in-degree larger than the out-degree. z z e f y d e f y d a b x c a b x c Figure 7. For every other node in this graph the in-degree is equal to the corresponding out-degree.

. A concept map showing various classes of some special graphs.1.A Special Class of Graphs 385 Concept Map 7.

Both the graphs shown in this diagram can be partitioned into edge disjoint cycles (or circuits) shown in diﬀerent colors. for the rest of the nodes. Before moving forward. the two paths are shown in Fig. the in-degree is equal to the corresponding out-degree. Remember that the number of vertices having odd degree in a graph can not be odd (why?). There is no special vertex in this graph. An undirected graph belonging to the same category is shown in the left diagram of this ﬁgure.1. the out-degree of vertex x is 1 while its in-degree is equal to 3.3. The out-degree of vertex f is 3 while the in-degree is equal to 1. 7.1. What are the necessary and suﬃcient conditions for a (connected) graph to be cyclic? .1. 7. How other properties of a graph change (or do not change) after such a transformation is interesting to explore. It is interesting to note that a directed graph (where the in-degree of each node is equal to the corresponding out-degree) belongs to the same class as an undirected graph where the degree of each vertex is even (why?). One such property is shown in Fig. it will become a Class A or Class B graph.386 Eulerian Graphs & the Chinese Postman Problem every graph G (having p vertices) has 2k nodes with an odd degree. the in-degree of every vertex is equal to the corresponding out-degree. The degree of each node in this undirected graph is even. Can we also ﬁnd trails in this graph such that each edge of this graph is covered exactly once by one of the trails? We show a Class C directed graph in the left diagram of Fig. We show a Class B directed graph in Fig. Similarly if we add a path between vertex a and d (these are the only two vertices having an odd degree) in a Class E graph then it will be transformed into a Class C category. We can use any traversal algorithm to ﬁnd a cycle in such graphs.4.4. 7. here are a few questions that you should be able to answer by yourself: 1. the rest of the p − 2k vertices have an even degree.1. We can use Algorithm 55 to ﬁnd the two edge-disjoint paths from vertex f to vertex x in D. As you should discover yourself Class C directed and undirected graphs have some special and interesting properties.3. If however we remove (all edges in) a path from any vertex x to a vertex y in a Class C graph then the new graph will not be a Class C graph any more. 7. if we now remove edges of this cycle from the original graph then the new graph will also belong to the same class (why?).

The edge set of these graphs can be partitioned into edge-disjoint cycles (shown by diﬀerent colors) which if combined together will create a circuit consisting of all edges of the graph.4: Every node in the directed graph has an in-degree equal to the corresponding out-degree as shown in the left diagram. For every other node in this graph the in-degree is equal to the corresponding out-degree. Both these graphs belong to our Class C category.1. .1. z z e f y d e f y d a b x c a b x c Figure 7.3: A directed graph of Class B: The out-degree of node f is larger than the in-degree while the in-degree of x is larger than its out-degree.A Special Class of Graphs 387 Figure 7. An un-directed graph where the degree of each vertex is even is shown in the right diagram.

Now we make a number of claims (it will become evident from these claims that an Eulerian graph belongs to our Class C category): 1. What about if each vertex in a graph has a degree equal to at least two? Remember we are considering connected graphs only as mentioned earlier in this section. A graph G is Eulerian if and only if the edge set of G can be decomposed into edge-disjoint cycles. What can you say about other properties of this special graph? 3. Can we make the above claim if the degree of every vertex is even? 5.2 Eulerian Circuits and Graphs A graph G is Eulerian provided it contains an Eulerian circuit. 2. The degree of each vertex in a graph G is even if and only if the edge set of G can be decomposed into edge-disjoint cycles. then we should be able to prove that the degree of each vertex of G is even (you should be able to do it easily). 7. a circuit which contains every edge of G. Try to visualize such a graph. We shall start with proving Claim Number 4 and then work backwards in order to prove earlier claims. Please remember that in a circuit it is possible to visit a vertex several times but we are allowed to traverse an edge only once. A graph G is Eulerian if and only if every edge of G lies on an odd number of cycles. A graph G is Eulerian if and only if the degree of each vertex is even. So we assume that the degree of each vertex is even and now we should be able to prove that the graph G can be decomposed into edge-disjoint cycles.388 Eulerian Graphs & the Chinese Postman Problem 2. 3. Can we claim that in such a graph every vertex will lie on some cycle? 4. Let us do . Assume that a graph G can be decomposed into edge-disjoint cycles. 4. Let us consider a special case of Class C graphs where the degree of each vertex is not only even it is exactly two.

If the graph is Eulerian then there will be an Eulerian Circuit inside that graph as shown in left diagram of Fig. Let us now tackle Claim Number 3. We have earlier proved in Claim Number 4 that a graph can be partitioned into edge-disjoint cycles if and only if the degree of each vertex in the graph is even. 7. so the graph will be Eulerian. As the degree of each vertex in G is even we can ﬁnd a cycle C in G using any traversal algorithm. It is possible to build logic on this observation in order to design a formal proof.2. Remember in a circuit a vertex may be repeated but an edge cannot be repeated. This part of the proof is done and let us attempt the other part: if a graph is Eulerian then (we shall be able to prove that) it can be partitioned into edge-disjoint cycles.2.1: An Eulerian graph containing an Eulerian circuit is shown in the left diagram. 7.1.2. In Claim Number 3 we have proved that a graph G is Eulerian if and only if the edge set of G can be decomposed into edge-disjoint cycles. If this circuit is a cycle then the proof is complete otherwise it will consist of several cycles. z z e f y d e f y d a b x c a b x c Figure 7. If the edge set of a graph can be partitioned into edge-disjoint cycles then we can always combine these cycles to create a circuit which will cover every edge of the graph exactly once.Eulerian Circuits and Graphs 389 it now. Combining the two we can prove that a Graph is Eulerian if and only if the degree of each node in the graph is even. Thus the cycles forming the Eulerian circuit will be edge-disjoint as shown in the left diagram of Fig.1. The circuit can be decomposed into edge-disjoint cycles as shown in the right diagram. If we remove all the edges belonging to C from G then in the resulting graph the degree of each vertex will again be even (why?) but this new graph will have fewer edges as compared to the original graph G. .

as the degree of every vertex in G is even so if you can enter a vertex then you can leave it as well.2. As the graph G is Eulerian thus the degree of each node will be even.2 will be equal to . The total number of trails in the graph of Fig.2. n) in graph G is part of an odd number of cycles. Proving that there is an odd number of paths between vertex m and vertex n is in fact equivalent to proving that there is an odd number of trails from vertex m to vertex n. We intend to prove that the edge ab is part of an odd number of cycles in this graph. 7. 7. First assume that every edge (m. Consider vertex a which is adjacent to vertex b in this graph. Please note that if there is a counter clockwise cycle from vertex f to vertex y to vertex z and back to f then there is clockwise cycle from vertex f to z to y and back to vertex f . 7. It means that the degree of node m as well as that of n will be even. Please remember that in a trail we may repeat vertices but we cannot repeat edges while in a path neither vertices nor edges can be repeated. This may not be very obvious so we shall prove this after ﬁrst ﬁnding the number of distinct trails between the two vertices. we have to prove that every edge (m.3.2. n) will be part of an odd number of cycles is equivalent to proving that there are an odd number of paths between vertex m and vertex n (why?). thus the degree of node m as well as that of node n will be even.2: An Eulerian graph is shown. We start from a (in Fig. Now assume that the graph G is Eulerian.390 Eulerian Graphs & the Chinese Postman Problem Figure 7. Proving that edge (m.2. This means that if you draw a tree of all possible trails then the out-degree of every node in this tree will be an odd number as shown in Fig.2. in fact there will always be an odd number of ways out (why?).2) and arrive at the adjacent vertex e. Let us now concentrate on Claim Number 1. thus G will be an Eulerian graph.2. n) in G will be part of an odd number of cycles as shown in Fig. 7.

3: Consider the Eulerian graph shown in Fig. .2. We show here (middle diagram) all possible trails starting from vertex a and ending at vertex b. We show all possible paths between vertex a and vertex b in the bottom diagram.Eulerian Circuits and Graphs 391 z z e f y d e a b z f x c f y d a y d a b z x c e e f z b y e f y d a b x c a b x c y b z x b x f b f b d c b d c b b c x b d x b c x b d x b z e f y d a b x c Figure 7.2.2. 7.

7. How can you eﬃciently ﬁnd an Eulerian circuit in an Eulerian graph? 3.2. How can you eﬃciently check if a graph G is Eulerian using diﬀerent (necessary & suﬃcient) conditions for a graph to be Eulerian? 2. 7. Thus the total number of paths between vertex m and vertex n will be an odd number (why?).3 which will be an odd number (why?). How can you eﬃciently ﬁnd edge-disjoint cycles in an Eulerian graph? There are a number of exciting theoretical problems which you should attempt before moving forward: 1.3. in multi-graphs we allow parallel edges and self loops? (Hint: Can you convert a multi-graph into a simple graph?) 2.2 and Fig. 7. How can you generalize (or modify) the four claims in case of directed graphs? . How can you generalize the four claims that we have made for multigraphs. Every cycle in the graph contributes to two trails as shown in Fig.2.392 Eulerian Graphs & the Chinese Postman Problem the number of leaf vertices in the tree of Fig.2. There are a number of algorithmic issues apart from the above (theoretical) claims and their respective proofs: 1.

1. .4. 7.Eulerian Circuits and Graphs 393 Problem Set 7.2.1. Apply the above algorithm on the graph G as shown in Fig. Problem 7.1. Problem 7. Please read the following algorithm which is primarily designed to ﬁnd edge-disjoint cycles in a graph G where the degree of every vertex is even.1. Remove all edges in the Cycle C from graph G. If some edges are still left in G then go to step 1 otherwise exit.4.4: Problem 7. Someone claims that the algorithm outputs maximal number of edge-disjoint cycles in a graph G. e f y e f y a Graph G b x a b Graph H x c c Figure 7. Some one claims that the algorithm outputs edge disjoint cycles.1.2. and keep a record of it. Prove the claim or give a counter example.2. Problem 7. Someone claims that the algorithm outputs maximum number of edge-disjoint cycles in a graph G. Discuss why or why not. Algorithm 56: Find Cycles in an un-directed graph G where degree of every vertex is even input : Undirected graph G where degree of every vertex is even output: Edge-disjoint cycles in graph G 1 2 Find a Cycle C in graph G.3. Prove the claim or give a counter example. and specify each cycle output by the algorithm.1.

5.1.3 Eulerian Trails and Related Problems Let us now consider Class E undirected graphs where the degree of every vertex is even except for two special vertices f and x where the degree is an odd number (will the degree of the two odd vertices be the same? Why?). . It will be useful to design the following algorithms for an undirected graph G. Algorithm 57: Find graph G given a set of edge-disjoint cycles of G input : Edge-disjoint cycles in an unknown graph G output: Un-directed graph G (degree of every vertex in G will be even) Algorithm 58: Find an Eulerian circuit in graph G given a set of edge-disjoint cycles of G input : Edge-disjoint cycles in an unknown graph G output: An Eulerian circuit in G Algorithm 59: Find a set of edge-disjoint cycles of G given an Eulerian circuit in a graph G input : An Eulerian circuit in G output: Edge-disjoint cycles in an unknown graph G Problem 7. How would the algorithm behave in this type of graph? What will be the output of the algorithm? How will the output be diﬀerent in this case? Discuss brieﬂy.6. Assume that we apply the above algorithm to graph H which is diﬀerent from graph G.7.394 Eulerian Graphs & the Chinese Postman Problem Problem 7.1. How will the solution of earlier problems be aﬀected? 7.1. How about if we have a directed graph in which the indegree of every vertex is equal to its out-degree. Problem 7.

We can use Algorithm 56 to ﬁnd out eﬃciently one such set of edge-disjoint cycles. Several sets of edge-disjoint cycles are shown here. some having a larger size than others. .Eulerian Trails and Related Problems 395 e f y a b x e f y c e f y a b x a b x c e f y e c f y a b x a b x c c Figure 7.2.5: A graph (with every vertex having even degree) can be split up into edge-disjoint cycles. Note that every edge is part of an edge-disjoint cycle.

6: We have seen that if the degree of every vertex is even then the graph can be split into edge-disjoint cycles again shown in the top diagram.396 Eulerian Graphs & the Chinese Postman Problem b x e f e f f y c f a y b a b b x x x c e f y a b x c Figure 7. The original graph will have all nodes with even degree. There will be an Eulerian circuit in the reconstructed graph.2. The reconstruction algorithm will help you reconcile with this claim. . On the other hand if a graph can be split into edge-disjoint cycles or if the edge-disjoint cycles of a graph are given then we can reconstruct the original graph as shown in the middle diagram.

1.3. In both these graphs it is possible to ﬁnd an Eulerian trail from vertex f to vertex x. 7. the degree of every vertex is not even then the problem is to traverse each edge at least once (not exactly once) and making sure . while it is the other way round for the other special vertex.3.2 for comparison with graphs in Fig.3.2 and 7.3. a trail in which every edge of the graph is covered (exactly once).1. here the outdegree of one special vertex is larger than its in-degree by one.3. Such a graph is shown in the left diagram of Fig. 7.4 Eulerian Walk and the Chinese Postman Problem We know that if the degree of every vertex is even in an undirected graph G then we can ﬁnd an Eulerian Circuit in G by traversing each edge exactly once. If. however. 7. for the rest of the vertices the in-degree is equal to the corresponding out-degree. 7.3.1. 7. How can we prove this and how can we ﬁnd an Eulerian trail? Perhaps we can ﬁnd a constructive proof which will solve both the problems.3. the rest of the p − 2k vertices have an even degree. Again we should appreciate that we can use Algorithm 55 to ﬁnd maximum number of edge-disjoint paths from a source to a sink vertex? We have earlier presented Class B and Class A category directed graphs in Fig.3. 7. This observation should lead you to design a formal proof for the above claim. 7. The claim for such a graph G is that the edge set of G can be partitioned into k trails where each trail is connecting two odd vertices.Eulerian Walk and the Chinese Postman Problem 397 Such a graph is shown in the left diagram of Fig. with odd vertices shown in bold.1. 7. We have made certain claims about Class A graphs earlier in this chapter. Its counterpart in directed graphs is shown in the right diagram of Fig.3.1. These claims can be generalized with some interesting modiﬁcations for Class B directed graphs and then proved using our newly acquired experience of Eulerian Graphs? We now present one last claim which is applicable to Class F undirected graphs. It will then become possible to ﬁnd an Eulerian circuit in the resulting graph which is also shown in the right diagram of Fig. These graphs are reproduced in Fig. This class comprises of undirected graphs having 2k nodes with an odd degree. The right diagram shows the same graph where we add an extra edge between two odd vertices converting this graph into a Class C category where the degree of each vertex is even.

this is a Class E un-directed graph. A directed graph of Class A category is shown in the right diagram.3.3.2: A directed graph of Class B category is shown in the left diagram. the degree of vertex f and x is odd while the degree of every other vertex is even.1: An un-directed graph shown in the left diagram.398 Eulerian Graphs & the Chinese Postman Problem z z e f y d e f y d a b x c a b x c Figure 7. the out-degree of vertex f is one larger than its in-degree and it is the other way round for vertex x in this directed graph. the out degree of vertex f is three while its in-degree is 1. the in-degree is equal to the out-degree for every node in this graph except f and x. vertex a has only out-degree while vertex d has only in-degree. the in-degree is equal to the out-degree for every node in this graph except a and d. . it is the other way round for vertex x. z z e f f y d e f y d a b x x c a b x c Figure 7. A directed graph D with two special nodes f and x is shown in the right diagram.

y and x is odd while the degree of every other vertex is even. By adding two edges between odd vertices we can convert this graph into a Class C category where the degree of every vertex is even. the degree of vertex f .Eulerian Walk and the Chinese Postman Problem 399 z 3 3 4 z 4 e f y d e f y d 3 3 4 4 a b x c a b x c Degree of 4 vertices is odd Degrees of odd vertices is made even by inserting edges (shown in red color) between odd vertices z z e f y d e f y d a b x c a b x c We get an Eulerian Circuit We remove the dotted edges and get two trails Figure 7. b.3: An undirected graph of Class F shown in the left diagram.3. .

Such a walk (walk because some edges will be traversed more than once) is also known as an Eulerian walk in the graph G.2. We show a simple technique of converting a graph with odd vertices into a graph with all vertices even in Fig. traversed more than once. he would certainly like to traverse each lane at least once while making sure that the traversals of the same lane should be minimized. We ﬁnd a path from one odd vertex to another odd vertex and duplicate every edge encountered in that path.4.400 Eulerian Graphs & the Chinese Postman Problem that the number of edges. 1. in graph G we shall be traversing an edge twice when in graph H we shall be traversing a duplicated edge. 2. This problem is formally deﬁned as the Chinese Postman Problem: We need to ﬁnd a shortest closed walk in a graph G which passes through every edge of G at least once. All these possible paths gives rise to diﬀerent number of duplicated edges required to convert a graph into an Eulerian graph. We need to convert a given graph G into an Eulerian graph H by duplicating some existing edges of G. The resulting graph will be Eulerian as shown in the right diagram of this ﬁgure. we show graphs where there are two vertices of odd degree. 7. Now an Eulerian circuit in H will correspond to a closed Eulerian Walk in G.4. We need to make sure that the Eulerian trail that we have created in the ﬁrst part is shortest in terms of number of edges involved or in terms of edge weights. There are basically two problems that we intend to solve simultaneously but ﬁrst we need an understanding of these problems in isolation.3. Please note that the degree of the two terminal odd vertices in the path will become even while the degree of an even vertex in the middle of the path will stay even. Indeed there could be paths of diﬀerent edge lengths between the two odd vertices in a graph as shown in Fig. In the left diagram of this ﬁgure we have an un-weighted graph while the right diagram shows a weighted graph. This problem is faced by any post man delivering letters in houses along lanes or a sweeper who is sweeping roads. In other words the Eulerian graph H should be of minimum size in terms of number of edges or in terms of sum of edge weights of H. As you can well imagine. Each resulting Eulerian graph H will . 7. we need to minimize the total sum of edge weights in a closed walk which covers every edge of the graph at least once. are minimized. in a weighted graph. In the next ﬁgure.

We show diﬀerent Eulerian graphs corresponding to a weighted graph G in Fig. have diﬀerent number of edges.Eulerian Walk and the Chinese Postman Problem 401 Two vertices with odd degree (red color) in an unweighted graph Two vertices with odd degree (red color) in a weighted graph Figure 7. The Chinese Postman Problem for an un-weighted graph can thus be rephrased: We need to convert a graph G (having some odd vertices) into an Eulerian graph H (having all vertices with even degree) by duplicating minimum number of existing edges of graph G. consists of more edges than the graph shown in the middle diagram. Both graphs have two vertices with an odd degree. The right diagram shows a weighted graph. It is interesting to note that optimal graph. For a weighted graph we need to convert G into an Eulerian graph by duplicating certain edges such that the sum total of edge weighted corresponding to duplicated edges is minimized. .4.1: An undirected graph and un-weighted graph (left diagram). 7. we need to select the one with the minimum number. shown in the right diagram.4.4.

An Eulerian Circuit in H is equal to an Eulerian Walk in G.402 Eulerian Graphs & the Chinese Postman Problem 1 3 2 G 2 Transform G into H 1 4 H 2 4 4 4 2 3 3 4 3 Find a path between the two odd degree vertices in graph G After Duplicating the edges in the path the odd vertices in G become even and even vertices remain even Figure 7. the graph becomes Eulerian The duplicated edges are shown in red. 1 2 1 2 1 2 4 3 4 3 4 3 The duplicated edges are shown in red. The Eulerian circuit in each graph is also indicated. the graph becomes Eulerian Optimal Solution Only one edge (red) is duplicated to create an Eulerian Circuit Figure 7. The duplicated edges are shown in red color in the graph H.4.3: It is possible to convert a graph having two odd vertices into diﬀerent Eulerian graphs with varying number of edges.2: Shows how can we convert a graph G having two odd vertices into a graph H where the degree of each vertex is even. .4.

The Eulerian circuit in each graph is also indicated.4.6. A perfect matching in this graph provides the desired set of all pairs of odd vertices. The resulting Eulerian graph is shown in the right diagram of the same ﬁgure. It is quite obvious now that a shortest path between the two odd vertices provides us an optimal solution to the Chinese Postman Problem given that the graph has only two odd vertices. Let us start with an arbitrary selection of vertices in the three pairs as shown in Fig. 7.8. Thus the problem is reduced to ﬁnding the set of pairs of odd vertices which minimizes the cost of duplicating the edges. 7. 7.4. 7.7.but a diﬀerent set of pair of odd vertices may help us in further reducing this cost as shown in Fig. Do we have to enumerate all possible sets of pairs of odd vertices in the graph G? How to do that systematically and estimate what is the total number of possibilities? Is a brute force approach suitable or should we ﬁnd a way to solve this problem in a more eﬃcient manner? Given 2k items (corresponding to 2k odd vertices) numbered from 1 to 2k. 7.4: It is possible to convert a graph having two odd vertices into diﬀerent Eulerian graphs with varying number of edges.Eulerian Walk and the Chinese Postman Problem 1 9 6 4 6 2 403 1 9 2 2 1 9 2 2 2 4 6 4 4 3 7 4 7 3 4 7 3 The duplicated edges shown in red Cost is 6+7=13 The duplicated edge shown in red Cost is 9 Optimal Solution Two edges are duplicated Cost is 2+4 = 6 Figure 7.5? How about if we apply the same trick of ﬁnding a shortest path between vertices belonging to diﬀerent pairs of odd vertices? (Remember the total number of odd vertices in any graph will always be even).9. The total number of edges duplicated is also indicated in this diagram. What about if a graph G consists of more than 2 odd vertices as shown in Fig. A minimum weight .4.4. Finding shortest paths for a ﬁxed set of pairs of odd vertices certainly helps to reduce the cost of making the degree of each vertex even .4. It is possible to put weights on edges of the completely connected graph as shown in Fig. let us draw a completely connected graph consisting of 2k = 6 vertices (of G) as shown in Fig.4.

6: We ﬁnd shortest paths between a ﬁxed set of odd vertices in graph G.5: A graph G consisting of 6 odd vertices.4. . The resulting Eulerian graph H is shown in the right diagram.4. and 5 & 6 2 4 c b 3 1 a 6 e 5 d Add an extra edge in each path All vertices become even now Cost=Extra Edges=3+3+1=7 4 3 e Figure 7. 2 & 4. 2 c b 1 a 6 5 d Find shortest paths between odd vertices 1 & 3.404 Eulerian Graphs & the Chinese Postman Problem Figure 7.

perfect matching in the completely connected weighted graph will provide an eﬃcient solution to our problem as shown in the following ﬁgures. and 5 & 6 2 4 c b 3 1 a 6 e 5 d Add an extra edge in each path All vertices become even now 4 3 e Cost=Extra Edges=2+1+1=4 Figure 7. 3 & 4.Eulerian Walk and the Chinese Postman Problem 405 2 c b 1 a 6 5 d Find shortest paths between odd vertices 1 & 2.7: We ﬁnd shortest paths between a diﬀerent set of odd vertices in graph G. . The resulting Eulerian graph H is shown in the right diagram.4.

(2. every odd vertex of G is a vertex of this completely connected graph K.4).6) A Perfect Matching (1. Identify odd vertices in graph G. Create a completely connected graph K. The weight of an edge between two vertices in graph K is equal to the weight of the shortest path between the corresponding odd vertices in graph G.4). y).4).8: A perfect matching in a completely connected graph K of odd vertices of graph G. 3.406 1 Eulerian Graphs & the Chinese Postman Problem 2 3 4 3 6 2 1 2 3 4 1 2 1 3 2 2 1 1 2 3 4 1 2 2 6 3 2 3 6 2 1 3 2 3 1 2 5 4 5 2 4 5 2 4 A Perfect Matching (1. 2.3). (2. A minimum cost perfect matching in the completely connected graph K provides us the desired pairs of vertices (x. y) in graph K. For every such pair (x.6) A Perfect Matching (1. . (3.6) Figure 7. (5. (5.5). An eﬃcient solution of the Chinese Postman Problem in an un-directed graph G is thus reduced to the following steps: 1.4.2). we duplicate edges along the shortest path between vertex x and vertex y in G. (3.

9: The weight of a shortest path between two odd vertices in G corresponds to the weight of an edge between the two corresponding odd vertices in the graph K. (5. (3.6) .3).2).4). (2. (5.4).4.Eulerian Walk and the Chinese Postman Problem 407 2 c b a 6 5 d e 5 a 4 c 2 4 b 1 3 1 3 6 e d (1. (1.6) 1 2 2 1 3 2 3 6 1 1 3 6 1 3 5 4 5 4 Figure 7.

4) 3 2 5 3 (1.5). (2. how do we ﬁnd a better solution? . (2.6).3).4.3).6) 4 5 3 (1.6) 1 2 1 2 1 2 3 6 3 3 6 3 2 2 3 6 1 3 3 1 5 (1.6).2). (4.5) 4 (1.5).2).3). (4. (2. (3. (2. (3.5). (4.6). (2.6).4). (5. (3. (3.6).2). (3.3).5) 4 5 (1. (4. (2.6) 1 2 3 6 4 2 3 4 5 (1.6) 2 1 4 5 2 4 5 3 (1. (3.5) 4 1 2 1 2 1 2 2 6 4 1 3 6 4 1 5 (1. (2.4).4).5). (2. (5. (3. (3.5).4).6) 4 5 (1.6) 4 5 (1. (5. (4. (2.408 1 Eulerian Graphs & the Chinese Postman Problem 2 2 1 2 2 1 2 2 6 3 6 3 6 1 3 1 5 (1.10: We enumerate all distinct perfect matching in a completely connected graph consisting of 6 odd vertices of G.6) 4 5 (1. Please note that looking at all enumerations will be very costly.6).3).4). (2. (3. (4.4).4) 4 1 2 1 2 1 2 1 6 2 3 6 1 3 3 6 1 2 1 4 5 (1.6) 4 5 (1.4).5) 4 1 2 1 2 1 2 1 1 6 2 3 6 1 1 3 3 6 1 1 3 5 3 (1.5).6). (2. (2.3).5).5) 4 Figure 7.

4.11: The minimum weight perfect matching in a completely connected graph K among all odd vertices in G corresponds to the minimum number of edges of G which if duplicated will convert graph G into an Eulerian graph H. Without enumerating all perfect matchings in a graph we can still eﬃciently ﬁnd the minimum cost perfect matching in a graph. .Eulerian Walk and the Chinese Postman Problem 409 2 c 2 3 2 4 1 2 1 2 3 1 2 1 1 3 2 4 b 1 a 6 5 d e 3 Minimum Weight Perfect Matching in a completely connected weighted graph Add extra edges corresponding to Minimum Weight Perfect Matching Cost=Extra Edges=1+1+1=3 Figure 7.

1. Finding shortest paths from each orange vertex (with ∆ negative) to the only red vertex (with ∆ positive) will provide us the optimal solution to .5. 7. Two such vertices exist in the directed graph D and are shown in green color. A solution to this problem for an undirected graph G is not helpful even if the directed graph is derived from the same undirected graph as shown in the bottom left and right diagrams of Fig. however there are vertices with +ive and/or -ive ∆ then we face the challenge of solving the Chinese Postman Problem. Here the problem is simple: Finding a path from each of the three orange vertices to the only red vertex and duplicating edges in these paths will convert the graph G into an Eulerian graph.2. 2. 3. There are four such vertices in graph D. In contrast. If all vertices in a directed graph D have ∆ equal to zero then graph D is Eulerian.that is why graph G is not Eulerian. this graph is converted into a directed graph as shown in the top right diagram of the same ﬁgure. all shown in orange. 1. If. 7. If. We show a directed graph G where there is only one vertex with positive ∆ as shown in Fig. The diﬀerence ∆ (equal to out-degree minus in-degree) for any vertex is zero for such vertices. The out-degree is larger than the corresponding in-degree. however. all shown in red. The out-degree is equal to the corresponding in-degree. If a directed graph G have all vertices where the in-degree is equal to the corresponding out-degree then the graph G is Eulerian.5. hence ∆ is negative. hence ∆ is positive. 7. some vertices have out-degree larger or smaller than the in-degree then we need to convert graph G into an Eulerian graph H by duplicating minimum number of existing edges of G.410 Eulerian Graphs & the Chinese Postman Problem 7.5. The undirected graph G has even as well as odd vertices . We show an undirected graph G in the top left corner of Fig.1. By putting directions on edges of G.5 The Chinese Postman Problem for Directed Graphs We discuss here the Chinese Postman Problem for a directed graph. the directed graph D has three types of vertices as described below. The out-degree is less than the corresponding in-degree. There are three such vertices in graph D.

It is converted into a directed graph D as shown in the top right diagram.The Chinese Postman Problem for Directed Graphs 411 8 9 4 1 6 1 1- 8 7 1+ 1- 9 4 2+ 7 1- 6 1- 2 3 Graph G: All six odd vertices are shown in red while even vertices are shown in green 5 2 0 1+ 5 0 3 A Directed graph D derived from the un-directed graph G: Difference ∆ between out-degree and In-degree for each vertex is indicated: There are vertices with +.1: We again show an undirected graph G in the top left diagram. -.5. & zero ∆ 8 9 4 1 6 1 7 9 8 7 4 6 2 3 5 2 3 An Eulerian Walk for the un-directed G: Not applicable for directed graph D 5 We duplicate certain edges as shown in red color. The resulting multi-graph H has now become Eulerian. It is obvious that graph G is not Eulerian. The Eulerian walk in G is not an Eulerian walk in the directed graph D. . An Eulerian walk in G is shown in the bottom right diagram. After duplicating certain edges in graph G it is transformed into an Eulerian graph as shown in the bottom left diagram. Figure 7.

2: We show a directed graph G where there is only one vertex (shown in red) where the out-degree is larger than the in-degree. .5. All other vertices have either out-degree equal to in-degree (shown in green) or less than in-degree (shown in orange).412 Eulerian Graphs & the Chinese Postman Problem 8 0 0 8 7 1- 9 9 7 1 0 3+ 4 6 0 1 4 6 2 1- 5 3 0 1- 2 3 5 The Difference ∆ between out-degree and In-degree is indicated with each vertex: There is only one vertex with positive ∆ shown in red in this graph G We find a shortest path from each orange vertex (where ∆ is negative) to a vertex with positive ∆ shown in red color 0 8 2 2 0 9 7 0 0 5 5 4 1 0 4 6 0 3 7 2 0 5 3 0 0 The lengths of different shortest paths between orange vertices and the red vertex in graph G Edges in each shortest path are duplicated: The resulting graph H has now become Eulerian Figure 7.

there will be an edge from every orange vertex to every red vertex in B signifying that there will be a path from every orange vertex to every red vertex in graph G. The graph G will become Eulerian but the cost in terms of number of edges of G that are duplicated may be high. 7. The maximum ﬂow in this graph (as shown in the bottom diagram) will provide the required information. We create a bipartite graph B consisting of an A partite (consisting of all orange vertices) and a B partite (consisting of red vertices) as shown in the middle left diagram of Fig. The solution is simple: we create a weighted bipartite graph B where the weight of an edge from an orange vertex x to a red vertex y in B signiﬁes the weight of the shortest path between the orange vertex x to red vertex y in graph G. Finding a maximum ﬂow eﬃciently (in polynomial time) in this (special) network graph N is by itself an interesting problem. There are two vertices (4 & 10) with ∆ negative shown in orange color. Further adding vertices s and t and edge capacities (middle right diagram) the problem is converted into a ﬂow problem.5. An eﬃcient solution of the Chinese Postman Problem in a directed graph G is thus reduced to the following steps: . Similarly two paths should be terminating at vertex 9 to convert its ∆ from +2 to zero (please see Fig. Please note that this will be a complete bipartite graph. that single vertex has ∆ exactly equal to +3. all shown in red color.The Chinese Postman Problem for Directed Graphs 413 the Chinese Postman problem as shown in the same ﬁgure.5. Please note that all the three shortest paths originating from vertices with ∆ equal to minus 1 are terminating at a single vertex.3). duplicating edges on shortest paths ensures that the number of extra edges (added) is minimized. this will make the new directed graph Eulerian. We show a directed graph in the top diagram of Fig. 7.4.3. Please note that there should be three paths coming out of vertex 4 in order to increase its ∆ from −3 to zero. Finding a maximum ﬂow with minimum cost in a network graph N will ensure that the graph becomes Eulerian and the number of edges (which are) duplicated are minimized at the same time. 7. This has been illustrated in Fig. Vertex 4 has ∆ equal to −3 while vertex 10 has ∆ equal to −1. In order to make ∆ of every vertex zero (thus converting the graph G into an Eulerian graph) we should ﬁnd out which path originating from an orange vertex should terminate at which red vertex. Similarly there are three vertices with ∆ positive.3.5. vertex 9 has ∆ equal to +2. the problem is to minimize the cost also.5. 7.

6. & 9 6 10 2 0 1- 1+ 5 0 1 4 6 10 9 3 ∞ 3 0 1 ∞ 1 4 ∞ The path requirement can be fulfilled by finding maximum flow in this network graph: edge capacities are indicated with each edge s 1 6 10 ∞ ∞ ∞ 1 t 2 ∞ ∞ 3 1 1 9 4 ∞ s 1 6 1 t Maximum flow tells us which path coming from 4 &10 should terminate at which vertex (1.5.414 Eulerian Graphs & the Chinese Postman Problem 8 2+ 0 9 4 3- 7 0 1 1+ The Number of paths coming out of 4 & 10 should be exactly equal to the number of paths going in 1. or 9) to make the graph Eulerian 10 ∞ ∞ ∞ 2 9 Figure 7. 6.3: A maximum ﬂow in a network graph N (middle right diagram) helps us ﬁnd how to convert a directed graph into an Eulerian graph. .

Is this a coincidence or will every directed graph possess this property? Discuss brieﬂy. Convert bipartite graph B into a network ﬂow graph after adding vertices s & t. Show that a necessary & suﬃcient condition for a directed graph D to have a solution to the Chinese Postman Problem is that graph D should be strongly connected.3. the capacity of these edges will be inﬁnite. It will be interesting to derive the time complexity of the above algorithm and compare it with that of the algorithm used to solve the Chinese Postman Problem for undirected graphs.1. 7. The weight of an edge from an orange vertex x to a red vertex y in B signiﬁes the weight of the shortest path between the orange vertex x to red vertex y in graph G. while y belongs to partite B of red vertices). Identify orange and red vertices in G. The capacity of an edge from s to an orange vertex x is equal to ∆(x). it means that there should be a path between every pair of vertices in graph D. The capacity of an edge from a red vertex y to t will be equal to ∆(y). Problem Set 7. The cost of any other edge in N will be the corresponding weight in the bipartite graph.2. We show a directed graph in the top left diagram of Fig. Create a weighted bipartite graph B consisting of orange vertices as an A partite and red vertices as the B partite. Here there are four vertices with ∆ negative (shown in orange color) while . A minimum cost maximum ﬂow in the network graph N will provide us the desired pairs of orange/red vertices in graph G.5. Problem 7. 415 2. Problem 7. duplicate edges in the shortest path from vertex x to vertex y in graph G. y) pair (x belongs to partite A consisting of orange vertices.5. Problem 7.2. 3. The examples of directed graphs that we have considered in this section have one thing in common: If we sum ∆ of all vertices in a graph it comes out to be zero. Corresponding to every such (x.2.2.2. The costs of these edges will be zero.The Chinese Postman Problem for Directed Graphs 1. 4.

4: We show capacity/cost associated with each edge in the middle network graph.5. A maximum ﬂow at minimum cost in this network graph helps us ﬁnd how we can convert a directed graph into an Eulerian graph by duplicating minimum number of existing edges.416 Eulerian Graphs & the Chinese Postman Problem 8 2+ of s t t hs C o t Pa nd s Fi orte Sh 0 9 4 3- 7 0 1 1+ 6 10 1- 1+ 1 3 2 0 5 0 4 5 3 3 6 1 6 4 Ma Mi ximu n im m um Flo Co w st 0 10 ∞/3 ∞/5 1 1/0 9 s 8 2+ 0 3/0 4 ∞/3 6 1/0 1/0 t 10 ∞/1 ∞/6 ∞/4 2/0 9 4 3- 7 0 9 1+ al tim ph Op Gr a An rian le Eu 1 1+ 6 10 1- 2 0 5 0 3 0 Figure 7. .

Note that vertex 4 is duplicated in the Bipartite graph? The Difference ∆ between outdegree and In-degree is indicated with each vertex for the graph G 0 1 6 2 7 7 4 3 5 3 2 2 1 3 4 2 6 3 3 0 8 9 4 0 7 0 6 4 0 1 4 0 6 0 7 4 8 9 2 0 5 3 0 We find a minimum cost perfect matching in the complete bipartite graph We have duplicated edges in each path corresponding to the minimum cost perfect matching: The ∆ for each vertex becomes 0: The new graph H has now become Eulerian Figure 7.The Chinese Postman Problem for Directed Graphs 8 1+ 1- 417 9 4 7 1 16 2 7 7 4 3 5 3 2 2 1 3 4 2 6 3 3 1 1- 2+ 6 4 6 1- 7 4 4 2 0 5 0 8 9 3 1+ We find a shortest path from every vertex with negative ∆ to each vertex with a positive ∆. where the out-degree is less than the corresponding in-degree. shown in orange color. . Vertices where the out-degree is larger than the in-degree are shown in red color.5.5: We show a directed graph G where there are three vertices. Green vertices have out-degree equal to the in-degree. We describe how we can convert a directed graph G into an Eulerian graph H by duplicating minimum number of edges of G.

two vertices where in-degree is larger than out-degree There are two vertices where out-degree is larger than in-degree. We demonstrate an alternate scheme to solve the Chinese Postman problem.2. two vertices where in-degree is larger than out-degree 3 1 6 4 5 4 7 4 6 7 7 10 6 8 9 10 9 5 9 Figure 7. We need to convert these graphs into Eulerian graphs by duplicating minimum number of existing edges of these graphs. 7. Problem 7.5.6. 8 2+ 0 8 7 1+ 3+ 0 9 4 3- 9 4 3- 7 1+ 1 1+ 6 0 0 1 10 1- 6 0 10 2 0 1- 5 0 2 0 5 0 3 0 3 0 There are three vertices where out-degree is larger than in-degree. Solve the Chinese Postman problem for both these graphs using an eﬃcient algorithm.418 Eulerian Graphs & the Chinese Postman Problem there are three red vertices with ∆ positive.5.6: We show two directed graphs which are not Eulerian.4. Describe an algorithm behind this demonstration and calculate the time complexity of this algorithm in comparison with that of the algorithm discussed in the text (based on minimum cost maximum ﬂow algorithm). Derive the time complexity of the algorithm (that we have described in the text) which can be used to solve the Chinese Postman prob- . We show two directed graphs in Fig.2. Problem 7.5.

the graph shown in the left diagram is Eulerian while the one shown in the right diagram is neither Eulerian nor it is strongly connected.7.8.2.7. thus the graph is Eulerian.7. 7.7: We show two directed graphs.5.The Chinese Postman Problem for Directed Graphs 419 lem for directed graphs. Problem 7. Compare its value with the time complexity of the algorithm used for undirected graphs. show the detailed working of this algorithm on this graph. The Chinese Postman is supposed to start delivering his mail from a speciﬁc . Problem 7. if that is not possible then we should allow him (the Chinese Postman) to traverse the red edges at least once and come back after traversing a minimum number of edges in this graph. 7.8. The Chinese Postman is supposed to deliver mail in red streets only. 7. it is neither strongly connected yet it may be possible for the Chinese Postman to distribute mail in (only red) streets while traversing minimum number of extra graph edges.2.5.5. Figure 7.2. We need to ﬁnd an Eulerian circuit consisting of edges corresponding to red streets alone. Please describe an eﬃcient algorithm to solve this problem. please note that the in-degree of every vertex in this diagram is exactly equal to its corresponding out-degree.6. We show another directed graph in the right diagram of Fig. Problem 7.5. We show a directed graph in the left diagram of Fig. We show a directed graph G in the left diagram of Fig. This graph is not Eulerian. The Chinese Postman is supposed to distribute mail on streets shown in red color only.

The postman is supposed to traverse every edge of this graph exactly once. 7. . the red vertices have in-degree smaller than the corresponding out-degree while the orange vertices have in-degree larger than the out-degree.420 Eulerian Graphs & the Chinese Postman Problem point and end his delivery job at another point as shown in the ﬁgure.8: We show a directed graph G in the left diagram. If this is not possible then he should traverse each edge at least once and also minimize the number of edges which are traversed more than once. Design an eﬃcient algorithm to eﬃciently solve the above problem. Does the right diagram of Fig. The right diagram of this ﬁgure shows a transformation of graph G into another graph where certain edges of G are duplicated. Show that an Euler trail is possible from vertex 8 to vertex 3 in this graph.8 provide an optimal solution to our problem for the graph shown in the left diagram? Discuss brieﬂy? 5 7 4 1 End here 5 6 7 4 3 1 End here 6 3 10 10 2 8 Start here 9 2 8 Start here 9 Figure 7. the green vertices have out-degree equal to the corresponding out-degree. The right diagram shows a transformation of graph G into another graph where it is possible to ﬁnd an Eulerian Path from vertex 8 to vertex 3.5.5.

9: Eu An O ler p ian tim Gr a l ap h n Fi d M um im in o Fl w 0 t 0 .The Chinese Postman Problem for Directed Graphs 421 8 2+ 0 8 7 0 2+ 0 9 4 3- 9 4 7 0 1 1+ 6 10 2 0 1- 1+ 3- 1 1+ 6 10 1- 1+ 5 0 0 2 3 0 5 0 3 0 0 8 2+ 9 7 4 30 0 1+ 1 s 0 6 0 1+ 10 1- 2 0 5 0 3 0 Figure 7.5.

422 Eulerian Graphs & the Chinese Postman Problem a b a +1 b s t +2 s t -1 d c F Eu ind l e r Op ian tim Gr al ap h d c -2 ∞/3 2/0 a ∞/2 1/0 a +1 b c x 1/0 y t ∞/1 ∞/2 2/0 s +2 t -1 s a 2 s 1 1 d 1 c 1 3 b 1 d c -2 1 i M um n im ow Fl t Figure 7.5.10: 0 8 2+ 0 9 7 4 31+ 0 0 8 2+ 9 7 0 0 1+ 1 s 0 6 0 0 0 t 1+ 1 s 0 4 31+ 6 0 10 0 0 t 1- 2 0 10 1- 5 0 2 0 5 0 3 0 3 0 Figure 7.5.11: .

3 8.4 8.2 8.Chapter 8 Hamiltonian Graphs 8.1 8.5 8.6 Introduction Prior Knowledge Hamiltonian Graphs Bipartite Hamiltonian Graphs Some Theoretical Claims A Categorization of Hamiltonian Graphs .

Students of this topic sometimes get confused between necessary and suﬃcient conditions. Thus a Hamiltonian graph should be more than a tree graph.424 Hamiltonian Graphs 8. In Hamiltonian Graphs however. This means that no vertex should be a cut vertex and no edge is a . we are unaware of such a characterization so we shall be talking about necessary and suﬃcient conditions separately.2 Necessary Conditions for a Hamiltonian Graph A graph can not be Hamiltonian unless it is connected. 8. It will be interesting to ﬁnd suﬃcient conditions for a graph to be connected. We begin by using constructive proof techniques for certain suﬃcient conditions. however. A tree graph is connected but it can not be Hamiltonian as it has no cycles (it can. contain a Hamiltonian Path). In case of Eulerian Graphs where we have a neat classiﬁcation. 8.2. Having edges less than this limit will be a suﬃcient condition for a graph to be disconnected. We shall also be considering certain conditions (necessary and then suﬃcient) for a graph to be Hamiltonian.2 8. there should be at least p − 1 edges otherwise the graph will be guaranteed to be disconnected. It should be connected and there should be a cycle spanning all vertices.1 Introduction In this chapter. Such a graph is known as a tree where each vertex is a cut vertex and each edge is a bridge edge. the same techniques can be used to ﬁnd a Hamiltonian Cycle in a graph where a Hamiltonian Cycle is guaranteed (by the suﬃcient conditions) to exist. But then there are graphs where the number of edges is more than this critical number but still these graphs are not connected.2.1 Prior Knowledge Necessary Conditions for a Connected Graph Let us start with a familiar and simple example of a connected graph. For a graph (with p vertices) to be connected. That means this (q ≥ p − 1) will be a necessary condition for a connected graph. we shall address the problem of ﬁnding a Hamiltonian cycle and a Hamiltonian Path in a graph. It is thus a necessary condition. although a loose necessary condition. but we shall discuss this issue later in this topic. we can easily diﬀerentiate between necessary and suﬃcient conditions.

(How?) This 2 implies that the condition (minimum degree ≥ (p−1) ) is certainly a sharp 2 condition for connectedness. Eulerian. Obviously a completely connected condition would be just too loose for a graph to be just connected. and Hamiltonian (see Concept Map . The other side of the spectrum is a completely connected graph where every vertex is connected to every other vertex.2. let us solve a much familiar and also simpler problem of ﬁnding a suﬃcient condition for a graph to be connected. The minimum degree of any vertex in a graph should be at least (p−1) for a graph to be connected. We can certainly ﬁnd sharper necessary conditions as are explained in most other text books. A tree graph is just connected and belongs to one side of the extreme of connected graphs. This loose suﬃcient condition will be used in later pages to derive sharper suﬃcient conditions.3 A Loose Suﬃcient Condition for a Hamiltonian Graph Let us think of a familiar graph where a Hamiltonian Cycle is guaranteed to exist and we can ﬁnd this cycle using a trivial algorithm.2.1).Prior Knowledge 425 bridge edge in a Hamiltonian graph. It will be useful if a learner solves this problem by himself or herself.5 A Concept Map We show a concept map indicating some necessary and suﬃcient conditions for a graph to be connected.2.2. On the other hand if a graph contains a bridge edge (or a cut vertex) then it is certainly not Hamiltonian. 8. although it is perhaps an overkill and thus not a sharp suﬃcient condition. 8. 8. Thus the completely connected property is a suﬃcient condition for a graph to be Hamiltonian. Any permutation of the vertices of this graph will give you a Hamiltonian Cycle (see Fig. 2 It can also be shown that if the maximum degree of any vertex in a graph is equal to (p−2) then you can always draw a disconnected graph.4 Suﬃcient Condition for a Connected Graph Before ﬁnding a tighter suﬃcient condition for a Hamiltonian graph. Again these will be necessary conditions as there are graphs which satisfy these conditions but are not Hamiltonian. It is interesting to note that complete connectedness is not a suﬃcient condition for a graph to be Eulerian. 8.

1: A completely connected graph of 6 vertices. In case of Eulerian graphs we can ﬁnd a nice characterization that is necessary and suﬃcient for a graph to be Eulerian.2.426 Hamiltonian Graphs 1). And a minimum degree slightly larger than (p−1) is a suﬃcient condition for a graph to be Hamiltonian. Thus for a general graph which does not satisfy the suﬃcient conditions for a Hamiltonian Cycle it is extremely hard to design an algorithm which can ﬁnd a Hamiltonian Cycle (provided such a cycle exists) or out puts in negative if a Hamiltonian Cycle does not exist. We can still draw a disconnected graph if the minimum degree of a node in the graph is less than or equal to (p−2) . If the 2 minimum degree in a graph is equal to or more than (p−1) then certainly the 2 graph will be connected. If the number of edges is less than p − 1 then the graph will certainly be disconnected. Two Hamiltonian Cycles are shown in the completely connected graph. A simple Breadth First Search (or any traversal algorithm) can solve this problem eﬃciently. In case of connected or Hamiltonian graphs it is not possible to ﬁnd necessary and suﬃcient conditions. The graph may still not be Hamiltonian. We shall 2 . Subsequently we can design eﬃcient algorithms to actually ﬁnd an Euler Cycle in a graph provided the graph satisﬁes the given conditions. u5 u4 u5 u4 u6 u3 u6 u3 u1 u2 u1 u2 Figure 8. in fact we can draw a graph with the above property which is clearly not Hamiltonian. each cycle corresponds to a diﬀerent permutation of vertices of the graph. In case of connected property again it is not possible to devise necessary and suﬃcient conditions. Summary It will be interesting to summarize that what is possible (or not possible) and at what cost. Interestingly a minimum degree equal to (p−1) is a suﬃcient condition for 2 graph to contain a Hamiltonian Path. however it is possible to design eﬃcient algorithms which can determine if a given graph is connected or not.

1. A concept map of certain necessary and suﬃcient conditions for a graph to be connected. . and Hamiltonian. Eulerian.Prior Knowledge 427 Concept Map 8.

2.1. Please note that the diameter of a line graph is p − 1. Instead of simply describing the algorithms.1. For each of the problem you are supposed to design a formal proof.1. It will be interesting to explore if this is a more general result: G2 of any tree is Hamiltonian? Either show it or ﬁnd a counter example.3. Please see Fig. The k th power Gk of a graph G is a graph with same number of vertices as in G in which two vertices are adjacent if and only if they are at most d distance apart from each other in G.428 Hamiltonian Graphs now provide constructive proof techniques to prove a number of suﬃcient conditions for a graph to be Hamiltonian. You must solve this problem before moving forward.2. We shall also encourage you to solve a puzzle. Problem 8. 8.1. the experience that you will gain will provide you powerful tools that we shall use in this chapter in solving various problems. 8. we shall make you solve a number of related but simple problems. Problem Set 8. . Suppose G is a line graph then G2 has a Hamiltonian Cycle. Please note that the diameter of a star graph is equal to 2 irrespective of the order of the graph.3 Hamiltonian Graphs We shall make a drastically diﬀerent start. Let us start with simpler problems. and as it is obvious it is a function of the order of the graph.1 and Fig. If the diameter of a graph G is k then Gk will be a completely connected graph and that is why G2 of a star graph is Hamiltonian. Let us now try to solve a problem which belongs to the so called critical activity section. 8. You just need some prior knowledge in addition to some common sense. Suppose G is a star graph then G2 has a Hamiltonian Cycle. No graph (other than a line graph) can have a diameter as large as p − 1.3. Problem 8. Deciding when a speciﬁc tool can be used and where it can not be used is certainly a valuable learning experience. It is important for the learner to gain conﬁdence: You can discover and create new knowledge. For each of the above two problems it will be useful if the learner actually draws such graphs and then discovers the answer himself or herself. The diameter of a line graph is proportional to the size of the graph but still G2 is Hamiltonian.

8. The intermediate nodes are labeled as ui .3.3. But let us relax the condition that the degree of the two terminal vertices should be the same. That will be a suﬃcient condition for this graph to be Hamiltonian. Also assume that the Hamiltonian Path between u and v is already provided as an input. You are supposed to design an eﬃcient algorithm which will output the actual Hamiltonian Cycle in G. While inserting an edge from u1 to an intermediate vertex (and then an edge from up to an intermediate vertex) try your best that a Hamiltonian Cycle is not formed.2 Actually Finding a Hamiltonian Cycle in the Puzzle: Let us look at the same problem from an algorithmic point of view: You are given a graph G which contains a Hamiltonian path between two non adjacent vertices u and v.1. Assume that the sum of the degrees of u and v is equal to or larger than p. While inserting edges you should keep the degree of u1 and up exactly the same.1 A Puzzle: We are given a line graph with p nodes. You may like to solve the puzzle for the graph shown in Fig. Again this will be a suﬃcient condition for the modiﬁed graph to be Hamiltonian. instead of resisting a Hamiltonian Cycle.2 8. If. . Now the degree of one terminal vertex will be larger and the other smaller.Hamiltonian Graphs 429 8. 8. Again ﬁnd what will be the minimum sum of the two degrees (of the terminal vertices) when it will be impossible to resist a Hamiltonian Cycle. you are adamant to form one as soon as the ﬁrst opportunity arises then what will be the minimum degree of the two terminal vertices which will guarantee a Hamiltonian cycle? Now come back to the previous problem where we try to resist a Hamiltonian Cycle as far as possible.3. where 2 ≥ i ≥ p − 1 as shown in Fig.3. The problem is to ﬁnd out (by an actual trial and error drawing) the minimum degree of the two terminal vertices when it will be impossible to resist a Hamiltonian Cycle. You can not insert an edge between the two terminal nodes otherwise a Hamiltonian Cycle will immediately be formed (we already have a Hamiltonian Path between the two terminal vertices). the starting and end node of the line graph are designated as u1 and up respectively. You are allowed to insert new edges between u1 and any of the intermediate nodes. Similarly you can insert edges between up and any of the intermediate nodes.

.. We should add extra edges in this graph but do our best to avoid a Hamiltonian Cycle. A Hamiltonian Path between vertex u and v.430 Hamiltonian Graphs u1 up u1 up u2 u3 u4 u5 u2 u3 u4 u5 A graph where the degree of every vertex is 2 except for two terminal vertices An edge between the terminal vertices will instantly create a Hamiltonian Cycle u1 up u1 up u2 u3 u4 u5 Then u2 u3 u4 u5 Suppose we add an edge as shown.3. Now we should not add an edge which will now create a Hamiltonian Cycle Figure 8. Algorithm 60: Find a Hamiltonian Cycle in a graph G where deg(u)+ deg(v) ≥ p for a pair of non adjacent vertices u & v in G input : A Graph G..1: A line graph with six nodes. output: A Hamiltonian Cycle in G 1 Use the knowledge and expertise that you have gained while solving the puzzle.

3. .Hamiltonian Graphs 431 u v u v u v u v Figure 8.2: Without the red dotted edge there is no Hamiltonian Cycle in each of these graphs.

In the top graph the degree sum of the two special vertices is equal to the number of nodes in the graph.3: We are given three graphs where a Hamiltonian path exists between two special vertices. The Hamiltonian path between the two vertices is also indicated by shaded lines in each graph. in the bottom graphs the degree sum of the two special vertices is less than the number of nodes in the graph.3. Please note that a Hamiltonian Cycle exists in each of these graphs.432 Hamiltonian Graphs u5 u4 3 u6 u3 3 u1 u2 u4 u5 u4 2 3 u6 u4 2 3 u6 u3 u5 u2 u1 u2 u1 u3 Figure 8. .

p. Algorithm 61: Find a Hamiltonian Cycle in an un-directed graph G where deg(u) + deg(v) ≥ p for a pair of non adjacent vertices u & v in G. Is this not strange that a graph contains a Hamiltonian Cycle but your algorithm can not ﬁnd it? Let us now describe the details of the algorithm which solves the problem outlined above. . 8. . p − 1. x + 1.3. The index of u will be 1 while that of v will be p.4. The Hamiltonian Cycle will be 1. . . 8. . .3. 3. output: A Hamiltonian Cycle in G 1 2 3 Let us index the vertices of the Hamiltonian path like 1. please note that each of the graphs does indeed contain a Hamiltonian Cycle (which can easily be found by hit and trial method). p. . 2.3. Interestingly there may be graphs where the condition (that deg(u) + deg(v) ≥ p for a pair of non adjacent vertices u & v in G) is not met yet our algorithm will be able to ﬁnd a Hamiltonian cycle as shown in the same ﬁgure.3 in order to ﬁnd a Hamiltonian Cycle in each graph. 2. x. . . 8.5). a Hamiltonian path between u and v is also given. It is interesting to note that our algorithm also has a serious short coming: a graph may have a Hamiltonian Cycle but we can not ﬁnd it (as shown in Fig. input : A Hamiltonian Path between vertices u and v where deg(u) + deg(v) ≥ p in an un-directed graph G. Let us see where and why your algorithm fails and where it does ﬁnd a Hamiltonian Cycle. Find a vertex x such that vertex 1 is adjacent to vertex x + 1 while vertex p is adjacent with vertex x in G.Hamiltonian Graphs 433 Apply your algorithm on the graphs given in Fig. The working of the algorithm is illustrated in Fig. p − 2. 1. .

434 Hamiltonian Graphs u 2 1 v 3 6 (1) 4 5 2 1 ) (2 2 1 3 6 3 6 x x+1 4 5 (3) x x+1 4 5 Figure 8.4: Intermediate stages of how Algorithm 61 works to ﬁnd a Hamiltonian Cycle in a graph G where the condition (that deg(u) + deg(v) ≥ p for a pair of non adjacent vertices u & v in G) is met and where there is a Hamiltonian path between vertices u and v in G. .3.

A graph G shown where the condition (that deg(u) + deg(v) ≥ p for a pair of non adjacent vertices u & v in G) is not met yet the Algorithm 61 will be able to ﬁnd a Hamiltonian cycle as shown in the right diagram.3.Hamiltonian Graphs 435 Degree = 2 u5 u 3 2 u5 u u6 u3 v u6 u3 v 2 u1 u2 u1 u2 A Hamiltonian Cycle exists as shown by blue lines yet our algorithm will not be able to find it The Condition is not met yet our algorithm will be able to find the Hamiltonian Cycle shown in blue Figure 8. . but a Hamiltonian Cycle exists in this graph as shown by blue lines.5: A graph G shown (left diagram) where the condition (that deg(u) + deg(v) ≥ p for a pair of non adjacent vertices u & v in G) is not met and the Algorithm 61 will NOT be able to ﬁnd a Hamiltonian cycle.

that there will be a Hamiltonian Cycle in graph G (without that extra edge) as shown in the right diagrams of the Fig. we claim. 8. Now assume that after inserting that extra edge between the two vertices the resulting graph does not have a Hamiltonian Cycle.3. p and then going back to 1. . This intuition provides a powerful technique which can be used in most of Hamiltonian ﬁnding algorithms in Hamiltonian graphs.3. 8. 8. 3.4 Bondy & Chvatal’s Theorem: Now let us come back to a text book theorem which says that a graph G is Hamiltonian if and only if G + uv is Hamiltonian provided vertices u and v are non adjacent and deg(u) + deg(v) ≥ p. . Then. We insert an edge between these two vertices and assume that in the resulting graph there is a Hamiltonian Cycle as shown in the top left diagram of Fig. passing through 2. Then. It provides a couple of very powerful theoretical results and useful algorithmic tools which can be used to ﬁnd a Hamiltonian cycle in a certain category of graphs. Before attempting to prove this theorem let us look at the problem more closely and try to relate it to the previous knowledge that we have acquired.6.3 Basic Intuition Let us carefully look at the ramiﬁcations of Algorithm 61. 4. This essentially means that there will be a Hamiltonian Path starting from vertex 1 and terminating at vertex p in the original graph G. Consider a graph G where the degree sum of any pair of vertices in G is equal to or larger than p as shown in Fig.436 Hamiltonian Graphs 8. we claim.3. Now visualize a hypothetical Hamiltonian Cycle in this graph starting from 1. Assume that a graph G has two vertices where the degree sum of these two vertices is more than p as shown in the ﬁgure below. G+uv is Hamiltonian means that there is a Hamiltonian Cycle in the graph G+uv. . You know that we can always delete Extra edges one by one (using the techniques that we have recently acquired) forcing the Hamiltonian Cycle to divert through only graph edges. that there will not be a Hamiltonian Cycle in the graph G (without that extra edge) as shown in the left diagrams of the same ﬁgure. 8. If this hypothetical Hamiltonian Cycle does not pass through original graph edges then insert Extra edges as shown in (red) in this ﬁgure to create a cycle consisting of some original and some Extra edges.3.3.6.7. There are two possibilities: .

6: We make a number of claims in this diagram: A graph G is Hamiltonian if and only if the graph G plus an edge between two non adjacent vertices of G is Hamiltonian provided certain conditions are met.7: We make a number of claims in this diagram: A graph G is Hamiltonian if and only if the graph G plus an edge between two non adjacent vertices of G is Hamiltonian provided certain conditions are met.Hamiltonian Graphs 437 u1 up u2 u3 u4 u5 A graph G where the degree of u1 and up is equal to or more than p. u1 up u1 up u2 u3 u4 u5 u2 u3 u4 u5 Consider a graph where the degree sum of every pair of vertices is equal to or larger than p We force a Hamiltonian Cycle in this graph: If there no graph edges available then we insert Extra edges as shown in red Figure 8. . We do not know if a HAM cycle exists in graph G u1 up u1 up u2 u3 u4 u5 u2 u3 u4 u5 We insert a direct edge from u1 to up Assume that now a HAM Cycle does Not exist in the resulting graph Then Then We insert a direct edge from u1 to up Assume that now a HAM Cycle does exist in the resulting graph u1 up u1 up u2 u3 u4 u5 u2 u3 u4 u5 Now we remove the direct edge from u1 to up A HAM Cycle will NOT exist in graph G? Now we remove the direct edge from u1 to up A HAM Cycle will still exist in graph G? Figure 8.3.3.

How about if we are supposed to design an algorithm to ﬁnd a Hamiltonian Cycle in the graph G provided the above stated conditions are true. that the graph G is not Hamiltonian while the graph G + uv is Hamiltonian.3. This means the possibility. Again notice the ﬁgure of eight in this diagram. Under such conditions we can map this problem to the last problem that we have discussed except that the actual Hamiltonian Path between u and v is not provided here. . If there is a graph G in which there are two adjacent nodes u and v such that deg(u) + deg(v) ≥ p then G is Hamiltonian if and only if G + uv is Hamiltonian.8.3. As the edge uv is not part of the Hamiltonian Cycle so it is possible to remove this edge and still a Hamiltonian Cycle will exist in G. 8. its inclusion does not convert a non Hamiltonian graph into Hamiltonian and its removal does not convert a Hamiltonian graph into a non Hamiltonian graph provided other conditions are also met. Again it will be interesting to relate this algorithmic problem with the last such problem that we have discussed. Such a possibility is shown in the right diagram of Fig. 2.3.438 Hamiltonian Graphs 1. The Hamiltonian Cycle passes through the edge uv. 8. 8.6 Closure of a Graph: A closure c(G) of a graph G of order p is a graph obtained from G by recursively joining pairs of non adjacent vertices u and v whose degree sum is more than or equal to p until no such pair remains in G. does not exist. It will be instructive to actually draw such a graph. Then there will certainly be a Hamiltonian Path between the vertex u and vertex v.3.8. 8. Under such conditions a Hamiltonian Path between u and v may not exist.5 Summary Let us look at what we have really understood so far. The edge uv does not make any diﬀerence. This also means that if we remove the edge uv even then there will be a Hamiltonian Cycle in G provided there was a Hamiltonian Cycle in G + uv. The Hamiltonian Cycle does not pass through the edge uv. Such a possibility is indicated in the left diagram of Fig. It can now be proved that a graph G is Hamiltonian if and only if its closure c(G) is Hamiltonian.

8. We have already stated that complete connectedness is a very loose suﬃcient condition for a graph to be Hamiltonian. We have also stated that for a completely connected graph. degu + v ≥ p.8: A graph containing a Hamiltonian Cycle which passes through the edge between vertex u1 and u2 is shown in the left diagram. It can also be used constructively . Edges which were originally present in G. We call these edges extra edges. But it may also pass through some of the extra edges belonging to the second type.3.3. that means E(G).Hamiltonian Graphs u5 u4 u5 u4 439 u6 u3 u6 u3 u1 u2 u1 u2 Figure 8. But remember the Hamiltonian Cycle that we have found belonged to the closure of G. The right diagram shows a graph where the Hamiltonian Cycle does not pass through the edge between vertex u1 and u2 .7 Ore’s Theorem: The usefulness of the above result becomes obvious when in a graph G every pair of non adjacent vertices satisﬁes the above mentioned condition. ﬁnding a Hamiltonian Cycle is a trivial problem. The following algorithm can be used to ﬁnd a Hamiltonian Cycle in graph G. the same Hamiltonian Cycle may not exist in the actual graph G? This is because of the fact that c(G) consists of two types of edges: 1. How to ﬁnd a Hamiltonian Cycle which passes through E(G) alone is an interesting problem. 2. Extra edges inserted between very pair of non adjacent vertices u and v where deg(u) + (v) ≥ p. that is. These edges were not part of G. The Hamiltonian Cycle in c(G) will pass through some of the original edges of the graph. You can verify that a Hamiltonian path does not exist between these two vertices in the right diagram. then the closure c(G) will be obviously be a completely connected graph.

Discuss brieﬂy where it is possible to use Algorithm 62 without any modiﬁcation to ﬁnd a Hamiltonian Cycle. This suﬃcient condition was originally discovered by Ore.this closure is our starting graph H.1.2. Problem Set 8. in the ﬁrst graph G the degree sum of each pair of non adjacent vertices should be at least p. the degree sum of each pair of non adjacent vertices is not equal to p. output: A Hamiltonian Cycle in G 1 2 3 4 We ﬁnd a closure of graph G known as c(G) . thus if there is a Hamiltonian Path between u and v in H then we can ﬁnd a new Hamiltonian cycle in H which does not pass through the edge uv (use Algorithm 61). while there are extra edges in the Hamiltonian Cycle in graph H do Remove an extra edge uv from the cycle and from graph H thereby creating a Hamiltonian Path between two vertices u and v in the new graph H. . Also pinpoint the graph where it may not be easy to ﬁnd a Hamiltonian Cycle using the knowledge that we have acquired until now. input : An un-directed Graph G where deg(u) + deg(v) ≥ p for very pair of non adjacent vertices u & v in G. In the second graph H the degree sum of each pair of non adjacent vertices is not p but the closure of H is a completely connected graph. Problem 8. We know that deg(u) + deg(v) ≥ p. Algorithm 62: Find a Hamiltonian Cycle in a graph G where deg(u)+ deg(v) ≥ p for very pair of non adjacent vertices u & v in G.440 Hamiltonian Graphs to prove that if deg(u) + deg(u)v ≥ p for every non adjacent pair of vertices in a graph G then G is Hamiltonian.2. This cycle may pass through some of the graph G original edges and may also pass through some of the edges not present in G (but are present in H) known as extra edges. and last but not the least discuss where Algorithm 62 have to be modiﬁed in order to ﬁnd a Hamiltonian Cycle. Draw three diﬀerent graphs. We ﬁnd a Hamiltonian Cycle in graph H. This is certainly a tighter suﬃcient condition for a graph G to be Hamiltonian as compared to the complete connectedness of a graph. In the third graph J.

3. become important in the next example. 8.9: A graph G where the degree sum of each pair of non adjacent vertices is equal to p. Note that the closure is a completely connected graph containing a Hamiltonian Cycle also shown in the right diagram. The Hamiltonian Cycle is also indicated in this diagram. The closure of this graph is. We apply Algorithm 62 to this graph and show a number of intermediate results in Fig. A formal proof of this theorem can easily be derived from the above discussion. however.3. We remove extra edges one by one and each time ﬁnd a new Hamiltonian Cycle. however. a completely connected graph as shown in the top right diagram. 8. u5 u4 u5 u4 u6 u3 u6 u3 u1 u2 u1 u2 Figure 8. Note that the Hamiltonian Cycles passes entirely through extra edges. the extra edges removed are indicated by dotted lines while a Hamiltonian Cycle is shown by bold lines in Fig. The closure of this graph is a completely connected graph as shown in the right diagram of the same ﬁgure. A constructive proof can also be designed on similar lines. Why? The order will. the degree of some of the nodes is also indicated in this diagram. Example 2: We show a graph G in the top left diagram of Fig.10. the degree sum of a pair of non adjacent vertices is less than 6 in this graph. Please note that the order in which extra edges are removed is not very important in this example. The closure of this graph thus contains a Hamiltonian . interestingly the Hamiltonian Cycle passes entirely through extra edges.Hamiltonian Graphs 441 Dirac’s Theorem: A graph G where the degree of each node is more than or equal to p/2 is Hamiltonian. 8.3.10.3. 8.3. Example 1: We show a graph G where the degree of each node is equal to p/2 in the left diagram of Fig.9. the graph is shown in the left diagram.12. The closure of this graph is shown in the right diagram.

3. We repeat this process until all extra edges are removed. . All extra edges which are removed are shown by dotted lines. remove an extra edge and ﬁnd a new Hamiltonian Cycle.442 Remove One of the Extra edges shown in orange Hamiltonian Graphs Find Hamiltonian cycle (blue color) in the remaining graph u5 u4 u5 u4 u6 u3 u6 u3 u1 u2 w th e gr ap h ra u1 u2 u1 u4 R Remove One more Extra edge Find Hamiltonian cycle (blue color) in the remaining graph ed u1 u4 u6 u3 u6 u3 u5 u2 w th e gr ap h u5 ra u2 u4 u1 R Remove One more Extra edge Find Hamiltonian cycle (blue color) in the remaining graph ed u4 u1 u6 u3 u6 u3 u5 u2 u5 u2 u6 u4 R ed u3 u1 w th e gr ap Remove One more Extra edge ra Find Hamiltonian cycle (blue color) in the remaining graph h u3 u1 u6 u4 u5 u2 u5 u2 Figure 8. We apply Algorithm 62 to this graph.10: We start with the closure of the graph shown in the last ﬁgure.

passes through No Extra Edge Figure 8. At the end it passes through the graph edges as shown in the bottom right diagram. Another Extra Edge can NOT be removed Redraw the graph and remove another Extra Edge Hamiltonian Cycle shown in blue.Hamiltonian Graphs 443 u5 u4 u5 u4 u1 u4 u6 u3 u6 u3 u6 u3 u1 u2 u1 u2 u5 u2 Extra edges are shown in red. Initially the Hamiltonian Cycle passes through all the extra edges as shown in the top left diagram. Another Extra Edge can be removed Redraw the graph and remove another Extra Edge u4 u1 u4 u1 u1 u4 u6 u3 u6 u3 u6 u3 u5 u2 u5 u2 u5 u2 Hamiltonian Cycle shown in blue.3.11: It is possible to remove more than one extra edge (in a single step) from the graph. Another Extra Edge can be removed u3 u1 u3 u1 u5 u4 u6 u4 u6 u4 u6 u3 u5 u2 u5 u2 u1 u2 Redraw the graph and remove the last Extra Edge Hamiltonian Cycle. . We remove one Extra Edge Hamiltonian Cycle shown in blue. shown in blue.

remove other Extra Edges Figure 8. . This will increase the degree? Add Extra Edges where the degree sum condition is recently satisfied.12: While removing Extra edges. one should be very careful about the order in which they are removed otherwise one may fall into a trap as shown in the bottom diagrams. The closure is complete u5 u4 u5 u4 u5 u4 u6 u1 u6 u1 u6 u1 u3 u2 u3 u2 u3 u2 The Hamiltonian Cycle does not pass through any Extra Edge Find a Hamiltonian Cycle in the remaining graph as shown in blue color Delete an Extra Edge u5 u4 u5 u4 u6 ? u1 u2 u3 u6 u1 u3 u2 Redraw the graph and try to remove the last Extra Edge through which the Hamiltonian Cycle passes NOT Possible? Find a different Hamiltonian Cycle in the remaining graph as shown in blue color. It passes through one Extra Edge.444 Hamiltonian Graphs 4 u5 u4 2 u5 u4 u5 u4 3 u6 u3 u6 u3 u6 u3 u1 u2 4 u1 u2 u1 u2 We start with a graph where degree sum of a few pairs of vertices is not p Add Extra Edges where the degree sum condition is satisfied.3.

3.Hamiltonian Graphs 445 A given graph where degree sum condition for every pair of vertices is satisfied We add Extra Edges so that a Hamiltonian Cycle is formed. the closure is not yet complete 1 6 2 1 6 2 5 4 1 6 3 5 4 3 2 It is possible to add just one Extra Edge so as to get a Hamiltonian Cycle 5 4 3 Figure 8.13: There is no need to make the closure of a graph complete. we can add just enough extra edges such that a Hamiltonian Cycle becomes possible in the graph. .

Why this order has suddenly become important and why it was not important in the graph of Fig.3.446 Hamiltonian Graphs Cycle. If we now remove the extra edges in the wrong order then we may end up with a diﬃcult situation as depicted in the bottom right diagram of Fig.4 Bipartite Hamiltonian Graphs We are now in a position to design or discover similar suﬃcient conditions for a bipartite graph to be Hamiltonian (It will also be exciting to discover some of the necessary conditions for a bipartite graph to be Hamiltonian).14: The top left diagram shows a graph in which the degree sum of every pair of non adjacent vertices is not equal to (or larger than) the number of nodes in the graph. 8. while inserting edges you should keep in mind that in a bipartite graph.3.9? It is essential for you to answer these questions before moving forward. The closure of this graph is still a completely connected graph as shown in the bottom left diagram. Be careful this time.3. Let us solve puzzle No. 8. 8. an edge uv exists provided .12. 4 u5 u4 2 3 u5 u4 4 4 u6 u3 u6 u3 u1 u2 4 u1 u2 u5 u4 u5 u4 u6 u3 u6 u3 u1 u2 u1 u2 Figure 8.1 once again. 8. The bottom right diagram shows that a diﬃcult situation arises if we remove extra edges in the wrong order.3.

4.3 u1 u2 u3 u4 u5 u6 u7 u8 Figure 8.1. Fig.2 and Fig.4. It is always Moorish Connected. Hamiltonian Graphs: p-closure is complete in G: A Hamiltonian Cycle exists in G. While inserting an edge from u1 to an intermediate vertex (and then an edge from up to again an intermediate vertex) try your best that a Hamiltonian Cycle is not formed.1: We show a bipartite graph consisting of eight vertices containing a Hamiltonian Path between two end vertices. 8. You can not insert an edge between the two terminal nodes otherwise a Hamiltonian Cycle will immediately be formed (we already have a Hamiltonian Path between the two terminal vertices).Some Theoretical Claims 447 vertex u and vertex v belong to diﬀerent partites. Please see Fig. The problem is to ﬁnd out (by an actual trial and error drawing) the minimum degree of the two terminal vertices when it will be impossible to resist a Hamiltonian Cycle. You should also keep the degree of u1 and up exactly the same while inserting new edges. 8. . If we insert an edge between the two end vertices then a Hamiltonian Cycle will immediately be formed. Hamiltonian Connected: (p+1)-Closure is complete: A Hamiltonian Path passes through every pair of vertices.4. 8.5 Some Theoretical Claims We shall describe a number of special Hamiltonian graphs and then present a number of graph theoretical claims.4. 8. That will be a suﬃcient condition for this graph to be Hamiltonian.

similar color vertices belong to one partite while all the other color vertices are in the second partite.2: Here we show a Hamiltonian Path between two vertices in the bipartite graph shown in Fig. Notice the bi-colored vertices. an edge uv exists provided u and v belong to diﬀerent partite.1.4. 8.4. In a bipartite graph. Edges not allowed in a bipartite graph are indicated in both the diagrams in the form of dotted lines. .448 Hamiltonian Graphs u1 up u2 u7 u3 u4 u5 u6 u1 up u2 u7 u3 u4 u5 u6 Figure 8.

. You can easily think of suﬃcient condition for a bipartite graph to be Hamiltonian.4.3: A bipartite graph of sizes 8.Some Theoretical Claims 449 u v u v u v u v Figure 8. and 12. 10.

Claim No.1: We show a graph G. . u k k G k k Then there will be a HAM cycle passing through vertex u & v provided u and v are adjacent in G v k Figure 8. If the closure of G+x is complete then there will be a HAM cycle in G + x and a HAM path in G between vertex u and vertex v of G.5. If vertex u and v are adjacent in graph G then there will be a HAM cycle in G passing through u and then v. 1: Given a graph G (having p vertices). It may or may not be Hamiltonian Connected. we add and connect a vertex x to vertices u and v of G as shown in the top diagrams.450 Hamiltonian Graphs Moorish Connected: A Hamiltonian Path passes through every pair of adjacent vertices. we add a vertex x to G and connect it to vertex u and vertex v of G. Now if p + 1 closure of H (having p + 1 vertices) is complete then there will be a HAM path in G with end points u and v in G. k k G Degree of every vertex larger than or equal to k k k k u 2 k+1 k k k x k+1 v If p+1 closure is complete in graph G+x then there will be a HAM cycle in the graph G+x. the new graph is known as graph H as shown in the ﬁgure below.

5. 8. It is somewhat surprising to note that a p closure of graph G is not complete yet a p + 1 closure of graph G + x is complete. It follows that such a graph G is Hamiltonian. We are lucky in this example as we do ﬁnd a HAM path between the two given vertices. Claim No. 2: Assume that in a graph G. in fact it is more than that: every edge u. We know before hand that a HAM path exists between these vertices but we also know that there is a possibility that a HAM path exists in a graph but we are unable to conﬁrm or ﬁnd it. Degree sum of other pairs becomes 6 1 2 2 4 5 1 5 4 5 1 5 4 x 4 2 x 2 5 5 2 4 5 2 2 5 5 5 5 4 4 3 2 3 All vertices in graph G+x are now completely connected 3 All vertices in G are completely connected There is a HAM path between vertex 4 and 5 Figure 8.2: We show a graph G.2 and we need to check if our newly acquired knowledge can really conﬁrm if there is a HAM path between two vertices 4 & 5 in graph G.Some Theoretical Claims 451 Example No. Degree sum of 4 and 5 becomes 6 Connect 4 & 5. v of G. we add and connect a vertex x to vertices 4 and 5 of G as shown in the top diagram. 1: We show a graph G in Fig. the p + 1 closure is complete then there will be a HAM path between every pair u. Such a graph G (where a HAM path exists between every pair of vertices in G) is known as Hamiltonian Connected.5. . v will be part of some HAM cycle. The closure of G + x is complete and there will be a HAM cycle in G + x and a HAM path in G between vertex 4 and 5 of G. 3 4 5 1 2 4 2 1 4 2 1 3 4 x 2 5 3 2 2 x 2 5 4 x 2 5 5 4 4 4 3 3 2 3 2 3 Connect vertices where degree sum is equal to 6 Connect x to 4 and 5.

. 3: Given a graph G (having p vertices). thus we can not conﬁrm that a HAM path exists between vertex 3 and 5 in G.5. 2: We show a chain graph G in Fig. 4: Assume that in a graph G. the p − 1 closure is complete then there will be a HAM path in G. we add and connect a vertex x to every vertex of G as shown in the top diagrams.3: We show a graph G. k+1 k k+1 G Degree of every vertex larger than or equal to k k k p k+1 x k k+1 AH AM pat h in k k+1 G If p+1 closure of G+x is complete then there will be a HAM cycle in G+x Figure 8. We know that a HAM path exists between vertex 3 and 5 in this graph. we add a new vertex x to G and connect it to every vertex of G. Claim No. We add a vertex x to G and connect it to vertex 3 and 5 as shown in the top left diagram. We add a vertex x and a vertex y to G such that vertex x is connected to vertices u and v of G. thus conﬁrming that a HAM path do exist in this graph. If the closure of G + x is complete then there will be a HAM path in G.5. v. the new graph is known as the graph H as shown in Fig. Now if p + 1 closure of H (having p + 1 vertices) is complete then there will be a HAM path in G. 8.5.452 Hamiltonian Graphs Claim No. 8. and w such that u is adjacent to v and v is adjacent to w. Then we connect vertex x to every vertex in G. now the p + 1 closure of G + x becomes complete as shown in the rest of the diagrams. 5: Given a graph G (having p vertices) with three vertices u. Claim No.4 with end vertices 3 and 5. The p + 1 closure of graph G + x (having p + 1 vertices) is not complete. Example No.3.

5. The p + 1 closure of graph G + x is complete and thus a HAM path exists in the graph G as shown in the rest of the diagrams. 3 Now we can connect 2 and 5 and 3 & 4 as the degree sum is 6 Figure 8.Some Theoretical Claims 453 1 2 2 4 2 5 1 3 3 4 2 5 1 3 4 4 2 5 2 3 4 2 2 x 2 2 x 2 2 x 3 A HAM path exists between 3 and 5 but the 6 closure of this graph is not complete 3 We add vertex x to G but now connect x it to every vertex of graph G 3 We connect 2 and 4 as the degree sum is 6 1 5 5 4 5 5 1 3 5 4 3 5 5 5 2 5 x 2 3 x 3 The closure is a completely connected graph.4: The p + 1 closure of the graph G + x (having p + 1 vertices) is not complete as shown in the top left diagram. .

w Figure 8. 8.5. a HAM path exists between vertex u and vertex v of G if and only if p + 1 .5: If the p + 2 closure of graph G + x + y (having p + 2 vertices) is complete then there will be a HAM cycle in G passing from vertex u to vertex v and then to vertex w of G. Claim No.5. k v G k k k There will be a HAM cycle passing through u then v and then w in G provided u is adjacent to v and v is adjacent to w. the p + 2 closure is complete then some HAM cycle will pass through every pair of adjacent edges {u. w} in G. v} and {v.5). Now if p + 2 closure of H (having p+2 vertices) is complete then there will be a HAM cycle in G which will be passing from vertex u to v and then to vertex w (see Fig. and so on. 6: Assume that in a graph G.454 Hamiltonian Graphs and vertex y is connected to vertex v and w of G. the new graph G + x + y is known as graph H as shown in the ﬁgure below. 7: In a regular graph G where the degree of every vertex is p/2. u k G Degree of every vertex larger than or equal to k k 2 k+1 x k k+2 k v k y k k 2 k+1 k w k u k If p+2 closure is complete in G+x+y then there will be a HAM cycle passing from u to x to v to y and then to w. Claim No.

the degree of every vertex is p/2.5. How can you modify the algorithm (which was earlier used to ﬁnd a Hamiltonian Cycle in a Hamiltonian graph) which makes sure that the resulting Hamiltonian Cycle passes through a given edge. If some of the graphs do not satisfy suﬃcient conditions for Hamiltonian graphs then there is a possibility that a Hamiltonian Cycle exists but our expertise is not able to ﬁnd it.5. Problem 8. Claim No. .6).7. You can use our past experience of ﬁnding a Hamiltonian cycle in these graphs.5.1.3. v} will be part of a HAM cycle. 455 Claim No.3. 8.3. 8. u p/2 p/2 u 2 p/2 p/2 G Degree of every vertex is exactly p/2 p/2 p/2 G v p/2 p/2 x p/2 v p/2 There will be a HAM path passing through vertex u & v in G If and only if p+1 closure is complete in graph G+x Figure 8. We add a vertex x to G and connect x to vertex u and v in G as shown in the right diagram. Problem 8. 8: In a regular graph G where the degree of each vertex is p/2.5.Some Theoretical Claims closure of G + x is complete (please see Fig.6 in this regard). 8.2. where the degree of each vertex is p/2. 9: A regular graph G. Problem Set 8. is Hamiltonian Connected (that means there is a HAM Path between every pair of vertices in G) if and only if p + 1 closure of G + x is complete for every pair u and v of G (please see Fig. every edge {u. Look at the graphs in Fig.6: We show a regular graph G.

Problem 8. Problem 8. 2. Design an eﬃcient algorithm to ﬁnd a Hamiltonian path in these graphs between two given (not any two but two special) vertices. Draw a graph which is Hamiltonian (that means it satisﬁes the suﬃcient conditions) but in which there is a Hamiltonian path between every pair of non adjacent vertices. 8.3. 3. . We call it category A graphs. We call it category D graphs. 8.4.6.6 A Categorization of Hamiltonian Graphs Category A: There is not a Hamiltonian path between every pair of non adjacent vertices in G and G is Hamiltonian (that means it satisﬁes the suﬃcient conditions). We call it category C graphs. For every graph in Fig.3. Draw a graph which is Hamiltonian (that means it satisﬁes the suﬃcient conditions) but in which there is a Hamiltonian path between every pair of vertices. Also consider the option when it is Hamiltonian Connected (B2).3. We call it category B graphs. Problem 8. We call it category E graphs.5.456 Hamiltonian Graphs 1. Draw a graph which is Hamiltonian (that means it satisﬁes the suﬃcient conditions) but in which there is not a Hamiltonian path between every pair of non adjacent vertices. Category B: There is a Hamiltonian path between every pair of non adjacent vertices in G and G is Hamiltonian (that means it satisﬁes the suﬃcient conditions) and it is not Hamiltonian Connected (B1).3. Design an eﬃcient algorithm to ﬁnd a Hamiltonian path in these graphs between any two vertices. Draw a graph which is not Hamiltonian (that means it does not satisfy the suﬃcient conditions) but in which there is a Hamiltonian path between every pair of non adjacent vertices.3. Problem 8. Draw a graph which is not Hamiltonian (that means it does not satisfy the suﬃcient conditions) but in which there is a Hamiltonian path between every pair of vertices.7.7.5.3. Problem 8. check if there is a Hamiltonian cycle and also check if our expertise can ﬁnd it or can not ﬁnd it.

5.A Categorization of Hamiltonian Graphs 457 Figure 8.7: You may ﬁnd some graphs here which you were supposed to draw in earlier problems. .

some containing a Hamiltonian Path. etc. .458 Hamiltonian Graphs u5 u4 u6 u3 u1 u2 Figure 8.8: A panoramic hierarchy of graphs. some containing a Hamiltonian Cycle.5.

8. Problem 8. Category D: There is a Hamiltonian path between every pair of non adjacent vertices in G and G is not Hamiltonian (that means it does not satisfy the suﬃcient conditions). Initially you can assume that G is a regular graph and thus the degree of every vertex is the same. Try to draw a graph G where G2 is not Hamiltonian while G3 is Hamiltonian.3. v and w in G (see the bottom right diagram in Fig. Try to draw a graph G where G2 is not Hamiltonian while G3 is not Hamiltonian Connected.3. Category E: G is Hamiltonian Connected but is not Hamiltonian. 8. Try to draw a connected graph G where G3 is not Hamiltonian Connected. Try to draw a graph G where G2 is not Hamiltonian while G3 is Hamiltonian Connected.16.12. Problem 8. and the degree of every vertex is larger than or equal to p/2.3. 8.6.1).1). Problem 8.6.9. Assume that we are given a graph G with number of vertices equal to p where p is even. You can relax this condition later and cater to the condition when the degree of every vertex may be larger than p/2. Problem 8.1).10. Also consider the option when G is not Hamiltonian Connected (C2). We need to determine conditions under which there will be a Hamiltonian Path in G (see the top diagrams in Fig.14. Problem 8.6. We need to determine k such that a Hamiltonian Path (or a cycle) passes through three vertices u. We need to ﬁnd (that is design an eﬃcient algorithm to solve this . Problem 8. 8.11. We need to determine k such that a Hamiltonian Path (or a cycle) passes through every two vertices u and v in G (see the bottom left diagram in Fig.3. Prove that G3 of a graph G is always Hamiltonian. Problem 8.15. Problem 8.3.13. A graph G where the minimum degree is k is given as shown below.3.3.A Categorization of Hamiltonian Graphs 459 Category C: G is Hamiltonian (that means it satisﬁes the suﬃcient conditions) & Hamiltonian Connected (C1).3.3. Problem 8.

1: Figures for the last problem set .6.460 Hamiltonian Graphs k k k k+1 k+1 G k k p k+1 x k+1 k+1 u 2 k+1 k k x 2 u k+1 k v k+1 x k+1 2 k y w v k+1 k Figure 8.

8. Consider two options separately: (a) when the two given vertices are adjacent. If there is really a Hamiltonian path then our algorithm should be able to output this path (we should provide a proof for this).2 may provide some food for thought.6. . and (b) when they are not adjacent. The following graphs in Fig.A Categorization of Hamiltonian Graphs 461 problem) if there is a Hamiltonian path between two given vertices.

2: We show here a number of regular graphs where the degree of each vertex is exactly p/2 and p is even. .6.462 Hamiltonian Graphs Figure 8.

3 9.Chapter 9 Strongly Connected Directed Graphs and Tournaments 9.4 9.5 9. Properties & Actions Strongly Connected Directed Graphs Directed Acyclic Graphs (DAG’s) Strongly Connected Components Tournaments Unilaterally Connected Directed Graphs: .1 9.6 Concepts.2 9.

unilaterally connected directed graphs and tournaments. Properties & Actions We have earlier classiﬁed an un-directed graph on the basis of connectedness. When we make a transformation on a graph we create a graph with new properties. An undirected graph is known as strongly orient-able if it has the potential of becoming a strongly connected directed graph. On the other extreme we have seen the completely connected graph. This is how we shall study directed graphs in this chapter. and how they are connected. Some of the properties of graphs. We shall be talking about strongly connected directed graphs. We have also discussed a connected graph which was not a tree that means a graph which was cyclic. As with un-directed graphs. We shall also describe eﬃcient algorithms to ﬁnd if a directed graph is strongly connected. We have also talked about certain actions on graphs like the square of a graph or the complement of a graph. Each category of directed graph possesses some speciﬁc properties.464 Strongly Connected Directed Graphs and Tournaments Introduction We shall talk about some speciﬁc features of directed graphs in this chapter. Graphs are also judged by diﬀerent properties that they possess. These actions on a graph G transform G into another graph H. We had an un-directed graph which was not connected. and if not then what are its strongly connected components. some action items (or so called transformations). A completely connected graph is always Hamiltonian. It will be interesting to examine how diﬀerent properties of a graph change (or do not change) if we transform a graph into a new directed graph using . We shall discuss and prove (again using constructive proof strategies) necessary and suﬃcient conditions for an undirected graph to be strongly orient-able. and then we had a just barely connected graph known as a tree. For example a line graph which is acyclic and is not Hamiltonian. We have seen in the last chapter that if we take the square of a line graph or a star graph then the resulting graph is Hamiltonian. We shall start with diﬀerent categories (shown as concepts in Concept map 1) of directed graphs.1 Concepts. 9. and a classiﬁcation of un-directed and directed graphs are shown in a concept map (see Concept map 1). directed acyclic graphs. directed graphs can also be classiﬁed into diﬀerent categories.

and a classiﬁcation of undirected and directed graphs. Properties & Actions 465 Concept Map 9.Concepts. Please note that the action items are represented by elliptical objects while the properties are shown by square boxes. some action items or transformations. . A concept map showing some of the properties of graphs.1.

It is also possible to put directions in a completely connected graph in such a manner that the resulting directed graph is acyclic. Concepts As you can see in Concept map 1. Please try to pinpoint which one is which. A directed graph D is unilaterally connected provided for every pair of vertices u and v. The third is neither unilaterally connected nor strongly connected. One of these graphs is acyclic while the rest are cyclic. When we put directions in an un-directed (or bi-directed) graph G then it becomes a directed graph D. and is therefore not strongly connected. It is obvious that a tournament directed graph may be acyclic . there is a path from u to v or a path from v to u.466 Strongly Connected Directed Graphs and Tournaments some of the action items shown in Concept map 1. That means a strongly connected graph is always a unilaterally connected graph but not vise versa. This means that if we intelligently put directions in a completely connected un-directed graph then the resulting directed graph will be strongly connected (or unilaterally connected). Those which can be converted into a strongly connected graph are known as strongly orient-able un-directed graphs. 9. Fig. If we remove directions from a directed graph D then the resulting graph will become undirected and is known as the underlying undirected graph. A directed graph having no cycles is called an directed acyclic graph or a DAG. One of them is strongly connected. Both strongly connected as well as unilaterally connected directed graphs are always weakly connected but again it may not be true the other way round. The other is unilaterally connected but not strongly connected. A directed graph formed by putting arbitrary directions in a completely connected undirected graph has a special name that is a tournament.1. If the underlying undirected graph of D is connected then D is known as a weekly connected directed graph. In a strongly connected directed graph there is a path from u to v and a path from v to u. A directed graph where you can reach any vertex from any other vertex is known as a strongly connected graph. Un-directed graphs which can be converted into a unilaterally connected directed graph are known as unilaterally orient-able undirected graphs. Not all un-directed graphs can be converted into a strongly connected directed graph. Completely connected un-directed graphs are both unilaterally orient-able and strongly orient-able. directed graphs can also be classiﬁed on the basis of connectedness.1 shows three diﬀerent directed graphs.

The resulting graph should be cyclic and not unilaterally connected. A graph consisting of six vertices is shown in Fig. in fact it may contain a Hamiltonian Cycle. We have not asked you to draw a graph which should be acyclic and strongly connected. One of them is strongly connected. Problem 9.1.1. You are supposed to put directions in these undirected edges in order to fulﬁll some objective as deﬁned below.2.1. Problem Set 9.Concepts.2. or may contain a cycle.1.1. as we shall discuss in detail in this chapter. Only two edges in this graph are directed while the rest are left un-directed or bi-directed. Problem 9. Properties & Actions 467 2 1 3 4 6 5 2 1 3 6 1 2 3 4 5 4 6 5 Figure 9. Why? . Problem 9.1. The resulting graph should be acyclic and not unilaterally connected.4. After putting appropriate directions draw the directed graph D. 9.1: Three diﬀerent directed graphs. The resulting graph should be acyclic and unilaterally connected.1. Problem 9.1.3.

A directed graph in which every node lies on a directed cycle but the graph is not strongly connected.3. A directed graph in which every node lies on a directed cycle but the graph is not strongly connected.1.5.2.2. Problem 9. The directed graph should be weekly connected. A directed graph in which if there is a path from u to v then there is a path from v to u for every pair of vertices u and v in D.2.1.468 Strongly Connected Directed Graphs and Tournaments Problem 9. Problem 9.8. Will the resulting graph always be unilaterally connected? Discuss brieﬂy.2: A graph in which only two edges are directed while the rest are left un-directed. Problem 9. 3 4 . The resulting directed graph should be cyclic but not strongly connected.1. The resulting graph should be unilaterally connected but not strongly connected. The resulting directed graph should be cyclic and strongly connected.6. Problem 9.2. Problem 9. The directed graph may not be weekly connected.1. 2 1 6 5 Figure 9.7.1. You are supposed to make it a directed graph by putting directions on un-directed edges in order to fulﬁll certain objectives Problem Set 9. The resulting graph should be unilaterally connected. Draw a directed graph D in order to fulﬁll the following objectives: Problem 9. not strongly connected but cyclic.1. and D is not strong.2.

The Reachable Relation matrix of an undirected connected graph will contain all 1’s. As we know in a walk a node as well as an edge may be traversed several times. This deﬁnition is almost the same as given in the last chapter for un-directed graphs. v) = 1 provided there is a directed path from u to v in D. Similarly the Reachable Relation matrix of a strongly connected directed graph will also contain all 1’s. or acyclic? Discuss brieﬂy. A directed graph D is n − cyclic if it contains a directed cycle consisting of n nodes where n ≤ p.Concepts. A weekly connected directed graph in which for every pair of vertices u and v. if there is a path from u to v then there is no path from v to u. An Eulerian Trail may pass through a vertex several times but it should pass through every edge exactly once. Properties & Actions 469 Problem 9. The Reachable Relation graph of D can be represented by an adjacency matrix A in which A(u. A Hamiltonian Path or a spanning path spans every vertex only once but is not closed so you can not come back from where you have started. We know that a spanning cycle passes through every vertex exactly once.4. Action Items Let us now discuss some of the action items or so called transformations. We shall introduce more action items as the need arises.2. A directed graph D is transitive if and only if there is an edge from u to v provided . unilaterally connected. A closed spanning walk in a directed graph D passes through every node of D and comes back from where it has started. and it is zero otherwise. If n = p then the graph D is Hamiltonian. Will the resulting graph be strongly connected. Properties A directed graph D is Hamiltonian provided there is a spanning cycle in the graph. An Eulerian Trail is a closed trail which spans all edges exactly once. The Reachable Relation (or the transitive closure) of a directed graph D is another directed graph in which there is an edge from vertex u to vertex v provided v is reachable from u in D. The square of a graph D is another graph (known as) D2 in which there is an edge from vertex u to vertex v provided there is a two edge path from u to v or there is an edge (that is a one edge path) from u to v in D. The transpose of a directed graph D is another directed graph E in which there is an edge from u to v if and only if there is an edge from v to u in D.

7.3.5.3.470 Strongly Connected Directed Graphs and Tournaments there is an edge from u to any vertex w and an edge from w to v for every pair of vertices u and v in D. 2 1 3 4 6 5 Figure 9.3. Problem Set 9. Problem 9. .3. Is this graph strongly connected? Why? Problem 9. Problem 9.1.3.3. Problem 9. Is D2 Hamiltonian? Discuss brieﬂy.1.3. answer the following: 9.3: A directed graph D for the problem set. Find a closed spanning walk in this graph.2.6. Problem 9. For the directed graph D shown in Fig.3.4.3.1.8. Is this graph Hamiltonian? Discuss brieﬂy. Problem 9. Draw D2 . Is the transpose also strongly connected? Why? Problem 9. Find a Reachable Relation Matrix for this graph. Is D or D2 transitive? Discuss brieﬂy.3. try to Problem 9. Draw the transpose of the graph.3.

Transitive. A strongly connected graph may not be Hamiltonian but it perhaps should always contain a cycle of length n where n < p. When a graph is strongly connected then it is possible to reach every vertex from every vertex in that graph. These properties are: 1.2 Strongly Connected Directed Graphs Let us focus on a strongly connected graph (we consider it as the current concept). Let me now pick one action item. Eulerian Trail 3. A directed graph which is Hamiltonian contains a Hamiltonian Cycle. that is every strongly connected graph is Hamiltonian? I think you should be able to ﬁnd a counter example quite easily. In such graphs it is possible to ﬁnd a Eulerian trail.2). n-cyclic 5. this implies that every vertex is reachable on this cycle. a trail passes through every edge exactly once but may pass through a vertex several times. Is it the other way round also. Why it can not be an acyclic graph? Because otherwise it will not be possible to reach from v to u if it is possible to reach from u to v. Closed spanning walk 4. Again it is not the other way round that is every cyclic graph may not be strongly connected (we have already witnessed this in a problem set). that is. Please do it before moving forward. Hamiltonian Cycle 2. This directly implies that the Reachable Relation matrix of a strongly connected graph will contain all 1’s (see Concept map 9. As every vertex is visited at least once and we come back from where we have started thus every Eulerian graph .Strongly Connected Directed Graphs 471 9. and thus such a graph will be strongly connected. Does it also imply that if the Reachable Relation matrix of a graph contains all 1’s then the graph is strongly connected? I think it is quite obvious that the answer is yes. the Reachable Relationship of a directed graph. Thus a strongly connected graph should never be acyclic. Let us now focus on Eulerian directed graphs. Keep in mind a number of properties a directed graph can possess.

After looking at Hamiltonian or Eulerian graphs which are quite restrictive in nature. 1 2 7 1 2 u v 7 6 U 3 8 6 W 3 8 5 4 9 5 4 9 Figure 9.2. that will in fact be a closed walk. it may. We repeat this process until the closed walk becomes a closed spanning walk (see Fig. it will still be possible to come back to vertex u. We also know that in a strongly connected graph it is possible to move from any vertex to any other vertex. It uses the Reachable Relation of a graph as an intermediate or a so called bridging concept. Let us call this a closed walk U . This will result in another closed walk W which when merged in U gives us a closed walk with more vertices that in U . Algorithm 63 answers if a given directed graph is strongly connected (or not) in a polynomial time algorithm.1: A closed walk U is indicated in a directed graph D. however. Another closed walk W is also shown in the same directed graph. When we merge U and W we shall get a closed spanning walk in the graph D. go to vertex v.472 Strongly Connected Directed Graphs and Tournaments will be strongly connected but not vise versa. be not a closed spanning walk. As U does not span all vertices thus there will be a vertex u in U which will be connected to a vertex v of D which is not part of U (why?). We are now in a position to design algorithms to solve a number of related problems. We can start from u.2. Once we have the Reachable Relation we have some information about the nature of the directed graph. We know that it is possible to traverse a node or even an edge several times in a walk. 9. let us look at a relatively more general graph D which contains a closed spanning walk. A graph D is strongly connected if and only if we can ﬁnd a closed spanning walk in D or D is strongly connected if and only if the Reachable Relationship of D contains all 1’s. Let us summarize of what we have gained so far. it means that you can always come back to a vertex from where you have started.1). .

and strongly connected directed graph is exactly the same. a couple of properties and an action item which is the Reachable Relation.Strongly Connected Directed Graphs 473 Algorithm 63: Check if directed graph D is strongly connected input : Directed graph D output: Graph D is Strongly Connected or not 1 Transform the Directed Graph D into a Reachable Relation graph by applying any traversal algorithm on every vertex of D. A map showing the concept of a strongly connected graph. Eulerian. It is interesting to note that the Reachable Relation graph of a Hamiltonian. Concept Map 9.2. . If the Reachable Relation matrix contains all 1’s then the graph D is strongly connected otherwise not.

Algorithm 65: Find a closed spanning walk in a strong graph D input : A strongly connected directed graph D output: A closed spanning walk in D 1 2 Find a closed walk u in D.474 Strongly Connected Directed Graphs and Tournaments If the relation matrix contains all 1’s then the graph D is strongly connected otherwise it is not. Convert it into a cycle. The given directed graph D may not be strongly connected but it should contain a cycle. Algorithm 64 ﬁnds a cycle in a directed graph D. If D is strongly connected then it will certainly contain a cycle. Khawaja Fahd says that we should just check the diagonal boxes in the Reachable Matrix and there is no need to check any other box. What do you think? It is interesting to note that it is possible to design a much more eﬃcient algorithm to solve the same problem but then we need some more concepts and a deeper insight into the problem. Increase its size until it becomes a closed spanning walk as previously explained in this section. Algorithm 64: Find a cycle in a directed graph D input : A directed graph D which is not acyclic output: A cycle in D 1 2 Find a closed walk u in D. In this algorithm ﬁrst we ﬁnd a closed walk in graph D using any traversal algorithm. Note that this algorithm is directly related to the (constructive) proof which proves that a directed graph D is strongly connected if and only if D contains . We shall address this problem once we acquire the required knowledge. It will be interesting to derive the time complexity of this algorithm and to make it more eﬃcient if possible. A closed walk can always be converted into a cycle.

Will it be still possible to reach any vertex from any vertex in this graph? If yes then the transpose of D will always be strongly connected provided D was strongly connected. every directed edge should be part of a directed cycle otherwise it will be impossible to ensure reach ability from any vertex to every other vertex. It is obvious that the un-directed G should be connected. This implies that a graph G should not contain any bridge edge for G to be strongly orient-able. we have taken the transpose of D. On the other hand there are un-directed graphs where it is impossible to convert them into strongly connected directed graphs. We should remember that the desired directed graph should not only be cyclic. 9.Strongly Connected Directed Graphs 475 a closed spanning walk. Now assume that we reverse the direction of each edge in graph D. We next consider a class of un-directed graphs (known as strongly orient-able) where if we put a direction intelligently on each edge then the resulting directed graph will be strongly connected. that is. It will again be interesting to derive the time complexity of this algorithm and to make it more eﬃcient if possible. Is a strongly connected graph D transitive? Should it never be transitive? If it is transitive then will it be a special strongly connected graph? If a strongly connected graph D is not transitive then will D2 be transitive? Under what conditions D2 be transitive? We know that in a strongly connected graph D it is possible to reach any vertex from any vertex in D. It is interesting (or shocking) to note that the underlying un-directed graph of a strongly connected graph may not be strongly orient-able (why?).1). The proof was earlier presented informally in this section.2. It should not be acyclic otherwise it will be impossible to create a directed cyclic graph out of it which is strongly connected. One of the necessary conditions for a graph to be Hamiltonian is that there should be no cut vertex. The algorithm is quite similar to the algorithm . Let us discuss strongly connected graphs in terms of one more property (transitive) and one more transformation (transpose). Is this also a necessary condition for a graph G to be strongly orient-able? The following algorithm converts an un-directed graph with no bridge edges into a strongly connected directed graph by putting appropriate direction on each edge (see Fig. Strongly orient-able Un-directed Graphs We need to discover necessary and suﬃcient conditions for an undirected graph G to be transformed into a strongly connected graph.

Increase the size of the spanning walk until it becomes a closed spanning walk as previously explained. It will be worthwhile to conjecture that if G is connected but not strongly orient-able then G2 is certainly strongly orient-able. a vertex u is reachable from v and the vertex v is reachable from u for every vertex u and v in D. Thus a DAG can never be strongly connected. or a closed walk can not exist in a DAG. here if a vertex v is reachable from u then the vertex u is not reachable from v for every pair of vertices u and v in a DAG.3 Directed Acyclic Graphs (DAG’s) In a strongly connected directed graph every vertex is reachable from every other vertex. As it should be evident. We have also seen that G2 of a star graph is also Hamiltonian. 9. You should either prove this conjecture or ﬁnd a counter example. Algorithm 66: Convert an un-directed G into a strongly connected D input : An un-directed graph G output: A strongly connected directed graph D 1 2 3 Find a closed spanning walk u in G. a DAG is quite the apposite. Put appropriate directions. In other words there is no cycle in a DAG and that is why the name: directed acyclic graph. an n-Cycle. As opposed to a strongly connected graph. an Eulerian Trail. We have seen in the last chapter that G2 of a line graph is Hamiltonian and is therefore strongly orient-able. that is. That will in fact complete the proof of a theorem which states that a connected graph G is strongly orient-able if and only if G contains no bridge edges. a Hamiltonian Cycle. The algorithm can also be used as a constructive proof to prove that if there are no bridge edges in an un-directed graph G then it is possible to convert G into a strongly connected directed graph D. We have yet to prove that if there is a bridge edge in a graph G then it is impossible to convert G into a strongly connected graph D. Can a DAG be unilaterally connected? Can a DAG be not unilaterally connected? Should a DAG be always transitive or always not transitive? These are some of the questions .476 Strongly Connected Directed Graphs and Tournaments used to ﬁnd a closed spanning walk in a strongly connected directed graph.

It is interesting to note that the underlying undirected graph of a DAG will be an undirected graph. If the undirected graph is a tree then we may put an arbitrary direction on each edge and the resulting directed graph will guaranteed to be a DAG. An intermediate node has both in degree as well as out degree. the transpose of a DAG. A tournament DAG is always transitive (why?). What happens to these vertices when we take a transform of a DAG? A source node has no in-degree but when we reverse directions it will have no out-degree so it will be transformed into a sink as shown in Concept map 9. 9. a sink vertex. A source node is deﬁned as a node with no in degree while a sink node has no out degree. Similarly the sink of the original DAG will be transformed into a source in the transpose of the DAG. For example every DAG will have at least one source node and at least one sink node in addition to other ordinary (sometimes called intermediate nodes). as this DAG is derived from a completely connected un-directed graph so it is known as a tournament DAG.3. There are certain nodes in a DAG which have some special features not noticed in other directed graphs.4. We shall shortly provide an eﬃcient algorithm to solve this problem. Answer these questions before moving forward. how the matrix will tell us that it represents the reachable relation for a directed acyclic graph? . the direction of each edge is reversed only. On the other hand if an un-directed graph is completely connected then we have to be careful in selecting the direction of an edge in order to transform G into a DAG. Will the transpose of a DAG always a DAG? Why? It will obviously contain the same number of vertices and exactly the same number of edges.Directed Acyclic Graphs (DAG’s) 477 which should trouble your mind. How about if we take the square of a DAG? Will the resulting graph also a DAG? How the roles of diﬀerent vertices change or remain the same in the square graph? Will the resulting graph be transitive? If we draw a Reachable Relation matrix A for a DAG.4). Perhaps you may like to ﬁnd a non tournament DAG which is also transitive? Let us look at a DAG along with an action item. But then a DAG consists of a source vertex. Looking from the other way round you can start from any undirected graph G and put a direction on each edge such that the resulting directed graph becomes a DAG (in fact it can be converted into several diﬀerent DAG’s). Try your luck and design an algorithm which can transform an un-directed completely connected graph into a DAG (see Fig. and a number of intermediate vertices.

This visualization of a DAG may encourage us in devising a scheme to convert an un-directed graph into an acyclic directed graph. identify tree edges. Back edges 5. you must have become familiar with Depth First Search of a graph while studying algorithms.3.4. In this so called topological sort. 9. Problem Set 9. and cross edges if any.2. 9.2). Forward edges 3.4. Finishing times of all vertices (please see Concept map 9. For the directed acyclic graph D shown in Fig. More importantly it is beneﬁcial to sort the vertices of the DAG on the basis of decreasing ﬁnishing times. Find the vertex of maximum ﬁnishing time. do the following: Problem 9. the vertices of the DAG can be so arranged on a horizontal line such that all directed edges go from left to right. it should still tell us somehow that it represents a directed acyclic graph? Let us now introduce a new action item.4. DFS spanning tree consisting of tree edges 2. Cross edges 4.3).1. We also know that if a directed graph is a DAG then the vertex with maximum ﬁnishing time will always be (one of) the source vertices of the DAG. Problem 9.478 Strongly Connected Directed Graphs and Tournaments If we take the transpose of a DAG then obviously the Reachable Relation matrix for the transpose will be diﬀerent from that of the original graph. Start a DFS from a vertex other than u and again locate a vertex with the maximum ﬁnishing time. It is interesting to note that the vertices of a cyclic graph can not be so arranged on a horizontal line such that all edges go in only one direction. We know that a directed graph is acyclic if and only if a DFS of the directed graph does not produce a back edge. back edges.3. .1. The source vertex will always be on the extreme left while the sink will be on the extreme right on the horizontal line (see Fig. forward edges.4. The output of the DFS are: 1. Perform a DFS from any vertex u in D. the directed edges should always go only from left to right. Problem 9.3.

. A concept map showing the concept of a directed acyclic graph. a couple of properties and two action items which are Reachable Relation and transpose of a DAG.Directed Acyclic Graphs (DAG’s) 479 Concept Map 9.3.

5.4. Problem 9.2.5. Problem 9.6. Problem 9.7. Discuss the outcome? 2 1 3 4 6 5 Figure 9.5. 2. Let us try to address the following problems: Problem Set 9.5.3. Find the source and the sink node in a DAG.1: A directed graph D for Problem Set. Problem 9. Find if a given DAG has a node u such that you can reach every other vertex of the DAG from u.4. Repeat the above three steps (1. Problem 9. Convert a completely connected un-directed graph into a DAG. .480 Strongly Connected Directed Graphs and Tournaments Problem 9.4. Find if a given directed graph is acyclic.5. Find if a given directed graph (not necessarily a DAG) has a node u such that you can reach every vertex from u.5. reverse the direction of the edge between vertex 2 and vertex 4.5. Design an eﬃcient algorithm to solve the following: Problem 9.5.3. & 3) on the same graph with one change.5. We are now in a position to address a number of algorithmic issues. Problem 9.1. Convert a connected graph into a DAG. Find if a DAG has a node u such that you can reach u from every other vertex of the DAG.

Algorithm 67 used DFS as a bridge to solve a couple of problems. How about if instead of a DAG we have an ordinary directed graph which may contain cycles? There . ﬁnd the source and the sink. Algorithm 68: Check if D is a DAG. input : A directed graph D output: Yes/No. if yes then the source and the sink vertices 1 2 3 Find a Reachable Relation R for the given graph D. input : A directed graph D output: Yes/No. But then the Reachable Relation provides much more information about a graph. this will be a source vertex. Algorithm 67 can also be slightly modiﬁed to locate a vertex u in a special DAG from where it is possible to reach every other vertex. If all diagonal entries in R are zero then D is a DAG. ﬁnd the source and the sink. This is because the Reachable Relation Matrix R is expensive as compared to a single DFS. The source vertex can be found directly by identifying the vertex with maximum ﬁnishing time. Source vertex will be the one with maximum ﬁnishing time. Using a Reachable Relation Matrix we can easily ﬁnd if there is a node u in D from where it is possible to reach every vertex of D. You might have noticed that Algorithm 68 is much more costly than Algorithm 67. First we can ﬁnd the vertex with maximum ﬁnishing time. Perhaps you should take the transpose of D and then again perform a DFS now on the transpose of D. if yes then the source and the sink vertices 1 2 3 481 Apply DFS on graph D. It is not possible to ﬁnd the sink node directly.3 for further hints. if all vertices of D are spanned by the BFS then the DAG possesses the desired characteristics (Does it mean that D is strongly connected?). You should try to solve these problems yourself before moving forward. Sink vertex: You ﬁnd out.Directed Acyclic Graphs (DAG’s) Algorithm 67: Check if D is a DAG. Look at Concept map 9. Source: Vertex with maximum reachability in R?. Now we can start a new BFS from this very vertex. Sink: Vertex with zero reachabiliy?. In fact it can answer this question even if the graph D is not acyclic. If no back edge then D is a DAG.

and if it does then the algorithm outputs the actual Hamiltonian Path. Please note that if the undirected graph G is not completely connected then it will be hard to ﬁnd a Hamiltonian Path in G (as is done in Algorithm 69.3.4. Perhaps in an ordinary graph. now the vertices of the DAG can be so arranged on a horizontal line such that the source vertex will always be on the extreme left while the sink will be on the extreme right on the horizontal line (see Fig. It is left as an exercise for the learner to design an algorithm in order to convert an ordinary connected graph into a DAG. The ﬁrst step should be to do a topological sort on the vertices of the given directed graph. Put directions on this line going from left to right only. All edges of the graph will go from left to right in this arrangement otherwise it will not be a directed acyclic graph.482 Strongly Connected Directed Graphs and Tournaments may still be a node u in D from where it is possible to reach every where. For a Hamiltonian path to exist in this graph there should be a directed edge .4). But then we have to remove the extra edges that we have inserted into the original un-directed graph? So what? It is interesting to note that ﬁnding a Hamiltonian Path in a DAG is not a hard problem as it is in other graphs. will the maximum ﬁnishing time be able to locate this u in D? It is important for you to verify or contradict this conjecture at this very stage before moving forward. 9. Algorithm 69 can be used to put appropriate directions on a completely connected un-directed graph in order to convert it into a DAG (see Fig. Arrange the Hamiltonian Path as a Horizontal line. This node u is not a conventional source vertex as it may have an in-degree. 9. We can easily design an eﬃcient algorithm to check if such a path exists. we should ﬁrst put directions arbitrarily and then remove cycles by reversing back edges? Or put edge directions such that no cycle is created in the ﬁrst place? Or why not convert the given un-directed graph into a completely connected un-directed graph and then use Algorithm 69. How about if we perform a DFS in this directed graph. Algorithm 69: Convert a completely connected graph into a DAG input : An undirected completely connected graph G output: A DAG D (with same number of nodes and edges) 1 2 3 4 Find a Hamiltonian Path in G.2). Put back the remaining edges of G with directions going from left to right only.

It implies that a Hamiltonian path does not exist in this directed acyclic graph. this observation conﬁrms that D is a directed acyclic graph. A path passing through all topological sorted vertices means a Hamiltonian path exists otherwise not.Directed Acyclic Graphs (DAG’s) 483 (from left to right) between every two consecutive vertices.2 shows a directed acyclic graph D. . 9. A directed edge between two consecutive vertices (8/9 & 1/6) is missing. We start a Depth First Search in this graph starting from a vertex designated as a start vertex in the top diagram. Algorithm 70: Find a Hamiltonian path in a DAG input : A directed acyclic graph D output: A Hamiltonian path in D provided it exists 1 2 Perform a topological sort on vertices of D.3. The resulting start / ﬁnishing times are indicated along with each vertex in this diagram.. thus it is not possible to ﬁnd a directed path passing through all the topologically sorted vertices. a Hamiltonian path in D will essentially be a path between topological sorted vertices in D (in the topological sorted order). As one can see all edges of this graph are going from left to right. The vertices of D are topologically sorted on the basis of decreasing ﬁnishing times as shown in the bottom diagram. Fig.

The start/ﬁnishing times of each vertex is also indicated here.484 Strongly Connected Directed Graphs and Tournaments 3/4 8/9 2/5 7/10 1/6 Start Node 11/12 11/12 7/10 8/9 1/6 2/5 3/4 Figure 9. Vertices of D are topologically sorted on the basis of decreasing ﬁnishing times as shown in the bottom diagram. A direct edge between two consecutive vertices is missing in the bottom diagram thus a Hamiltonian path is not possible in this graph.3. .2: A depth ﬁrst search is conducted on the directed acyclic graph D starting from a vertex labeled as start node as shown in the top diagram. The directed graph D is acyclic thus all edges move from left to right in the bottom diagram.

the resulting graph is no longer independently connected.4.4 Strongly Connected Components We know that in a strongly connected graph D. 9.4). An independently connected graph may not be strongly connected but a strongly connected directed graph is always independently connected (see Concept map 9. The two sub-graphs in Fig. in the top diagram there is no edge between component E and F . The problem that we intend to address in this section is to understand how we can eﬃciently ﬁnd the following: 1. v in D. both of these sub-graphs are strongly connected while graph D as a whole is not strongly connected. it can not enter into another strongly connected component. It is important to appreciate that in an independently connected directed graph there are no edges among strongly connected components (see top diagram of Fig. The concept of independently connected graphs is introduced as it is much simpler to solve the above problem in such graphs.1 and Concept map 9. & 2.1.Strongly Connected Components 485 9. 9. 9. In such a graph every vertex u in D may not be reachable to every vertex v in D but if u is reachable to v then v is reachable to u for every pair of vertices u. An independently connected graph D which is not strongly connected is shown in the top of Fig.1 are in fact two strongly connected components. In the bottom diagram of Fig.4. a vertex u is reachable to vertex v and the vertex v is reachable to vertex u for every pair of vertices u.4. it is in fact an eﬃcient way of determining vertices belonging to a strongly connected . we add an edge between component E and F . Nodes belonging to a strongly connected component. 9. Thus if we start a BFS from any vertex belonging to any strongly connected component in an independently connected graph then the search is conﬁned to that strongly connected component.4.1. It is now natural to deﬁne a new concept before moving forward: a strongly connected component in a directed graph D is a maximal set of vertices of a directed graph in which vertices u and v are reachable from each other for every pair of vertices u and v in that maximal set. v in D. The number of strongly connected components in a directed graph. It is quite evident from this ﬁgure that graph D consists of two sub-graphs E and F . Let us now consider a (related) class of directed graphs which we call independently connected directed graphs.4).

4. The .1) thereby converting it into an independently connected graph then the problem of determining nodes belonging to a strongly connected component is much simpliﬁed. For example if you start a BFS from vertex 1 belonging to component E then the search will traverse vertices belonging to component E as well as F (see Fig. it may also enter another strongly connected component. In the top diagram.4. there is no edge between the two components and graph D is independently connected. If some how we can remove edges connecting diﬀerent strongly connected components in a directed graph (like the edge (3. 9. In a directed graph which is neither strongly connected nor independently connected there are edges between diﬀerent strongly connected components.1: Sub-graph E and sub-graph F are both strongly connected components. 9. note the directed edge from component E to component F in the directed graph D shown in the bottom of Fig. 9. component (it is as simple as determining nodes belonging to a connected component in an un-directed graph).486 Strongly Connected Directed Graphs and Tournaments 4 7 1 3 5 E 2 D F 6 4 7 1 3 5 E D 2 6 F Figure 9. In the bottom diagram there is an edge from E to F and the graph D is neither strongly connected nor independently connected.1) Thus the problem of determining nodes belonging to a strongly connected component becomes harder if a directed graph is neither strongly connected nor independently connected.1 If you start a BFS in this graph then the search may not be conﬁned to only one strongly connected component.4.5) in D shown in the bottom of Fig.4.

. symmetric as well as transitive. it is an equivalence relationship on the vertices of the independently connected graph. it is not reachable to vertices belonging to other strongly connected components.1.4. Once we have the Reachable matrix of an independently connected graph. 9. We shall certainly encourage you to draw the Reachable matrix for the independently connected graph shown at the top of Fig.Strongly Connected Components question is how to locate and then remove these edges? 487 It is important at this learning stage to apply the Reachable transformation to a number of independently connected directed graphs and draw the corresponding Reachable Matrices. 9. 9. In simple words it means that in an independently connected graph a vertex is reachable only to vertices belonging to the same strongly connected component. If you carefully look at the resulting Reachable matrix you will notice that the relationship it depicts on this graph is reﬂexive.4. The corresponding equivalence classes (that the relationship generates) are in fact the strongly connected components E and F of the independently connected graph D.1 is shown by the bold 1’s in any of the table shown in Fig.4. The Reachable Relation Matrix for the independently connected graph of Fig. it becomes trivial to pinpoint vertices belonging to a strongly connected component.2.

9. . The Reachable Relation Matrix A of D and the Reachable Relation Matrix B of the transpose of D are also shown in this table. We show the same directed graph D as depicted in the bottom of Fig.2 is again equivalent to removing the edge (3.4. The problem of determining strongly connected components in a directed graph is thus reduced to recovering the bold 1’s (or throwing away the small 1’s) in the Reachable Relation Matrices of Fig.2).4. It is interesting to note that the graph D is diﬀerent from its transpose but the Reachable relation of the two graphs will be exactly the same as demonstrated by bold 1’s in the two tables of Table shown in Fig. 9. The Reachable relation is not symmetric.4. It is thus no longer trivial to determine vertices in a strongly connected component in such directed graphs? If somehow we can convert it back into a symmetric relation without disturbing the connectivity inside any strongly connected component and without changing the number of strongly connected components then the problem will become much simpler? This means that some how we should be able to remove the small 1’s in the Reachable Relation Matrix A of table in Fig. this is indicated by the small 1’s in the two tables given in the ﬁgure. 9.4. 9. we take the transpose of a directed graph which is not independently connected then things will be diﬀerent.5) in the bottom diagram of Fig. For example if you draw the Reachable matrix of the graph shown in the bottom of Fig.2. It is quite obvious in the tables that the reachability within a strongly connected component is not aﬀected by the transpose transformation (see the bold 1’s in the two tables in Fig.1.1 as well as its transpose on the top of Table in Fig. 9.4. The question is again how to do it? Let us again consider an independently connected directed D and assume that we take a transpose of D.2). although vertex 1 belongs to strongly connected component E (please see Reachable Relation Matrix A in the table shown in Fig.4. 9. You might have noticed that removing those small ones in the table shown in Fig. If. 9. you will realize the inherent complication.1 thereby converting it again into an independently connected directed graph.488 Strongly Connected Directed Graphs and Tournaments The picture is not so rosy for a directed graph which is not independently connected.4.2.2.4.2. 9. A careful look at the two tables will provide the required answer. you can reach all vertices belonging to component E as well as component F from vertex 1.4.4. 9. 9. hence it is not an equivalence relationship. The reachability across strongly connected components is certainly aﬀected by taking the transpose of a directed graph. however.

3).2. that is (3. 4.4. We shall describe hints for designing a more eﬃcient algorithm to solve a similar problem in .2 except for one similar edge and that is (5. It is very diﬀerent from the transpose of D in Fig. It uses two transformations: Reachable Relation as well as the Transpose as intermediate building blocks of this algorithm. Graph J is almost the same as graph D in Fig.3. 9.2 except for one common edge.3) is reversed and another edge (6. Graph K is almost the same as graph I except that the edge (2. 2. 3. Algorithm 71 is a straight forward algorithm to ﬁnd all strongly connected components in a directed graph as already illustrated in the Table shown in Fig. Please note that: 1.4. Algorithm 71: Find strongly connected components of graph D input : A directed graph D output: Strongly connected components of graph D 1 2 3 4 Find Reachable Relation Matrix A of D.5) in D is reversed.6) in I is reversed in K thus creating a new cycle in the directed graph.2 except the connectivity inside strongly connected component E in D is altered. 9.4.2 except that the edge (3. ﬁnd the Reachable Relation Matrix and compare this matrix with the ones given in Table in Fig. Find Transpose T (D) of D.5).4. 9. Graph H is the same as graph D in Fig. (please see Fig. Graph I is the same as the transpose of D in Fig.4. Again it is quite diﬀerent from graph D in Fig.4.2 (this comparison will certainly be a useful learning experience). It may not be very eﬃcient (still a polynomial time algorithm) but certainly a good start for a new learner in this ﬁeld. 9.4.4.4. 9. 9. Take AND of Matrix A & B.2 except that the edge (5. 9.2) is added.2). 9. 9. Find Reachable Relation Matrix B of T (D).Strongly Connected Components 489 A problem For each of the graphs shown in Fig.

4.2). We know there are no edges between strongly connected components in an independently connected graph. the component E was a source while the component F was a sink.6) while Graph K is reduced into one strongly connected component because of a cycle created by the edge (6. Call BFS on T starting from u. Find Transpose T of D. This immediately suggests that strongly connected components in a directed graph are always connected in the form of a directed acyclic graph (see Concept map 9.490 Strongly Connected Directed Graphs and Tournaments the coming paragraphs. Let us for the time being restrict ourselves to ﬁnd one strongly connected component of a directed graph. Graph I has two strongly connected components in spite of the extra edges (2. When you insert edges you will soon realize that in order to achieve the above mentioned objective you should be careful not to create a cycle otherwise all strongly connected components within that cycle will collapse into one strongly connected component and the above condition will be violated. While in the top right diagram of the same ﬁgure. You are supposed to insert extra edges between the k strongly connected components such that the new directed graph should still have as many as k strongly connected components.2). Output all vertices traversed by the BFS. This further implies that there will be at least one source and one sink strongly connected component. let us describe another algorithm (Algorithm 73) which will also output a strongly connected component of F .4. 9. 9. ﬁnd vertex u of maximum ﬁnishing time.2. A comparison of the two will certainly be an exciting learning experience. Please recall graph I & K in Fig. Algorithm 72: Find a strongly connected components of graph D input : A directed graph D output: One Strongly Connected Component of D 1 2 3 4 Call DFS on D. .. In the top left diagram of Fig. Before discussing this algorithm (Algorithm 72). Again consider an independently connected directed graph D consisting of K strongly connected components. This looks very similar but there are interesting diﬀerences between the two algorithms. component F was a source and E was a sink strongly connected component.3.

A map showing the concept of a strongly connected graph. Eulerian. Call BFS on D starting from u. a couple of properties and an action item which is the Reachable Relation.4. . It is interesting to note that the Reachable Relation graph of a Hamiltonian. Call DFS on T : ﬁnd vertex u of maximum ﬁnishing time. Algorithm 73: Find a strongly connected component of graph D input : A directed graph D output: One Strongly Connected component of D 1 2 3 4 Find Transpose T of D.Strongly Connected Components 491 Concept Map 9. and strongly connected directed graph is exactly the same. Output all vertices traversed by the BFS.

Reachability within a strongly connected component is shown by a bold 1’s. .4.2: The Reachable Relation Matrix A for D is shown on the left. A similar matrix B for the Transpose of D is shown on the right.492 Strongly Connected Directed Graphs and Tournaments E 1 4 Graph D 5 7 4 Transpose of D 3 5 7 F 6 3 2 1 F 6 2 E 1 1 2 3 4 5 6 7 1 1 1 1 2 1 1 1 1 3 1 1 1 1 4 1 1 1 1 5 1 1 1 6 1 1 1 1 7 1 1 1 1 1 1 2 3 4 5 6 7 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 4 1 1 1 1 1 5 6 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Reachable Relation Matrix A of graph D Reachable Relation B of Transpose of graph D Figure 9.

This vertex will belong to the source component of the transpose of D. The output of this algorithm will thus be the source or the sink strongly connected component of directed graph D (see Concept map 9.4.Strongly Connected Components Graph H 4 E 1 2 3 5 6 F 1 2 7 E 3 5 6 F 4 Graph I 493 7 4 E 1 2 3 Graph J 7 E 5 6 F 1 4 Graph K 7 3 2 5 6 F Figure 9.5)? Please recall the algorithm in which we have tried to solve the problem of determining if a given directed graph is strongly connected. If we start a traversal from this node in the graph F then the traversal will not only traverse vertices belonging to the source strongly connected component. it will also enter and traverse vertices belonging to other strongly connected components. Algorithm 73 ﬁrst takes the transpose of D and then locates the vertex u of maximum ﬁnishing time. The source strongly connected component in D will become a sink in the transpose of D.3: Directed graphs for the problem set As you may have noticed that Algorithm 72 locates a vertex u of maximum ﬁnishing time after doing a DFS on D. Vertex u will belong to the source strongly connected component of directed graph D. We therefore take the transpose of D and then start a traversal from vertex u. What does that mean in terms of our newly acquired knowledge of strongly connected components? A strongly connected graph is just one strongly connected component. the output will thus be all vertices belonging to the source component in D as shown in Concept map 9.5. But how to determine if a directed graph possesses this property? How about if the sink strongly connected component consists of all vertices of the directed graph? We can determine this in O(p + q) instead of O(p3 ) . this time a traversal will be contained in the sink component of the transpose of D.

A directed graph F consists of a DAG of its strongly connected components. Transpose of F also consists of a (diﬀerent) DAG of strongly connected components. The source strongly connected component belonging to F is the same as the sink strongly connected component of the transpose of F . .5.494 Strongly Connected Directed Graphs and Tournaments Concept Map 9.

6. Diﬀerent directions are added in the completely connected un-directed graph to convert it into a strongly connected graph shown in the bottom left.1. the graph still remains a strongly connected graph. Please note that all edges in the bottom left diagram are not directed. 9. 9. It is interesting to note that the directed graph (bottom right) is a directed acyclic graph as all edges are going from left to right (see Algorithm 69). It should read. Directions are added in this undirected graph in order to convert it into an acyclic directed graph shown in the bottom right.4 (top) shows a completely connected undirected graph.6.4 determine the corresponding strongly connected components and the underlying DAG connecting the strongly connected components. You may put any directions on these edges (indicated by thin lines). For the two bottom graphs in Fig. Problem Set 9.4: A completely connected undirected graph of ﬁve vertices is shown in the top diagram.4. if BFS traverses all vertices of the directed graph D then D is strongly connected. What we need to do is to slightly modify the last line of Algorithm 72 or 73.Strongly Connected Components 495 for Algorithm 63. Problem 9. Please solve the following: 5 1 2 3 4 1 5 5 1 2 3 4 1 5 1 2 5 3 4 1 5 1 Figure 9.4. . The bottom of this ﬁgure shows two directed graph derived from the top graph by putting a directions on edges of the un-directed complete graph (such a directed graph is known as a tournament). The bottom left diagram of this ﬁgure is one strongly connected directed graph or component. Fig.4.

Fig. 9. Is it possible to convert the top un-directed graph Fig. .5.496 Strongly Connected Directed Graphs and Tournaments Problem 9.4 into a directed graph such that the resulting directed graph (which will be another tournament graph) is neither strongly connected nor acyclic. Problem 9.5 show three non-isomorphic directed graphs (tournaments) derived by putting directions on edges of the completely connected un-directed graph of Fig. Convert the completely connected un-directed graph in Fig.6. Problem 9.4.4. Problem 9.7.4. Find its strongly connected components and determine the DAG connecting these components.7. Problem 9.4. The corresponding DAG of strongly connected components of each tournament graph is drawn in front of it. How many non-isomorphic DAG’s are possible corresponding to all possible tournaments of 5 vertices. Is it possible to draw a tournament of 5 nodes which consists of 4 strongly connected components? Discuss brieﬂy.4. and the respective DAG of strongly connected components of each tournament. 9.6.1.3. Problem Set 9. 9. The DAG of strongly connected components of the bottom graph is not isomorphic to any of the two. Draw all these DAGs. 9. 9. Note that the top two directed graphs are not isomorphic to each other yet the DAG’s of strongly connected components are isomorphic to each other.7. please see Fig.5.4. Find and draw all non isomorphic directed graphs derived from the completely connected un-directed graph shown in the ﬁgure. it shows two tournaments (top and middle) with the same DAG and one with a diﬀerent DAG (bottom).2. Group all tournaments which correspond to the same DAG. Problem 9. Draw the corresponding DAG of strongly connected components for each of the tournament graph that you have drawn. Carefully examine each of non-isomorphic tournaments that you have drawn in the last problem set. What are their respective sizes in terms of number of nodes? Please remember that each node in a DAG corresponds to a strongly connected component.6.4.4 into a directed graph consisting of two strongly connected components such that one strongly connected component should consist of two nodes and the other will consist of the remaining three nodes? Discuss brieﬂy how this is possible or why it is not possible.6.2.

4.4 5 1 2 3 4 5 1. Note that all edges are not directed as shown by thin lines in the bottom graph.4.5: We show here three non-isomorphic directed graphs derived by putting directions on each edge of a completely connected graph of Fig. the strongly connected components and the corresponding DAG will still remain the same.3.4 5 5 Figure 9. 9. The corresponding DAG of strongly connected components of each tournament graph is drawn in front of it. . 2 3 4 5 1 2 3 4 5 1.2 3. you may put any directions on these edges.4.Strongly Connected Components 497 1 2 3 4 5 1 2.

5 9. While playing with tournaments in previous problems. The goal is to ﬁnd a Hamiltonian path in the tournament which will be a simple path of length p − 1. We know . Let us start with some very simple properties. 9.4.5. you might have noticed that a tournament can be strongly connected while another tournament may be a directed acyclic graph again shown in Fig.7.1 are in fact all tournaments.5.5. There are several non-isomorphic tournaments possible which are not acyclic (Fig.5.5. Derive an exact expression for the number of non isomorphic DAGs of strongly connected components of tournaments of size p. Why? Only because it is a tournament? Recall how a tournament is constructed from a completely connected un-directed graph and also recall the deﬁnition of a unilaterally connected directed graph? 9.7. We can take any node u in T which is not part of P .1). 9.498 Strongly Connected Directed Graphs and Tournaments Problem 9. 9. We shall study these and many other interesting properties of tournaments in this section. 9. Is the DAG of strongly connected components of a tournament also a tournament? Why? Problem 9. Similarly a tournament is transitive if and only if it is acyclic (why?). we can design an eﬃcient algorithm to ﬁnd that path.5. 9.5.1 Tournaments A Panoramic Picture and a Concept Map A directed graph obtained by putting directions on edges in a completely connected un-directed graph is known as a tournament (see Fig.3.7. Assume that we have a tournament of p nodes and we have already found a path P of length k in this tournament.6). The directed graphs that you have studied in Fig. a tournament is always unilaterally connected.2) but there is always a unique acyclic tournament for a ﬁxed number of vertices (why?).2 A Hamiltonian Path in a Tournament Every tournament has a Hamiltonian path. Is it possible to draw a DAG of 4 strongly connected components corresponding to a tournament of size 4? Problem 9. Within these two extremes there is a lot of variety of possible tournaments consisting of various strongly connected components (see Concept map 9.1 .

it possesses some very special properties as shown in this concept map.Tournaments 499 Concept Map 9. Such a directed graph is known as a Tournament. An un-directed and completely connected graph can be converted into a directed graph by putting directions on each edge in an arbitrary fashion.6. .

.500 Strongly Connected Directed Graphs and Tournaments We start with a completely connected un-directed graph Which is usually drawn in this fashion 1 5 2 Put directions on each edge 1 2 3 4 1 5 4 3 1 5 2 1 2 3 4 1 5 4 3 A directed acyclic tournament We get a Tournament: This is a directed acyclic graph 1 2 3 4 1 5 1 2 3 4 1 5 A strongly connected tournament A strongly connected tournament Figure 9.1: Diﬀerent Tournament graphs constructed from a completely connected un-directed graph.5.

Tournaments 501 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 11 2 3 4 5 1 2 3 4 5 1 2 3 4 5 5 1 2 3 4 5 1 2 3 4 5 Figure 9.2: Diﬀerent Tournaments and the associared Strongly Connected Components. .5.

502 Strongly Connected Directed Graphs and Tournaments 1 2 3 4 1 k u 1 2 3 4 1 k 1 1 2 1 3 4 1 k u u Figure 9. Vertex u will be connected to every vertex in P. . you are at liberty to put any directions in the top diagram you will always end up with an extended path P of length k+1. Any exercise to put directions so that the path length does not increase will fail as shown in the bottom diagrams. Consider any vertex u in T which is not included in P.5. The extended Hamiltonian path is shown in bold in the bottom diagrams.3: A directed path P of length k is shown in a tournament.

5.3 A Hamiltonian Cycle in a Strong Tournament We know that a tournament can be acyclic. 9. 9.3 (bottom). and a cycle C of length k in T output: A cycle of length k + 1 in T Before providing an answer to the above problem. thus it may not be strongly connected.Tournaments 503 that u is connected to all nodes in T (why?) as shown in Fig. we ﬁrst prove a simpler hypothesis: if there is a cycle C of length k in a tournament then it is possible to ﬁnd a cycle of length k +1 in that tournament. Using Algorithm 74 it is possible to ﬁnd a Hamiltonian path in a tournament. let us look at a related problem: Assume that we are given a Hamiltonian cycle in a tournament T of size k. Also assume that now we add another vertex u to T such that T +u is strongly connected and is also a tournament. Algorithm 74: Extend path length in P from k to k + 1 input : A Tournament T . We now prove that if a tournament is strongly connected then it will always be Hamiltonian. How about if we use a similar approach used earlier for extending the path length. you are bound to get an increase in the path length of P from k to k + 1. Algorithm 75: Extend cycle length in T from k to k + 1 input : A strong Tournament T. Before proving that general result.3 (top). 9.5. It will be an interesting (but futile) exercise to put directions such that the path length does not increase by one as is demonstrated in Fig. See if you can ﬁnd the Basic Idea and Time Complexity of Algorithm 75 as shown below. and a simple path P of length k in T output: A simple path P of length k + 1 in T 1 2 Consider any node u in T not already in the path P . you may put any directions on these edges. it will not contain a Hamiltonian cycle. Try your luck and check if it is possible. The algorithm also serves as a constructive proof that there is always a Hamiltonian path in any tournament. Include u in P and output the new path P . We will now show that T + u .5.

how about if T is a directed acyclic tournament but T +u is a strongly connected. the vertex u will have a ﬁnite in-degree and a ﬁnite out-degree as T + u is strongly connected (see Fig.5 before making up your mind. 9. that is certainly not a hard problem? Then we should locate a vertex u such that the cycle length increases from 3 to 4. It means that if T is Hamiltonian then T + u will also be Hamiltonian provided T + u is a strong tournament.5. In fact this special case is simple to solve as there is only one way to convert a directed acyclic tournament graph (we already . 9. Then how can we show that T + u will be Hamiltonian? Let us look at the extreme.504 Strongly Connected Directed Graphs and Tournaments is Hamiltonian.4.5.4). A new vertex u is added to T such that T + u is a tournament and is also strongly connected. 9.5. it is possible that a tournament T is not strongly connected but T + u is a strongly connected tournament. As T + u is a tournament thus u will be connected to every vertex of T. Is it feasible or not? Carefully look at Fig.4: A Hamiltonian cycle in a tournament T of size k is shown. It is thus always possible to ﬁnd a Hamiltonian cycle in T + u as shown in bold in the left diagram. The vertex u will have at least one incoming edge and one outgoing edge (right). This type of approach will be very similar to Algorithm 74 where we extend the path length incrementally and ﬁnally output the Hamiltonian path.5. How the above hypothesis will help us in ﬁnding a Hamiltonian cycle in a strongly connected tournament or in proving that a strongly connected tournament is Hamiltonian? How about ﬁnding a cycle of length 3 in a strong tournament. Thus it will always be possible to ﬁnd a Hamiltonian cycle in T + u as shown in Fig. 3 4 3 4 2 u 5 2 u 5 1 k 1 k Figure 9. As you can see there is a serious complication here. and so on until we ﬁnd a Hamiltonian cycle.

If it is right then the tournament will have a cycle of every possible length until we have a Hamiltonian cycle. We have already considered the possibility when T is strongly connected. it will be interesting for you to explore? 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 Figure 9. . A cycle of length 4 is shown in the bottom right. A cycle of length 5 is shown in bottom left diagram. thus a strongly connected tournament is Hamiltonian. this will certainly result in a Hamiltonian graph (why?). Let us come back to the problem of designing Algorithm 75 or proving that if a cycle C of length k exists in a strong tournament then a cycle of length k + 1 also exists in the strong tournament. but there is a possibility when T is neither strongly connected nor acyclic. both these vertices are outside the cycle C and are double circled. Before proving this hypothesis let us look at its repercussions. How to cater to that class of graph. Please note that vertex 4 has all incoming edges from vertices belonging to the cycle C while vertex 5 has all out going edges to vertices belonging to the cycle C. Consider vertices 4 and 5 in this ﬁgure. we have also considered the possibility when T is a directed acyclic graph. in fact it is more than that.5.5: A directed cycle C of length 3 is shown (enclosed in a dotted circle) in a strongly connected tournament of size 5 (top).Tournaments 505 know that it will have a Hamiltonian path inside it) into a strongly connected graph is to insert the extra node u is to connect it with the source node of the DAG and then connect the sink with node u.

5.5). it is possible to convert this cycle into a cycle of length k + 1 by a simple manipulation (see the bottom right of Fig. Assume that we have found a cycle C of length k in a strongly connected tournament. 9. The Concept of a Rip Vertex Let us deﬁne a new term before designing an alternate strategy to ﬁnd a Hamiltonian cycle in a strong tournament. Let us now come to the proof of the above hypothesis. You can certainly ﬁnd a cycle of length K +1 in this situation by extending the cycle length of C from k to k + 1.5. If you can not ﬁnd a vertex u with the above property then you will certainly ﬁnd a vertex u and a vertex v such that (a) all edges to u from every vertex of C are incoming towards u. There are essentially two possibilities. (b) all edges from v to every vertex of the cycle C are out going. 9. 9. 9. This possibility is quite similar to the one illustrated in Fig. This scenario is depicted in Fig.5. This also provides an eﬃcient algorithm to ﬁnd a cycle from length 3 to all the way to a Hamiltonian cycle of length p − 1. Now we intend to ﬁnd a cycle of length k + 1 in the same tournament. 1. Corresponding to a cut vertex in a connected un-directed graph there is a counter part concept in a (strongly) connected directed graph: a vertex v is a rip vertex (in a strongly connected directed graph D) provided D − v is not . This completes the constructive proof that you can extend the cycle length in a strong tournament of p nodes from 3 to p−1.6 ).5.5and also Fig.5.5. You can ﬁnd a vertex u such that it has at least one incoming and one out going edge connecting u to vertices already in the given cycle C. Note that if (a) or (b) is not true then we shall end up with the ﬁrst possibility. If (c) is not true then the tournament T will not be strongly connected.4. You are already familiar with the concept of a cut vertex in an un-directed graph (a vertex v in an undirected connected graph G is a cut vertex provided G − v is not connected). and (c) there is an edge from u to v. 2. 9.506 Strongly Connected Directed Graphs and Tournaments a cycle of length k is possible in a strongly connected tournament where k is equal to or more than 3. Now it is possible to ﬁnd a cycle of length k + 2 (see the bottom left of Fig.

.5.Tournaments 507 1 2 3 4 5 We find a 3-cycle in the graph The 3-cycle is extended into a 4-cycle 1 2 3 4 5 1 2 3 4 5 The 4-cycle is extended into a 5-cycle which is a HAM Cycle 1 2 3 4 5 We start with a different 3-cycle in the same graph This 3-cycle can not be extended into a 4-cycle. It can be extended into a 5-cycle directly 1 2 3 4 5 Figure 9.6: Extending a 3-cycle into a 5-cycle in a strongly connected tournament.

In the earlier algorithm we grow a cycle within the original tournament from a small size to p. Problem 9. until you ﬁnd the Hamiltonian cycle in the original tournament T .4. Indicate which vertices are rip vertices and which vertices are not rip vertices in Fig.508 Strongly Connected Directed Graphs and Tournaments (strongly) connected.5. Problem 9. Draw a strong tournament in which no vertex is a rip vertex.8. we then insert the removed vertices one by one and Hamiltonian cycle also increases incrementally with the size of the graph.8.5.8. We can do this step of removing a non rip vertex recursively until the original tournament is reduced to such a small sized tournament where it will be trivial to ﬁnd a Hamiltonian cycle. Now we can start inserting back the removed vertices one by one in the last removed ﬁrst inserted order.8. Problem 9.1. How can you eﬃciently ﬁnd a non rip vertex in a strong tournament? .3.2. The resulting graph T − u will be a tournament (why?) and a strong tournament (because u was not a rip vertex) of size p − 1.8. 9.5. It will be interesting to derive and compare the time complexities of the two algorithms. Problem Set 9. 9. We ﬁrst locate and then remove a non rip vertex u. It will be a learning experience to compare the working of the two algorithms that we have described to ﬁnd a Hamiltonian cycle in a strong tournament. Problem 9. It is important for you to answer the following in order to meaningfully understand the last algorithm that we have described to ﬁnd a Hamiltonian cycle in a strong tournament.8. the Hamiltonian cycle will grow incrementally (with the graph) as shown in Fig. Prove that there always exists at least one non rip vertex in a strong tournament. Problem 9.8. In the later algorithm we remove non rip vertices from a tournament one by one until it is possible to ﬁnd a Hamiltonian cycle in the reduced size tournament. Now assume that we are given a strongly connected tournament T of size p. Draw a strong tournament in which there are at least 3 rip vertices in a tournament of size 5 or 6 .5. On the basis of these ideas it is possible to construct an alternate algorithm to ﬁnd a Hamiltonian cycle in a strong tournament.

In the other diagrams we check if a given vertex is a rip vertex any any of the top tournaments.We show four diﬀerent tournaments in the top diagram.7: Finding a rip vertex in a Tournament.5. .Tournaments 509 5 5 5 5 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 5 1 2 3 4 1 2 3 4 1 2 3 4 5 1 2 3 4 1 is a rip vertex 1 is a rip vertex Not a rip vertex Not a rip vertex 5 1 2 3 4 1 2 3 4 1 2 5 3 4 1 2 3 4 Not a rip vertex 2 is a rip vertex Not a rip vertex 2 is a rip vertex 5 1 2 3 4 1 2 5 3 4 1 2 3 4 1 2 3 4 Not a rip vertex Not a rip vertex 3 is a rip vertex 3 is a rip vertex 5 1 2 3 4 1 2 3 4 1 2 3 4 5 1 2 3 4 4 is a rip vertex Not a rip vertex 4 is a rip vertex Not a rip vertex Figure 9.

510 Strongly Connected Directed Graphs and Tournaments 1 2 3 4 5 2 3 4 5 Identify 1 as a non-rip vertex Remove the non-rip vertex 2 3 4 5 2 4 5 Identify 3 as a non-rip vertex Remove the non-rip vertex 2 4 5 2 3 4 5 Find a 3 cycle in the last graph Insert back the last vertex removed 2 3 4 5 1 2 3 4 5 Find a 4 cycle in the last graph Insert back the last vertex removed Find a 5 cycle in the graph which is the HAM Cycle 1 2 3 4 5 Figure 9.5. .8: Extending a 3-cycle into a 5-cycle in a strongly connected tournament.

6. It will be useful at this stage to draw a couple of such . j] = 1 or A[j.7. 9. Problem 9.6. Let us ﬁrst address the problem of how a Reachable Relation Matrix A of a unilaterally connected graph would look like. j] = 1 for every pair of vertices i.8. If instead of removing a non rip vertex in a strong tournament. Can you visualize a tournament graph where there is no rip vertex? Please see Fig. A variety of non-isomorphic directed acyclic graphs are possible which will produce such a Reachable Relation matrix.9 9. In this section we shall discuss various properties of unilaterally connected directed graphs. j] and A[j.8. Each of the matrices.9. 9. That means a strongly connected graph is always a unilaterally connected graph but not vise versa. Thus a directed graph D will be unilaterally connected if A[i. i] are equal to 1 for every pair of vertices i.1 corresponds to a unilaterally connected graph which is also directed acyclic (why?) assuming that all other entries in the matrix are equal to zero. In a strongly connected directed graph there is a path from u to v and a path from v to u. i] = 1 for every pair of vertices i. there is a path from u to v or a path from v to u.Unilaterally Connected Directed Graphs: 511 Problem 9. This means that the Reachable Relation Matrix A for a unilaterally connected directed graph will have all 1’s either on upper side of the diagonal (or on the lower side of the diagonal) as shown in Table. We have also seen that a tournament graph is also unilaterally connected. we remove a rip vertex then what will be the complication in reconstructing the Hamiltonian cycle in T ? Problem 9. What will be the overall time complexity of ﬁnding a Hamiltonian cycle in a strong tournament using the above algorithm. in fact it will be strongly connected.5.6. It is clear from the deﬁnition of such directed graphs that either A[i.1. j in D if j > i. If instead of one both A[i. j in D then D will be more than unilaterally connected.8.6 Unilaterally Connected Directed Graphs: A directed graph D is unilaterally connected provided for every pair of vertices u and v. j in D.8.8. shown in Table 9. Why we insist that a non rip vertex should be removed instead of a rip vertex? Problem 9.

9: The eﬀect of deleting a vertex in a Special Tournament .512 Strongly Connected Directed Graphs and Tournaments 1 2 3 4 1 5 2 3 4 1 5 1 1 3 4 1 5 1 2 4 1 5 1 1 2 3 5 1 2 3 4 1 A tournament where the in-degree as well as out-degree of every vertex is equal Figure 9.5.

7. . A map showing the concept of a unilaterally connected directed graph. a couple of properties and an action item which is the Reachable Relation. An un-directed connected graph which can be converted into a unilaterally connected directed graph is known as a unilaterally orient-able graph.Unilaterally Connected Directed Graphs: 513 Concept Map 9. A tree graph is unilaterally orient-able provided it is a path graph.

The right diagram shows such a graph with maximum number of edges.6. Both theses graphs are directed acyclic.6.514 Strongly Connected Directed Graphs and Tournaments Figure 9.2: A unilaterally connected directed graph D having minimum number of edges with all 1’s in the upper side of the diagonal and 0’s else where as shown in the left diagram.1: The Reachable Relation Matrix A for a unilaterally connected directed graph should have all 1’s either on the upper side of the diagonal (left) or on the lower side as shown in the right table. . 5 1 1 5 3 1 4 5 2 3 4 1 5 2 Figure 9.

In fact we shall prove that a directed graph is unilaterally connected if and only if it contains an open spanning walk. 9. thus for every consecutive vertex pair {u. We are dealing with a directed acyclic graph D. What we have not observed until now is that whether a unilaterally connected directed graph contains a Hamiltonian path or not it will certainly contain an open spanning walk. one having minimum number of edges (left) and the other having maximum number of edges as shown on the right of this diagram.6. 9. as well as cyclic containing a Hamiltonian path (as before) as shown in the middle diagram of Fig.3). There will not be any edge going from right to left because otherwise graph D will be cyclic. What is quite unexpected is that the Hamiltonian path may disappear because of the extra 1’s that we have added in the Reachable Relation matrix as shown in the bottom diagram of Fig.6. 9. We are dealing with a unilaterally connected directed graph D. Under such conditions one would expect that the resulting directed graph will be unilateral. Assume that in addition to all 1’s on the upper side of the diagonal there are some additional 1’s as shown (in bold) in the top diagram of Fig. 9. 9. this would imply a Hamiltonian path in D (it will .6. such a unilaterally connected graphs.3.6.Unilaterally Connected Directed Graphs: 515 graphs with the above property and the assumption that all other entries in the matrix are zero. This means there will be a direct edge between every two consecutive vertices (again from left to right).2.2.6. we show in Fig.2). If there are cycles in the unilaterally connected graph then there may or may not be a Hamiltonian path inside the graph (see Fig.6. But before that let us try to imagine what will happen if there are more 1’s then are absolutely essential for a graph to be unilaterally connected. Let us ﬁrst ﬁnd a constructive proof that a unilaterally connected directed acyclic graph will always contain a Hamiltonian path inside it.6. 9. v} in D either u is reachable to v or v is reachable to u.3. thus if we do a topological sort on vertices of D then the ordering of the vertices of the graph D along a horizontal line is such that all directed edges will be going from left to right as shown in Fig.3. We shall soon prove that a unilaterally connected directed acyclic graph D will always contain a Hamiltonian path inside D. assume that u is on the left of v in linear ordering then there must be a direct edge from u to v otherwise the condition stated above will be violated or there will be an edge going from right to left. 9. We have observed that a unilaterally connected graph contains a Hamiltonian path if it is acyclic (see Fig. Let us summarize our observations before making a number of formal proofs.

516 Strongly Connected Directed Graphs and Tournaments 1 1 2 3 4 5 2 1 3 1 4 1 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 5 1 4 5 1 2 3 1 4 5 Figure 9.3: A Reachable Relation matrix A for a unilaterally connected directed graph with some additional 1’s in the matrix (top).6. what is quite unexpected is that the Hamiltonian path may disappear from the resulting directed graph because of the extra 1’s as shown in the bottom diagram. . The extra 1’s (shown in bold) will make the unilaterally connected directed graph cyclic but there is still a Hamiltonian path inside the graph as shown in the middle diagram.

thus there will be (not only a spanning walk) but a spanning path inside D. Let us ﬁrst handle the hypothesis that if D is unilaterally connected then there will be an open spanning walk inside D. Thus there will be a Hamiltonian path passing through all strongly connected components of D as shown in Fig. We can again make a topological sort on strongly connected components of D and argue that there will be an edge going from left to right between every two consecutive strongly connected components of D. 9.6.4. If. D contains cycles then we can always ﬁnd strongly connected components of D and we know that the graph interconnecting its strongly connected components will be a directed acyclic graph. 9. We also know that there is a closed walk spanning all vertices inside each strongly connected component. 517 1 2 3 4 5 Figure 9.4: A unilaterally connected directed graph D having 5 strongly connected components. Note that inside each strongly connected component there is a closed walk.Unilaterally Connected Directed Graphs: essentially be a path between topological sorted vertices in D). Also note that the directed acyclic graph connecting all strongly connecting components should be a line graph otherwise D will not be a unilaterally oriented directed graph. Let us now consider the possibility when a unilaterally connected directed graph is not directed acyclic (see Fig. however. now we claim that a directed graph D is unilaterally connected if and only if it contains an open spanning walk.3) and so it may not have a Hamiltonian path.6. thus there will be an open spanning . We have already observed that if D is a unilaterally connected directed acyclic graph then there will be a Hamiltonian path inside D.6.

Strongly Connected Directed Graphs and Tournaments 9. Consider each connected component as a single (super) vertex. If you recall this is a suﬃcient condition for a graph to be strongly orient-able.6. We also know that a directed acyclic unilaterally connected graph D always contain a Hamiltonian path.6. If we put back the bridge edges then these (super) vertices will be connected in the form of a tree (why?). Thus when we put directions on edges in a tree graph in order to make it unilaterally connected then the resulting directed graph should also have a Hamiltonian path inside it. This would require that there should be an un-directed Hamiltonian path inside the tree graph G in the ﬁrst place otherwise it would have been impossible to convert G into D with a directed Hamiltonian path inside it. A tree of ordinary vertices can be unilaterally . If G is strongly orient-able then it will also be unilaterally orient-able. Now let us ﬁnd necessary and suﬃcient conditions for a general connected graph G (G is no longer restricted to be a tree and may contain cycles) to be unilaterally orient-able.5. Some edges are non bridge edges while some are bridges.518 walk inside D. We have already considered the ﬁrst possibility when G is a tree and every edge of G is a bridge edge. Thus a tree graph is unilaterally orient-able if and only if it is a line graph (or a path graph). 3. The only tree graph which contains a Hamiltonian path is in fact a line graph. If the graph G contains K bridge edges and if we remove all these K edges then G will be decomposed into k + 1 connected components. Every edge of G is a non-bridge edge. 2. Let us consider the second possibility when every edge of G is a non bridge edge. Every edge of G is a bridge edge.1 Unilaterally orient-able Un-directed Graphs We know that if we put directions on edges in an un-directed acyclic connected graph G (that means a tree) then no matter what is our direction scheme the resulting graph D would be a directed acyclic graph. There are essentially three possibilities: 1. Now we shall consider the third possibility when some edges of G are bridge edges while some other edges are non bridges as shown in Fig. 9.

6. The connected components are always connected in the form of a tree as shown in the bottom diagram. . If we remove all bridge edges then the un-directed graph is disconnected into 5 connected components shown in shaded circles.5: An un-directed connected graph G with 4 bridge edges shown in bold in the top diagram.Unilaterally Connected Directed Graphs: 519 3 1 2 4 5 3 1 2 4 5 Figure 9.

no edge inside the component will be a bridge edge (why?). So once again concentrate on a single connected component. This completes the proof that if a graph G is unilaterally orient-able then it will contain an open spanning walk. Thus each connected component is strongly orient-able (and will subsequently become a strongly connected component in the directed graph). there will be a closed spanning walk inside each component. A tree of super vertices can be unilaterally orient-able provided: (1) The tree is a line graph and (2) We can ﬁnd a closed spanning walk inside each connected component (why?).520 Strongly Connected Directed Graphs and Tournaments orient-able if and only if the tree is a line graph. You may prove the converse as an exercise? .

htm#top. Math. . Rawlins. [11] G. In 2003 International Conference on Engineering Education.com/dphils/dphil1. The teaching of problem solving.tcdc. 1995.edu/∼mhale/teach/index. 1975. 2003. 2003. 1980. Monthly. [9] William R. A New Aspect of Mathematical Method. [2] Sara Baase and Allen Van Gelder. The magic of dynamic programming. national computer conference. Narosa Publishing House.stetson. Iqbal and Atif Alvi. Addison-Wesley. Math. Miller. Princeton University Press. 102:317–321. Compared to What? Computer Science Press. [8] M. Iqbal. How to teach a class by the modiﬁed moore method. [6] P. Graph Theory Applications. 1988. [10] G. http://www. [5] Margie Hale. Halmos. Foulds. Polya.htm. Teaching computer science. R. R. Technical report. A. [7] M. Lecture. Monthly. Lahore University of Management Sciences. [4] L. New York.Bibliography [1] Websters dictionary. 1992. Department of Computer Science. 82:466–470. A. Computer Algorithms: Introduction to Design and Analysis. Amer. http://www. Amer. [3] Donald R. Chalice. How to Solve it. 1992. [12] David Rine. 2000.

C. 2003. Creative teaching: Heritage of r. Prentice Hall International. . [16] Steven S. Discrete Mathematics and its Applications. 1972. Springer-Verlag. 149.522 Bibliography [13] David Rine. george mason university. QA 29 M6T7. [15] Kenneth A. 2001. Lectures in patterns . [17] R. 1992. MIT Press. B. University of Houston. Taylor. Cormen. WCB/McGraw-Hill. l. 2002. Rivest T. Rosen.directed design. [14] Kenneth H. The Algorithm Design Manual. Leiserson and Cliﬀord Stein. Skiena. 1997. [18] D. Ross and Charles R. Cambridge MA. moore. 1972. Discrete Mathematics. New York. Introduction to Algorithms. Wright.

- Read and print without ads
- Download to keep your version
- Edit, email or read offline

Graph Theory

New Frontiers Graph Theory

Graph Theory

0521736536 Graph Algorithms

Geometry and Discrete Mathematics

Introduction Graph Theory

Handbook of Graph Theory 2ed Gross

Graph Theory With Applications

Algorithmics Theory and Practice

Schaum's

Number TheoryС

Modern Algebra Durbin

Handbook of Graph Theory

Algebraic.Graph.Theory.Morphisms,.Monoids.and.Matrices,..Knauer,.De.Gruyter,.2011.pdf

Clever Algorithms

Visibility Algorithms in the Plane - 0521875749

Algorithm Design and Applications.pdf

Electroweak Theory

number theory

Lowell W. Beineke & Robin J. Wilson & Peter J. Cameron - Topics in Algebraic Graph Theory

graphtheory

Pearls of Discrete Mathematics - M. Erickson (CRC, 2010) WW

Introduction to the Design & Analysis of Algorithms 2ND Edition by Anany Levitin

Ebooksclub.org a rial Approach to Matrix Theory and Its Applications Discrete Mathematics and Its Applications

Alan Baker - A Comprehensive Course in Number Theory - Cambridge University Press, 2012 - 269p

Graph Theory

Matrix Methods - Applied Linear Algebra 3rd Ed - Bronson,Costa.pdf

(U.john Hopkins) Matrix Computations (3rd Ed.)

Elementary_Probability.pdf

Truth, Reasoning, Certainty and Proof

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

CANCEL

OK

You've been reading!

NO, THANKS

OK

scribd

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->