Presentation is loading. Please wait.

Presentation is loading. Please wait.

Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday.

Similar presentations


Presentation on theme: "Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday."— Presentation transcript:

1 Eulerian Graphs CSE 331 Section 2 James Daly

2 Reminders Project 3 is out Covers graphs Due Friday

3 Review: Graphs G = (V, E) G is a graph V is a set of vertices / nodes E is a set of edges between vertices A vertex u is adjacent to vertex v if and only if the edge uv is in E

4 Graph Example V2V2 V1V1 V3V3 V5V5 V4V4 V1 is connected to V3 but not to V4

5 Review: Paths A path is a sequence of vertices v 1, v 2, …, v n such that v i v i+1 is in E for 1 ≤ i < n A simple path is a path where all vertices are distinct (except maybe the first and last) A cycle is a path that starts and ends at the same vertex

6 Seven Bridges of Konigsberg In Konigsberg (now Kaliningrad), can you cross each of the bridges exactly once? Image source: Wikipedia

7 Seven Bridges of Konigsberg The townsmen, after spending several hours drinking in the inn on the center island would try to walk the bridges Some would return after their success None could repeat it during the day

8 Proof Theorem: It is impossible to walk the bridges of Konigsburg Proof: After entering one of the banks by one bridge, you must leave by another. Thus you traverse an even number of bridges from each bank. The exception is where you start and end (which have an odd number) Since all four locales have an odd number of bridges, you cannot use all of the bridges

9 Eulerian Graphs An Eulerian path is a path which visits each edge exactly once An Eulerian cycle is a cycle which visits each edge exactly once A graph is Eulerian if it contains an Eulerian cycle A graph is semi-Eulerian if it contains an Eulerian path but not an Eulerian cycle

10 Eulerian Graphs Theorem: A graph is Eulerian iff it is connected and every vertex has even degree Proof: Since you must leave every vertex that you enter, each intermediate vertex must have edges in pairs, so they must have even degree. The exception is the first and last vertices. Since they are the same, they cancel out, leaving it with even degree. Corollary: A semi-Eulerian graph has exactly two vertices of odd degree.

11 Bridges of Kaliningrad Two of the bridges were destroyed during WW2 Two of the bridge were replaced Five bridges total A path exists, but it starts and ends on the islands Image Source: Wikipedia

12 Finding an Eulerian Path / Tour If all vertices have even degree Start anywhere and get an Eulerian Tour If exactly two have odd degree Start at one of them and get an Eulerian Path Otherwise no path exists Same algorithm works for both cases Works by a depth-first search

13 EulerianPath(V, E, v 0 ) C ← (v 0 ) // Linked list Ptr = C.Tail // Space after v 0 While (Ptr != C.Head) v ← Ptr.Prev If (deg(v) > 0) Pick u from Neighbors(v) E -= vu Ptr.InsertBefore(u) Else Ptr-- Return C


Download ppt "Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday."

Similar presentations


Ads by Google