Classic Graph Theory Problems

Similar documents
Chapter 3: Paths and Cycles

8. The Postman Problems

6.2. Paths and Cycles

Precept 4: Traveling Salesman Problem, Hierarchical Clustering. Qian Zhu 2/23/2011

Graph Theory and Applications

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

3 Euler Tours, Hamilton Cycles, and Their Applications

EECS 203 Lecture 20. More Graphs

Varying Applications (examples)

Solving problems on graph algorithms

Graph Theory. Connectivity, Coloring, Matching. Arjun Suresh 1. 1 GATE Overflow

Approximation Algorithms

Graph Theory Part A. Peter Keevash

CS270 Combinatorial Algorithms & Data Structures Spring Lecture 19:

Math 776 Graph Theory Lecture Note 1 Basic concepts

Graphs and Algorithms 2015

Graphs and Algorithms 2016

Jessica Su (some parts copied from CLRS / last quarter s notes)

Matching 4/21/2016. Bipartite Matching. 3330: Algorithms. First Try. Maximum Matching. Key Questions. Existence of Perfect Matching

MEI Further Mathematics Support Programme

Theorem 2.9: nearest addition algorithm

Introduction to Graph Theory

Chapter 9 Graph Algorithms

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

8.2 Paths and Cycles

Outline. 1 The matching problem. 2 The Chinese Postman Problem

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

Chapter 11: Graphs and Trees. March 23, 2008

Simple graph Complete graph K 7. Non- connected graph

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

V1.0: Seth Gilbert, V1.1: Steven Halim August 30, Abstract. d(e), and we assume that the distance function is non-negative (i.e., d(x, y) 0).

INTRODUCTION TO GRAPH THEORY. 1. Definitions

Chapter 9 Graph Algorithms

Graph theory: basic concepts

0.0.1 Network Analysis

How can we lay cable at minimum cost to make every telephone reachable from every other? What is the fastest route between two given cities?

Graph Algorithms Maximum Flow Applications

Network Topology and Graph

Discrete mathematics

Notes for Recitation 9

Graphs: Introduction. Ali Shokoufandeh, Department of Computer Science, Drexel University

Maximum Flows of Minimum Cost

Lecture 11: Maximum flow and minimum cut

val(y, I) α (9.0.2) α (9.0.3)

GRAPH THEORY AND LOGISTICS

CSE 417 Network Flows (pt 3) Modeling with Min Cuts

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

CS261: A Second Course in Algorithms Lecture #16: The Traveling Salesman Problem

Lecture 10 Graph Algorithms

Chapter 9 Graph Algorithms

Lecture 8: The Traveling Salesman Problem

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/z

Graph Theory. Chapter 4.

Material handling and Transportation in Logistics. Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena

Index. stack-based, 400 A* algorithm, 325

Questions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)

Institute of Operating Systems and Computer Networks Algorithms Group. Network Algorithms. Tutorial 4: Matching and other stuff

Graph Theory. Part of Texas Counties.

11.2 Eulerian Trails

Course Introduction / Review of Fundamentals of Graph Theory

Topic 10 Part 2 [474 marks]

Lecture Notes for IEOR 266: Graph Algorithms and Network Flows

Number Theory and Graph Theory

Math 443/543 Graph Theory Notes

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

1 The Traveling Salesperson Problem (TSP)

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

Lecture 19. Broadcast routing

Ma/CS 6a Class 8: Eulerian Cycles

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

Math 778S Spectral Graph Theory Handout #2: Basic graph theory

Algorithm Design and Analysis

List of Theorems. Mat 416, Introduction to Graph Theory. Theorem 1 The numbers R(p, q) exist and for p, q 2,

Unweighted Graphs & Algorithms

Assignments are handed in on Tuesdays in even weeks. Deadlines are:

2. CONNECTIVITY Connectivity

Minimum Cost Edge Disjoint Paths

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Algorithm Design (8) Graph Algorithms 1/2

Introduction III. Graphs. Motivations I. Introduction IV

1 Variations of the Traveling Salesman Problem

Modules. 6 Hamilton Graphs (4-8 lectures) Introduction Necessary conditions and sufficient conditions Exercises...

