1 / 57

Introduction to Graphs

Introduction to Graphs. Lecture 7: Sep 24. (based on slides in MIT 6.042). Seven Bridges of Königsberg. Is it possible to walk with a route that crosses each bridge exactly once?. Seven Bridges of Königsberg. Forget even more. Forget unimportant details. A Graph. An edge (or a line).

luigi
Download Presentation

Introduction to Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Graphs Lecture 7: Sep 24 (based on slides in MIT 6.042)

  2. Seven Bridges of Königsberg Is it possible to walk with a route that crosses each bridge exactly once?

  3. Seven Bridges of Königsberg Forget even more. Forget unimportant details.

  4. A Graph An edge (or a line) A vertex (or a node, or a point) e6 d e7 e5 e4 c a e3 e2 e1 b So, what is the “Seven Bridges of Königsberg” problem now? To find a walk that visits each edge exactly once.

  5. Euler’s Solution Question: Is it possible to find a walk that visits each edge exactly once. e6 d e7 e5 e4 v c a e3 e2 e1 b Suppose there is such a walk, there is a starting point and an endpoint point. For every “intermediate” point v, there must be the same number of incoming and outgoing edges, and so v must have an even number of edges.

  6. Euler’s Solution Question: Is it possible to find a walk that visits each edge exactly once. e6 d So, at most two vertices can have odd number of edges. e7 e5 e4 In this graph, every vertex has only an odd number of edges, and so there is no walk which visits each edge exactly one. c a e3 e2 e1 b Suppose there is such a walk, there is a starting point and an endpoint point. For every “intermediate” point v, there must be the same number of incoming and outgoing edges, and so v must have an even number of edges.

  7. Euler’s Solution So Euler showed that the “Seven Bridges of Königsberg” is unsolvable. When is it possible to have a walk that visits every edge exactly once? 一筆畫問題 Is it always possible to find such a walk if there is at most two vertices with even number of edges?

  8. Euler’s Solution So Euler showed that the “Seven Bridges of Königsberg” is unsolvable. When is it possible to have a walk that visits every edge exactly once? Is it always possible to find such a walk if there is at most two vertices with even number of edges? NO!

  9. Euler’s Solution So Euler showed that the “Seven Bridges of Königsberg” is unsolvable. When is it possible to have a walk that visits every edge exactly once? Is it always possible to find such a walk if the graph is “connected” and there are at most two vertices with even number of edges? YES!

  10. Euler’s Solution So Euler showed that the “Seven Bridges of Königsberg” is unsolvable. When is it possible to have a walk that visits every edge exactly once? Eulerian path Euler’s theorem: A graph has an Eulerian path if and only if it is “connected” and has at most two vertices with an odd number of edges. This theorem was proved in 1736, and was regarded as the starting point of graph theory.

  11. Application 1 Graph is very useful in representing relations (check Chapter 3.1). CSC 2110 CSC 6240 CSC 1130 CSC 1110 • Each course is a vertex. • There is an edge between two courses if some student is taking both. How can we schedule the exams in a minimum number of days so that no students would have conflicts? This is a graph colouring problem.

  12. Application 2 • Each computer is a vertex. • There is an edge between two • computers if there is a direct • connection. • How to find a shortest route between two computers? • How to find a cheapest network to connect all computers? • How to send the maximum amount of information between two computers? These are all graph problems (shortest path, minimum spanning tree, maximum flow).

  13. Application 3 • Each junction is a vertex. • Each edge is a road. • How to make every road an “one-way-road” so that everywhere can still be reached from everywhere? This is a graph orientation problem.

  14. Application 4 Isaac Darek Tom Jerry Marking Tutorials Solutions Newsgroup • Each person is a vertex above. • Each task is a vertex below. • There is an edge between a person and a task • if that person is willing to take up that task. How to assign people to tasks so that all tasks can be finished? This is a graph matching problem.

  15. Simple Graph Directed Graph Types of Graphs Will see later Eulerian path problem Multi-Graph Most of the problems in this course.

  16. Simple Graphs a b A graph G=(V,E) consists of: A set of vertices,V A set of undirected edges, E f c • V(G) = {a,b,c,d,e,f} • E(G) = {ad,af,bd,be,cd,ce,df} e d G Two vertices a,b are adjacent (neighbours) if the edge ab is present.

  17. Vertex Degrees a An edge uv is incident on the vertex u and the vertex v. b f The neighbour set N(v) of a vertex v is the set of vertices adjacent to it. c e e.g. N(a) = {d,f}, N(d) = {a,b,c,f}, N(e) = {b,c}. d degree of a vertex = # of incident edges e.g. deg(d) = 4, deg(a)=deg(b)=deg(c)=deg(e)=deg(f)=2. the degree of a vertex v = the number of neighbours of v? For multigraphs, NO. For simple graphs, YES.

  18. Degree Sequence Is there a graph with degree sequence (2,2,2)? YES. Is there a graph with degree sequence (3,3,3,3)? YES. Is there a graph with degree sequence (2,2,1)? NO. 2 2 1 Is there a graph with degree sequence (2,2,2,2,1)? Where to go? NO. What’s wrong with these sequences?

  19. Handshaking Lemma For any graph, sum of degrees = twice # edges Lemma. Corollary. • Sum of degree is an even number. • Number of odd degree vertices is even. Examples. 2+2+1 = odd, so impossible. 2+2+2+2+1 = odd, so impossible.

  20. Handshaking Lemma Lemma. Proof. Each edge contributes 2 to the sum on the right. Q.E.D. Question. Given a degree sequence, if the sum of degree is even, is it true that there is a graph with such a degree sequence? For simple graphs,NO, consider the degree sequence (3,3,3,1). For multigraphs (with self loops), YES! (easy by induction)

  21. 122 257 122 122 Grant 145 145 Sharat Albert 257 257 99 67 67 Christos 306 306 Sonya 99 99 Jessica 145 306 67 Same Graphs? Same graph (different drawings) Same graph (different labels)

  22. Graph Isomorphism All that matters is the connections. Graphs with the same connections are isomorphic. Informally, two graphs are isomorphic if they are the same after renaming. G1isomorphicto G2means there isan edge-preserving vertex matching. relation preserving renaming function Graph isomorphism has applications like checking fingerprint, testing molecules…

  23. Hay Dog Pig Corn Cow Cat Beef Tuna Are These Isomorphic? A bijection. f (Dog) = Beef f (Cat) = Tuna f (Cow) = Hay f (Pig) = Corn

  24. Hay Dog Pig Corn Cow Cat Beef Tuna Are These Isomorphic? A bijection. Edge preserved? YES! If there is an edge in the original graph, there is an edge after the mapping.

  25. Hay Dog Pig Corn Cow Cat Beef Tuna Are These Isomorphic? A bijection. Non-Edge preserved? YES! If there is no edge in the original graph, there is no edge after the mapping.

  26. Graph Isomorphism G1isomorphicto G2means there isan edge-preserving vertex matching. bijectionf: V1 →V2 u —v inE1iff f (u)—f (v)inE2 uv is an edge in G1 f(u)f(v) is an edge in G2 • If G1 and G2 are isomorphic, do they have the same number of vertices? • If G1 and G2 are isomorphic, do they have the same number of edges? • If G1 and G2 are isomorphic, do they have the same degree sequence? • If G1 and G2 have the same degree sequence, are they isomorphic? YES YES YES NO

  27. Exercise How to show two graphs are isomorphic? Find a mapping and show that it is edge-preserving. How to show two graphs are non-isomorphic? Find some isomorphic-preserving properties which is satisfied in one graph but not the other. Non-isomorphic all degree 3 degree 2

  28. Exercise Which is isomorphic to G1? Testing graph isomorphism is not easy – No known general method to test graph ismorphism much more efficient than checking all possibilities.

  29. Paths Path: sequence of adjacent vertices ( )

  30. ) ( Simple Paths Simple Path: all vertices different

  31. Connectedness • Vertices v, ware connected if and only if there is a path starting at v and ending at w. • A graphis connected iff every pair of vertices are connected. Is the relation “connected” an equivalence relation? • Equivalence relation R=(V,E) • Reflexive • Symmetric • Transitive (a,a) in E for all a (a,b) in E implies (b,a) in E (a,b) in E and (b,c) in E implies (a,c) in E

  32. Connectedness • Vertices v, ware connected if and only if there is a path starting at v and ending at w. • A graphis connected iff every pair of vertices are connected. Is the relation “connected” an equivalence relation? Let the relation R be connected. • Equivalence relation R=(V,E) • Reflexive • Symmetric • Transitive A vertex v is connected to itself. (u,v) is connected implies (v,u) is connected. (u,v) is connected and (v,w) is connected implies (u,w) is connected.

  33. E17 13 12 26 16 66 E25 10 8 4 Connectedness So the relation “u is connected to v” is an equivalence relation. Every graph consists of separate connected pieces (subgraphs) called connected components (equivalence classes) 3 connected components So a graph is connected if and only if it has only 1connected component.

  34. a w v Cycles A cycle is a path that begins and ends with same vertex. b cycle: v ···b ···w ···w ···a ···v also:a ···v ···b ···w ···w ···a

  35. v Simple Cycles A simple cycle is a cycle that doesn’t cross itself In a simple cycle, every vertex is of degree exactly 2. w also: w ···v ···w cycle: v ···w ···v

  36. c v u Shortest Paths A path between u and v is a shortest path if among all u-v paths it uses the minimum number of edges. Is a shortest path between two vertices always simple? Idea: remove the cycle will make the path shorter.

  37. c v u Shortest Paths Lemma. A shortest path between two vertices is simple. Proof (by contradiction): • Suppose there is a non-simple shortest path P=(u,…,v) • Let c be the first vertex that is visited twice. • Then P=(u,P1,c,P2,c,P3,v). • But P’=(u,P1,c,P3,v) is shorter, a contradiction. P3 This is a simple cycle without using vertices in P1 P1 P2

  38. Eulerian Graphs Euler’s theorem: A graph has an Eulerian path if and only if it is connected and has at most two vertices with an odd number of edges. Odd degree vertices. Can a graph has only 1 odd degree vertex? Euler’s theorem: A graph has an Eulerian path if and only if it has zero or two vertices with odd degrees. Proof by induction.

  39. Proof Idea Assume every vertex is of even degree. Pick any vertex, go to unvisited edges as long as possible. 1 6 3 5 2 4 Get stuck. Now what?

  40. Proof Idea Assume every vertex is of even degree. Pick any vertex, go to unvisited edges as long as possible. 1 6 3 5 2 4 Idea: Remove the edges already visited.

  41. Proof Idea Assume every vertex is of even degree. Again, pick any vertex, go to unvisited edges as long as possible. 1 6 3 5 2 4 The remaining graph is still Eulerian (why?)

  42. Proof Idea Assume every vertex is of even degree. Again, pick any vertex, go to unvisited edges as long as possible. 15 1 12 6 9 3 5 13 10 16 2 14 11 7 8 4 Let’s say we’ve found an Eulerian path in the remaining graph. Now what?

  43. Proof Idea Assume every vertex is of even degree. Idea: Combine the two Eulerian paths. Common vertex v 13 1 10 16 7 3 15 11 8 14 2 12 9 5 6 4 • Go along the first Eulerian path until reaching v, • follow the second Eulerian path visiting all the edges until coming back v, • then follow the remaining first Eulerian path.

  44. Complication What if we start and then get stuck in the blue vertex?

  45. Complication What if we start and then get stuck in the blue vertex? Then the remaining graph is disconnected into more components. The same idea applies.

  46. Proof by Induction Euler’s theorem: A graph has an Eulerian path if and only if it is connected and has zero or two vertices with odd degrees. Proof (by strong induction): Induction hypothesis: Euler’s theorem is true for all graphs with at most m edges. Base case (m=1): easy.

  47. Proof by Induction Euler’s theorem: A graph has an Eulerian path if and only if it is connected and has zero or two vertices with odd degrees. Induction step: • Pick a vertex x of odd degree (if G has one), otherwise any vertex x. • Let v1=x, and e1={x,y} be an unvisited edge incident on x. • Set v2=y, continue in this way each time choose an unvisited edge. • Stop when we reach a vertex vk that does not have any unused edge. Let the path so far be P=(v1,W,vk).

  48. Step 1 Assume every vertex is of even degree. Pick any vertex, go to unvisited edges as long as possible. 1 6 3 5 2 The path P is in red. 4 Get stuck. The remaining graph is still Eulerian (why?)

  49. Proof by Induction Euler’s theorem: A graph has an Eulerian path if and only if it is connected and has zero or two vertices with odd degrees. Let the path so far be P=(v1,W,vk). Why do we get stuck? If the degree of v1 is even, then vk=v1. because every intermediate vertex is of even degree, and so the path would not end up there. If the degree of v1 is odd, then vk is another odd vertex. since v1 is of odd degree, the path would not end up there.

  50. Proof by Induction Euler’s theorem: A graph has an Eulerian path if and only if it is connected and has zero or two vertices with odd degrees. Let the path so far be P=(v1,W,vk). Why do we get stuck? • If the degree of v1 is even, then vk=v1. • If the degree of v1 is odd, then vk is another odd vertex. Claim. If the edge in P are removed from the graph, then in the remaining graph every vertex is of even degree. If (i) happens, every vertex in G and in P is of even degree. If (ii) happens, in G and in P, only v1 and vk are of odd degree.

More Related