Sei sulla pagina 1di 554

1

figuresection

2

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 Why a new book? .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2

1.2 What do we emphasize?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3

1.3 How the book is organized?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6

1.4 How is the book designed?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

8

1.5 Some salient features of the book

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

8

1.6 What tools do we use?

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

10

1.7 A Possible Sequence

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

14

2 Basic Definitions in Graph Theory and Algorithms

 

19

3 Problems, Models & Graphs: Why Study Graph Theory

 

31

3.1 Introduction

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

32

3.2 Reducing One Problem into Another

.

.

.

.

.

.

.

.

.

.

.

.

.

.

32

3.3 The Satisfiability Problem in Logic Circuits

.

.

.

.

.

.

.

.

.

.

34

3.3.1 Reducing a 3-SAT Problem into an Independent Set

Problem

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

35

3.3.2 Reducing the 3-CNF Satisfiability Problem into the 3-

DNF Satisfiability Problem

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

39

3.3.3 Reducing the 3-CNF Satisfiability Problem into an-

other graph Problem

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

41

vi

Contents

3.3.4 Reducing the 2-CNF Satisfiability Problem into a Graph

 

Problem

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

41

3.4 An Activity Scheduling Problem .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

47

3.5 A Dual Machine Serial Processing Environment

.

.

.

.

.

.

.

.

48

3.6 Sequencing by Hybridization in Computational Biology

 

57

3.7 Discussion & Problems

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

62

4

Basics of Graph Theory

 

77

4.1 Introduction

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

78

4.2 A Mutual Friendship Graph

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

78

4.3 Representation of a Graph

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

79

4.4 Complement of a Graph

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

83

4.5 Equal Graphs & Isomorphic Graphs .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

83

4.6 The Degree Sequence

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

85

4.7 Walks, Trails, & Paths

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 106

4.8 Multi-graphs and Pseudo-graphs .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 107

4.9 Broad Categories of Graphs & some Special Graphs

.

.

.

.

.

. 107

4.9.1 Tree Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 107

4.9.2 Bipartite Graphs

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 107

4.9.3 Special Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 111

4.10 Integration of Concepts, Properties, and Action Items

 

120

4.11 Self Complementing Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 125

4.11.1 Regular Self Complementing graphs .

.

.

.

.

.

.

.

.

.

. 125

4.11.2 Non Regular Self Complementing graphs

.

.

.

.

.

.

.

. 130

4.11.3 Constructing Self Complementary Graphs

.

.

.

.

.

.

. 134

4.11.4 Transforming a SC graph with 4k + 1 vertices into an-

 

other SC graph with 4k vertices

.

.

.

.

.

.

.

.

.

.

.

.

. 138

Contents

vii

4.11.5 Transforming a SC graph with 4k vertices into another

 

SC graph with 4k + 1 vertices

 

.

.

.

.

.

.

.

.

.

.

.

.

.

. 143

4.11.6 The Self Complementary problem and Graph Isomor-

 

phism

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 147

4.11.7 A SC graph has diameter 2 or 3 - not less than 2 and

 

not more than 3?

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 148

4.11.8 Bipartite self complementary graphs

.

.

.

.

.

.

.

.

.

. 156

4.11.9 Decomposition of a SC graph G

.

.

.

.

.

.

.

.

.

.

.

.

. 158

4.11.10 Permutation, Isomorphism, automorphism & Self Com-

 

plementing Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 163

5

Basics of Graph Algorithms

 

177

5.1 Design of Algorithms

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 179

5.1.1 What is Design?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 180

5.1.2 The Moore Method .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 180

5.2 The Bucket Algorithm

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 180

5.2.1 Understanding the Bucket Algorithm

.

.

.

.

.

.

.

.

.

. 183

5.2.2 How does it Work?

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 183

5.2.3 Playing with the Algorithm

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 183

5.2.4 Solving Other Problems

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 185

5.2.5 The Right Provocation

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 185

5.3 Finding if a Graph is Connected .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 186

5.3.1 The Number of Connected Components

.

.

.

.

.

.

.

. 186

5.3.2 Finding a Bridge in a Graph .

.

.

.

.

.

.

.

.

.

.

.

.

.

. 188

5.4 Finding if a Graph is a Tree

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 188

5.4.1 Every Edge in a Tree is a Bridge

.

.

.

.

.

.

.

.

.

.

.

. 188

5.4.2 The Number of Edges in a Graph

.

.

.

.

.

.

.

.

.

.

.

. 190

5.4.3 The Spanning Tree of a Tree

 

.

.

.

.

.

.

.

.

.

.

.

.

. 190

viii

Contents

5.4.4

A Comparison

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 190

5.5 Finding a Spanning Tree of a Graph

.

.

.

.

.

.

.

.

.

.

.

.

.

. 190

5.5.1 Cutting Edges

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 191

5.5.2 Growing Edges

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 191