Discrete mathematics II. - Graphs

Elements of Graph Theory

by conservation of flow, hence the cancelation. Similarly, we have

Final. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013

5.5 The Travelling Salesman Problem

1 The Traveling Salesman Problem

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Fundamental Properties of Graphs

5.1 Min-Max Theorem for General Matching

Traveling Salesperson Problem (TSP)

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

Assignment 4 Solutions of graph problems

Jörgen Bang-Jensen and Gregory Gutin. Digraphs. Theory, Algorithms and Applications. Springer

BIL694-Lecture 1: Introduction to Graphs

Transcription:

Classic Graph Theory Problems Hiroki Sayama sayama@binghamton.edu

The Origin

Königsberg bridge problem Pregel River (Solved negatively by Euler in 176)

Representation in a graph Can all the seven edges be traversed in a single trail? 4

Theorem on the Eulerian trail An undirected connected graph has an Eulerian trail (a trail that includes every edge in a graph) if and only if it has at most two nodes of odd degree This case has four nodes of odd degree -> No Eulerian trail 5

Theorem on the Eulerian trail The condition is obviously necessary Why is it sufficient? If all nodes have even degrees (called Eulerian graph), the graph must have a cyclic trail that includes every edge (Easy to show that the longest trail must be cyclic and include every edge) If there are two nodes with odd degrees (called semi-eulerian graph), adding a new edge between them will reduce the problem to the above case 6

Implication Whether there exists an Eulerian trail in a graph can be determined by node degrees only Global property of a network is determined by local properties of nodes This is a highly exceptional case; doesn t happen in general 7

Matching Problem

Matching problem (bipartite) V 1 V 2 Does this bipartite graph G have a matching from V 1 to V 2? G 9

Exercise A company announced five position openings (clerk, salesperson, programmer, system engineer, and designer); six job seekers applied to these positions Applicant A looks for a clerk position; B for clerk or sales; C for sales, programming or SE; D for programming or design; and both E and F for design Can this company fill in all the positions? 10

A marriage theorem A bipartite graph G has a perfect matching from V 1 to V 2 if and only if every subset of V 1 is collectively connected to at least as many nodes in V 2 as itself 11

Exercise The condition is obviously necessary Why is it sufficient? (think about it yourself) 12

Matching problem (non-bipartite) Matching: Subset of edges that do not share any nodes What is the size of maximal matching? Is perfect matching possible? 1

Shortest Path Finding

Shortest path finding problem Given two nodes for start and goal, determine which path is the shortest one between these two nodes Applications can be found in Google Maps, car navigation systems, train transit search systems, etc. (Weights may be distance, time, or fare) 15

Dijkstra s algorithm E. Dijkstra (1959) Finds the shortest paths from a given node to every other node in a graph Works with both undirected/directed, unweighted/weighted graphs Known to be the best among several shortest path finding algorithms 16

Dijkstra s algorithm (1) w(e): weight of edge e u s : start node, u g : goal node L(u): a label assigned to node u that represents the tentative shortest distance from u s to u Initially L(u=u s )=0, L(u u s )= T: a set of nodes for which the shortest paths are not yet determined Initially T={ all nodes } 17

Dijkstra s algorithm (2) 1. Find a node with the smallest L in T (call it v hereafter) 2. If v=u g, return L(v) as an answer. Otherwise, for every edge e=<v, x>: If x is in T and L(x) > L(v) + w(e), then let L(x) = L(v) + w(e) 4. Remove v out of T and go back to 1 18

Example Start A 0 Edges: A -> B, C, E B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 Contents of T: {A, B, C, D, E} E Goal 19

Example Start A 0 Edges: A -> B, C, E B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 Contents of T: {A, B, C, D, E} E Goal 20

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 Contents of T: {A, B, C, D, E} 10 E Goal 21

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 Contents of T: {B, C, D, E} 10 E Goal 22

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 5 Contents of T: {B, C, D, E} 8 E Goal 2

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 5 Contents of T: {B, D, E} 8 E Goal 24

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 5 Contents of T: {D, E} 8 E Goal 25

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 5 Contents of T: {D, E} 7 E Goal 26

