1 / 50

Çizge Algoritmaları

Learn how to find Euler paths and circuits in graphs using Euler's theorem. Identify the conditions for the existence of an Euler path or circuit and apply the algorithm to solve sample problems.

dmartell
Télécharger la présentation

Çizge Algoritmaları

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. Çizge Algoritmaları

  2. Pencil Drawing Problem-Euler Paths Which of the following pictures can be drawn on paper without ever lifting the pencil and without retracing over any segment?

  3. Definitions • An Euler path is a path that passes through each edge of a graph exactly one time. • An Euler circuit is a circuit that passes through each edge of a graph exactly one time. • The difference between an Euler path and an Euler circuit is that an Euler circuit must start and end at the same vertex.

  4. Example: Recognizing Euler Circuits • Consider the graph below. • Is • an Euler circuit? • b) Does the graph have an Euler circuit? E F D A C B

  5. Example: Recognizing Euler Circuits Solution a) No, it does not use edge BD. b) Yes, the circuit is an Euler circuit. E F D A C B

  6. Examples • Euler path • Euler circuit

  7. Euler Theorem • Euler’s Theorem • The following statements are true for connected graphs: • If a graph has exactly two odd vertices, then it has at least one Euler path, but no Euler circuit. Each Euler path must start at one of the odd vertices and end at the other. • If a graph has no odd vertices (all even vertices), it has at least one Euler circuit. An Euler circuit can start and end at any vertex. • If a graph has more than two odd vertices, then it has no Euler paths and no Euler circuits.

  8. Euler’s Theorem Suppose we have a connected graph. 1. If the graph has an Euler circuit, then each vertex of the graph has even degree. 2. If each vertex of the graph has even degree, then the graph has an Euler circuit.

  9. Finding Euler Paths To find Euler paths, we’ll first give an algorithm for finding Euler cycles and then modify it to give Euler paths. THM: An undirected graph G has an Euler circuit iff it is connected and every vertex has even degree. NOTE: for directed graphs the condition is that G be weakly connected and that every vertex has same in-degree as out-degree.

  10. Finding Euler Circuits Q: Why does the following graph have no Euler circuit?

  11. Finding Euler Circuits A: It contains a vertex of odd degree.

  12. Generalizing to Euler Paths Q: Does the following have an Euler circuit?

  13. Generalizing to Euler Paths A: No, vertices of odd degree: Q: But why does it have an Euler path?

  14. Generalizing to Euler Paths A: YES! Because exactly 2 vertices of odd degree. So can add a phantom edge between odd degree vertices:

  15. Generalizing to Euler Paths All degrees now even so find Euler cycle:

  16. Generalizing to Euler Paths Now remove phantom edge obtaining: 1 2 3 7 4 6 5

  17. B A C B C A D D E Example: Using Euler’s Theorem • Use Euler’s theorem to determine whether an Euler path or an Euler circuit exists in the figures shown from the previous example.

  18. B A C D Example: Using Euler’s Theorem continued • The graph has no odd vertices (all vertices are even). According to item 1, at least one Euler circuit exists. An Euler circuit can be determined by starting at any vertex. The Euler circuit will end at the vertex from which is started. Remember that each Euler circuit is also an Euler path.

  19. B C A D E Example: Using Euler’s Theorem continued • There are 3 even vertices (A, B, C) and two odd vertices (D, E). Based on item 2, we conclude that since there are exactly two odd vertices, at least one Euler path exists but no Euler circuits exists. Each Euler path must begin at one of the odd vertices and end at the other odd vertex.

  20. A B C E D Model Problem Explain why the graph has at least one Euler path. degree 2 number of edges at each vertex: degree 4 degree 4 2 A: D: 3 3 B: E: 4 C: 4 degree 3 Two odd vertices degree 3 • If a graph has exactly two odd vertices, then it has at least one Euler path, but no Euler circuit. Each Euler path must start at one of the odd vertices and end at the other.

  21. A B C E D Model Problem Find a Euler path. 6 5 2 3 7 4 1 8 C, E, C, A, B, D, E D, B,

  22. degree 2 degree 2 Model Problem Explain why the graph has a least one Euler circuit. degree 4 degree 4 degree 2 degree 2 degree 4 degree 4 no odd vertices 2. If a graph has no odd vertices (all even vertices), it has at least one Euler circuit. An Euler circuit can start and end at any vertex.

  23. Model Problem Find an Euler circuit. 11 10 12 9 13 3 8 4 2 14 1 7 5 6 G, C, G, I, J, H, D, C, A, B, D, F, H H, E, Euler Circuit – a circuit that travels through every edge of a graph once and only once, and must begin and end at the same vertex.

  24. degree 3 Model Problem A, B, C, and D represent rooms. The outside of the house is labeled E. The openings represent doors. a) Is it possible to find a path that uses each door exactly once? degree 6 look for a Euler path or circuit exactly 2 odd vertices • If a graph has exactly two odd vertices, then it has at least one Euler path, but no Euler circuit. Each Euler path must start at one of the odd vertices and end at the other.

  25. Model Problem A, B, C, and D represent rooms. The outside of the house is labeled E. The openings represent doors. b) If possible, find such a path. 10 9 7 2 1 3 8 6 4 5 start at one of the odd vertices E, B, D, C, A, E, C, E, D B, A,

  26. Fluery’s Algorithm • If Euler’s Theorem indicates the existence of an Euler path or Euler circuit, one can be found using the following procedure. • If the graph has exactly two odd vertices, chose one of the two odd vertices as the starting point. If the graph has no odd vertices, choose any vertex as the starting point. • Number edges as you trace through the graph according to the following rules: • After you traveled over an edge, change it to a dashed line. • When faced with a choice of edges to trace, choose an edge that is not a bridge (an edge, which, if removed from a connected graph would leave behind a disconnected graph). Travel over an edge that is a bridge only if there is no alternative.

  27. Fleury’s Algorithm • To determine an Euler path or an Euler circuit: 1. Use Euler’s theorem to determine whether an Euler path or an Euler circuit exists. If one exists, proceed with steps 2-5. 2. If the graph has no odd vertices (therefore has an Euler circuit, which is also an Euler path), choose any vertex as the starting point. If the graph has exactly two odd vertices (therefore has only an Euler path), choose one of the two odd vertices as the starting point.

  28. Fleury’s Algorithm continued 3. Begin to trace the edges as you move through the graph. Number the edges as you trace them. Since you can’t trace any edges twice in Euler paths and Euler circuits, once an edge is traced consider it “invisible.” 4. When faced with a choice of edges to trace, if possible, choose an edge that is not a bridge (i.e., don’t create a disconnected graph with your choice of edges). 5. Continue until each edge of the entire graph has been traced once.

  29. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Preliminaries. Make sure that the graph is connected and either (1) has no odd vertices (circuit), or (2) has two odd vertices (path).

  30. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Start. Choose a starting vertex. [ In case (1) this can be any vertex; in case (2) it must be one of the two odd vertices.]

  31. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.

  32. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.

  33. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.

  34. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.

  35. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.

  36. Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • End. When you can’t travel any more, the circuit (path) is complete. [In case (1) you will be back at the starting vertex; in case (2) you will end at the other odd vertex.]

  37. B A C F D G E Example • Use Fluery’s algorithm to determine an Euler circuit. • There is at least one Euler circuit since there are no odd vertices. • Start at any vertex to determine an Euler circuit.

  38. start here 10 6 9 1 5 7 B 4 A C 8 2 3 F D G E Example continued • Start at C. • Choose either CB or CD. Continue to trace from vertex to vertex around the outside of the graph.

  39. start here 10 6 9 1 5 7 B 4 A C 8 2 3 F D G E Example continued • Start at C. • Choose either CB or CD. Continue to trace from vertex to vertex around the outside of the graph.

  40. 7 3 8 4 2 6 1 5 9 Model Problem The graph has at least one Euler circuit. Find it using Fleury’s Algorithm. F E D C A B no odd vertices, begin at any vertex.

  41. Fleury's Algorithm: O(E)? • Pick any vertex to start. • From that vertex pick an edge to traverse, considering following rule: never cross a bridge of the reduced graph unless there is no other choice. • Darken that edge, as a reminder that you can't traverse it again. • Travel that edge, coming to the next vertex. • Repeat 2-4 until all edges have been traversed, and you are back at the starting vertex. By reduced graph we mean the original graph minus the darkened (already used) edges. A bridge of a graph G is an edge whose deletion increases the number of components of G.

  42. Fleury's Algorithm in Action Pick any vertex (e.g. F) Take F to C  (arbitrary) Take C to D  (arbitrary) Take D to A  (arbitrary) A bridge is not a local property (i.e. if edge EF existed then AB would not be a bridge). How can we recognize a bridge efficiently? In the original graph, AB was not a bridge. Can we preprocess the graph in O(E) time identifying bridges and building a structure that can be updated in constant time with each reduction? Take A to C. Can't go to B: that edge is a bridge of the reduced graph, and there are two other choices.

  43. Euler Paths and CircuitsDefinition DEF: An Euler path in a graph G is a simple path containing every edge in G. An Euler circuit (or Euler cycle) is a cycle which is an Euler path. NOTE: The definition applies both to undirected as well as directed graphs of all types.

  44. Euler Circuits Eulerizing Graphs Our first step is to identify the odd vertices. This graph has eight odd vertices (B,C,E,F,H,I,K,and L), shown in red.

  45. Euler Circuits Eulerizing Graphs When we add a duplicate copy of edges BC,EF,HI, and KL, we get this graph. This is the eulerized version of the original graph.

  46. Euler Circuits Eulerizing Graphs This graph shows the many possible Euler circuits,with the edges numbered in the order they are traveled..

  47. Euler Circuits Eulerizing Graphs With the four duplicate edges (BC,EF,HI,and KL) indicating the deadhead blocks where a second pass is required. The total length of this route is 28 blocks (24 blocks in the grid plus 4 deadhead blocks).

  48. Euler Circuits Eulerizing Graphs In some situations we need to find an exhaustive route, but there is no requirement that it be closed—the route may start and end at different points.

  49. Euler Circuits Eulerizing Graphs In these cases, we want to leave two odd vertices on the graph unchanged, and change the other odd vertices into even vertices.

  50. Euler Circuits Eulerizing Graphs This process id called a semi-eulerization of the graph. In this case the route will start at one of the two odd vertices and end at the other one.

More Related