5.5.3 Selecting Edges

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 191

5.5.4 Integrating Concepts and Discovering Algorithms

.

.

. 192

5.6 Finding a Minimum Spanning Tree of a Weighted Graph

.

.

. 192

5.6.1 Cutting or Growing Edges: A Krushkal’s like greedy

 

algorithm

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 192

5.6.2 Selecting Edges: A Prim’s like greedy Algorithm

 

197

5.6.3 A Panoramic Picture of various MST Finding Techniques199

5.6.4 The Maximum Spanning Tree Problem

.

.

.

.

.

.

.

.

. 202

5.7 Finding a Path in a Graph .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 203

5.7.1 Cutting Edges

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 203

5.7.2 Selecting Edges

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 204

5.8 The Shortest Path Problem

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 204

5.8.1 Dijkstra’s (like) Algorithm

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 207

5.8.2 Discussion on Dijkstra’s (like) Algorithm

.

.

.

.

.

.

.

. 207

5.8.3 The Shortest Path Problem Redefined:

 

The k-edge

Shortest Path Problem

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 212

5.8.4 The k-edge Longest Path Problem

 

.

.

.

.

.

.

.

.

. 216

5.8.5 The Shortest Path Problem in Undirected Graphs with

Negative Weights

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 220

5.9 Graph Traversal Techniques

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 223

5.9.1 Traditional Techniques & the Bucket-Algorithm

 

223

5.9.2 The Underlying Data Structure

.

.

.

.

.

.

.

.

.

.

.

.

. 225

5.10 Some Graph Theoretic Claims

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 225

5.11 Shortest Path Algorithms

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 234

Contents

ix

5.11.1 Single Source Shortest Path Algorithms with positive

 

edge weights

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 235

 

5.11.2 Single Source Shortest Path Algorithms for Directed

 

Acyclic Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 245

 

5.11.3 Single Source Shortest Path Algorithms for directed

 

graphs with negative edge weights

 

.

.

.

.

.

.

.

.

. 252

 

5.11.4 All Pair Shortest Path Algorithms .

.

.

.

.

.

.

.

.

.

.

. 262

5.11.5 Johnson’s all Pair Shortest Path Algorithm

 

.

.

.

.

. 272

 

5.12

Discussion

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 290

6

Network Flows, Connectivity and Matching Problems

 

293

6.1 Introduction

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 294

6.2 Definitions & Prior Knowledge

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 294

6.3 Konig’s Theorem, Menger’s Theorem & Hall’s (Marriage) The- .

orem

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 306

6.4 Menger’s Theorem

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 310

 

6.4.1 Maximum Edge-Disjoint Paths in Directed Graphs

.

. 310

6.4.2 The Concept of a Minimum Cut in Directed Graphs

321

6.4.3 A Proof of Menger’s Theorem and Finding the Mini-

 

mum Cut in Directed Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

. 323

 

6.4.4 Finding Maximum Vertex-Disjoint Paths & Minimum

 

Vertex Cut in Directed Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

. 326

 

6.4.5 Menger’s Theorem for Un-directed Graphs

.

.

.

.

.

.

. 330

6.4.6 Edge Connectivity and Vertex Connectivity for Un-

 

directed Graphs .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 335

 

6.5 Konig’s Theorem, Menger’s Theorem & Hall’s (Marriage) The-

 

orem Revisited

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 348

 

6.6 Network Flows

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 356

6.6.1 Finding Maximum Edge-Disjoint Paths in Multi-Graphs356

. 360

6.6.2 The Maximum Flow & the Minimum Cut

.

.

.

.

.

.

x

Contents

6.6.3 Algorithmic Issues & Complexity Calculations

 

362

6.6.4 Lower Bounds on Edge Flows and the Max-Cut

.

.

.

. 365

6.7 The Matching Problem in Bipartite Graphs

.

.

.

.

.

.

.

.

.

. 379

6.7.1 Maximum Matching in Un-weighted bipartite graphs

. 379

6.7.2 Maximum Matching in Complete (Binary) Weighted

Bipartite Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 382

6.7.3 Maximum Weighted Matching in Complete Weighted

Bipartite Graphs

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 386

6.8 The Max-Flow Min-Cost Problem .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 402

6.8.1 Introduction .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 402

6.8.2 Finding a Maximum Flow or Finding a Shortest Path? 402

6.8.3 Category 3 network flow Problems

.

.

.

.

.

.

.

.

.

.

. 404

6.8.4 Category 2 (and 1) network flow Problems

.

.

.

.

.

.

. 412

6.8.5 A Panoramic Picture of Similar Problems & Solutions

(once again)

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 423

6.9 Network flows with lower & upper bounds on flow and the

Circulation Problem

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 425

6.9.1 Prior knowledge:

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 425

6.9.2 New concepts

.

.

.

.

.

.

.

.

.

.

.

.