Example Start A 0 Edges: A -> B, C, E 4 B 4 C 10 B -> A, C, D, E C -> A, B, D, E D -> B, C, E E -> A, B, C, D 2 4 D 2 5 5 Contents of T: {E} 7 E Goal 27

Exercise Find the shortest path and its length in the following graph using Dijkstra s algorithm Start w=1 Goal w=2 w= 28

Why Dijkstra s algorithm works (1) For each node in T, the label L(u) always represents the length of the tentative shortest path from u s to the node, without visiting any nodes in T u s 0 5 7 4 5 4 6 6 u g Solid lines show a subgraph induced by T 29

Why Dijkstra s algorithm works (2) There is still some possibility for each node in T that it may get smaller L(u) by way of other nodes in T u s 0 6 7 4 6 4 5 6 5 0

Why Dijkstra s algorithm works () However, the node with the smallest L(u) in T doesn t have such possibility -> For such a node, L(u) is the final value u s 0 7 4 6 4 5 6 5 1

Why Dijkstra s algorithm works (4) Hence that node can be removed from T, reducing the size of T Repeat this process until the goal node is finally removed from T u s 0 7 4 6 4 5 6 5 6 7 2

Exercise How to obtain the shortest path (i.e., sequence of edges) with the Dijkstra algorithm, not just its length? Assign an additional label k(u) to each node to keep track of where I came from k is updated every time L is updated Once the shortest distance is obtained, reconstruct the actual path by following k(u) from the goal back to the start

Floyd-Warshall algorithm R. W. Floyd / S. Warshall (1962) Calculates shortest path lengths between ALL pairs of nodes Works with undirected/directed, weighted/unweighted networks Computational complexity: O(n ) Dynamic programming: Algorithm is simple and easy! 4

Floyd-Warshall algorithm (1) d (k) ij: length of the shortest path between nodes i and j in which only nodes 1, 2,, k are allowed to appear on the path d (0) ij: edge weight between nodes i & j ( if i and j are not connected) 5

Floyd-Warshall algorithm (2) Basic idea: calculate d (k) ij using d (k-1) ij Update d (k) ij only if it helps to go through node k d (k) ij = min { d (k-1) ij, d (k-1) ik + d (k-1) kj } Repeat this for k = 1 ~ n 6

Exercise B A 4 C 2 D 5 10 Calculate shortest path lengths using the Floyd- Warshall algorithm 4 E 2 Show how d (k) ij develops over time 7

Other Route Search Problems on Networks

Chinese Postman Problem (CPP) (Originally proposed by Kwan Mei-Ko in 1962) Departing from a central post office in a city, a postman has to go through all the streets in the city, delivering mail to streetside houses, and then come back to the post office Tell him the most efficient route to go through all the streets in the city 9

Chinese Postman Problem (CPP) A problem to find the shortest cyclic walk that includes every edge in a graph Relatively easy to find for Eulerian or semi-eulerian graphs Can be solved in general by finding which edges you should travel twice 40

Exercise Find the most efficient cyclic walk for a postman working in a city (graph below) Assume every edge has length 1 41

Traveling Salesman Problem (TSP) A salesman, who has just arrived at a central station of a city, has to visit all the houses in the city to sell stuff and then come back to the station He shouldn t visit the same house more than once Tell him the most efficient route to visit every house in the city just once 42

Traveling Salesman Problem (TSP) A problem to find the shortest cyclic path that includes every node in a graph? Very hard to solve in general 4

NP-hard problems Obtaining optimal solutions for TSP is known to be in the class called NPhard problems Intuitively: Problems whose general solutions require computational complexity that is believed not to be bound by a polynomial of the problem size n (no rigorous proof given yet) 44

Minimum Spanning Tree

Minimum spanning tree A subgraph of a connected network that is a tree (= graph with no cycles) and connects all the nodes with the smallest sum of link weights Works with weighted undirected graphs Useful for finding and visualizing the backbone of a complex network Maximum spanning tree could also be obtained by inverting link weights 46

Kruskal s algorithm T: set of trees (initially just a set of nodes) L: set of links 1. Take a link with minimum weight from L 2. If the selected link connects two trees in T, connect them in T Otherwise discard it. Repeat 1 & 2 until you get MST 47

Exercise Find the minimum spanning tree of the following network w=1 w=2 w= 48

Exercise Generate a random network with n = 100, p = 0.05 Assign random weights to each link Visualize the original network & its minimum spanning tree using the same node positions 49

Max-Flow Min-Cut Theorem

Thickness of connection between nodes in unweighted graphs Edge-disjoint path Disconnecting set Menger s theorem 51

Edge-disjoint paths and disconnecting sets Think about multiple paths that connect between nodes v and w If they have no common edges, they are called edge-disjoint paths If such paths always have to go through one of the edges in a selected set, then the set is called vw-disconnecting set 52

Exercise Give some examples of edge-disjoint paths between v and w and vwdisconnecting sets in the graph below v w 5

Menger s theorem (edge version) The maximal # of edge-disjoint paths between nodes v and w in a connected graph equals the minimum # of edges in the smallest vw-disconnecting set Holds for both undirected and directed graphs Intuitive explanation: The thickness of connection between two nodes is determined by the capacity of the narrowest part 54

Exercise Confirm Menger s theorem by finding edgedisjoint paths between v and w and the smallest vw-disjointing set in the graph below v w 55

Thickness of connection between nodes in weighted directed graphs Flow Cut Maximum-flow minimum-cut theorem 56

Flow A flow from source v to sink w in a weighted directed graph is defined by the assignment of local current to each edge, f(e), that satisfy: f(e) w(e) Local current must not exceed the weight (capacity) on every edge Σ x f(<u, x>) = Σ y f(<y, u>) for u v, w Incoming volume equals outgoing volume for all nodes except for source and sink 57

Exercise Make a sample flow with volume from v to w on the graph below Each number represents edge capacity 1 2 v 2 1 4 2 2 2 2 2 2 w 58

Maximum flow A volume of a flow is defined by the total outgoing volume at source v (= total incoming volume at sink w) A maximum flow is a flow that conveys the maximum volume from v to w on a graph 59

Cut, minimum cut A set of edges C is called a cut if every path between v and w has to go through one of the edges in C (the same notion as vw-disconnecting set) A capacity of a cut is the sum total of the weights of edges in the cut Any flow b/w v and w can t exceed the capacity of any of their cuts A minimum cut is a cut that has minimum capacity 60

Maximum-flow minimum-cut theorem In any graph, the maximum flow between nodes v and w is exactly the capacity of the minimum cut between v and w (Assuming each weight as 1 will reduce this theorem to Menger s one) 61

Exercise Confirm the maximum-flow minimumcut theorem on the graph below 1 2 v 2 1 4 2 2 2 2 2 2 w 62

Intuitive proof (1) Given a flow on a graph, try to pick up every unsaturated edge that does not use its capacity to the full extent [i.e. f(e) < w(e)] If the flow is maximum, then you cannot reach sink w from source v by using such unsaturated edges only If you can, that means the flow is not maximum yet 6

Intuitive proof (2) Call the set of all nodes that can be reached by using only unsaturated edges S Call the set of all other nodes S Since v is in S and w is in S, the set of edges bridging from S to S forms a cut between v and w 64

Intuitive proof () All the edges from S to S must be saturated By the definition of S All the edges from S back to S must be with 0 flow Otherwise you could obtain a yet greater flow by canceling such a cyclic flow occurring in the middle of the graph 65

Intuitive proof (4) All the edges from S to S must be saturated All the edges from S to S must be with 0 flow I.e., the total volume of the flow from S to S is all originated at source v, and is absorbed in sink w (= the total flow in the entire graph) This flow is exactly the sum total of the weights of all the edges from S to S (= capacity of the cut) 66

Intuitive proof (5) Maximum flow = a capacity of a cut A minimum cut would have a capacity equal to or less than that of this cut; however, it must not be less than any flow by definition This cut must be a minimum cut It always equals the maximum flow 67

Exercise Create some non-trivial weighted network using NetworkX Choose one node arbitrarily Assess the strength of connection from the node to each of the rest of nodes by (1) distance and (2) max flow, and paint them using the results 68