Eulerian tours Miles Jones MTThF 8:30-9:50am CSE 4140 August 15, 2016.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

CS 336 March 19, 2012 Tandy Warnow.
Chapter 8 Topics in Graph Theory
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
Graph-02.
Introduction to Graphs
BY: MIKE BASHAM, Math in Scheduling. The Bridges of Konigsberg.
Koenigsberg bridge problem It is the Pregel River divided Koenigsberg into four distinct sections. Seven bridges connected the four portions of Koenigsberg.
Section 2.1 Euler Cycles Vocabulary CYCLE – a sequence of consecutively linked edges (x 1,x2),(x2,x3),…,(x n-1,x n ) whose starting vertex is the ending.
Introduction to Graphs Lecture 18: Nov 16. Seven Bridges of Königsberg Is it possible to walk with a route that crosses each bridge exactly once?
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
Math Foundations Week 12 Graphs (2). Agenda Paths Connectivity Euler paths Hamilton paths 2.
Euler Paths and Circuits. The original problem A resident of Konigsberg wrote to Leonard Euler saying that a popular pastime for couples was to try.
Discrete Math Round, Round, Get Around… I Get Around Mathematics of Getting Around.
Copyright © Cengage Learning. All rights reserved.
GRAPH Learning Outcomes Students should be able to:
EECS 203: It’s the end of the class and I feel fine. Graphs.
Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.
Graphs and DNA sequencing CS 466 Saurabh Sinha. Three problems in graph theory.
1 Excursions in Modern Mathematics Sixth Edition Peter Tannenbaum.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
CSNB143 – Discrete Structure Topic 9 – Graph. Learning Outcomes Student should be able to identify graphs and its components. Students should know how.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
Lecture 10: Graph-Path-Circuit
Introduction to Graphs. This Lecture In this part we will study some basic graph theory. Graph is a useful concept to model many problems in computer.
Vertex-Edge Graphs Euler Paths Euler Circuits. The Seven Bridges of Konigsberg.
AND.
Associated Matrices of Vertex Edge Graphs Euler Paths and Circuits Block Days April 30, May 1 and May
Euler Paths and Circuits. The original problem A resident of Konigsberg wrote to Leonard Euler saying that a popular pastime for couples was to try.
Eulerian Paths and Cycles. What is a Eulerian Path Given an graph. Find a path which uses every edge exactly once. This path is called an Eulerian Path.
MAT 2720 Discrete Mathematics Section 8.2 Paths and Cycles
Copyright 2013, 2010, 2007, Pearson, Education, Inc. Section 14.2 Euler Paths, and Euler Circuits.
Chapter 11 - Graph CSNB 143 Discrete Mathematical Structures.
Grade 11 AP Mathematics Graph Theory Definition: A graph, G, is a set of vertices v(G) = {v 1, v 2, v 3, …, v n } and edges e(G) = {v i v j where 1 ≤ i,
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2, 11.3
Trees.
CS Lecture 22 Graph Theory. Can I draw the above figure in one continuous trace with no line being drawn twice?
Graphs. Representations of graphs : undirected graph An undirected graph G have five vertices and seven edges An adjacency-list representation of G The.
MAT 110 Workshop Created by Michael Brown, Haden McDonald & Myra Bentley for use by the Center for Academic Support.
An Introduction to Graph Theory
Excursions in Modern Mathematics Sixth Edition
Excursions in Modern Mathematics Sixth Edition
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
EECS 203 Lecture 19 Graphs.
CSNB 143 Discrete Mathematical Structures
Çizge Algoritmaları.
Graphs: Definitions and Basic Properties
Graphs Hubert Chan (Chapter 9) [O1 Abstract Concepts]
Computing Connected Components on Parallel Computers
Euler Paths and Circuits
Agenda Lecture Content: Introduction to Graph Path and Cycle
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
EECS 203 Lecture 20 More Graphs.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Discrete Maths 9. Graphs Objective
CSE 421: Introduction to Algorithms
Can you draw this picture without lifting up your pen/pencil?
Euler Paths and Circuits
Introduction to Graph Theory Euler and Hamilton Paths and Circuits
Graph Theory.
Excursions in Modern Mathematics Sixth Edition
Konigsberg- in days past.
Euler and Hamilton Paths
Applied Combinatorics, 4th Ed. Alan Tucker
Warm Up – 3/19 - Wednesday Give the vertex set. Give the edge set.
A Survey of Mathematics with Applications
5 The Mathematics of Getting Around
Graph Theory Proof In Class Exercise.
Presentation transcript:

Eulerian tours Miles Jones MTThF 8:30-9:50am CSE 4140 August 15, 2016

Seven Bridges of Konigsberg Is there a path that crosses each bridge (exactly) once? Rosen p. 693

Seven Bridges of Konigsberg Observe: exact location on the north side doesn't matter because must come & go via a bridge. Can represent each bridge as an edge.

Seven Bridges of Konigsberg Is there a path where each edge occurs exactly once? Eulerian tour Rosen p. 693

Eulerian tour and Eulerian cycle (or circuit) Eulerian tour (or path): a path in a graph that passes through every edge exactly once. Eulerian cycle (or circuit): a path in a graph that pass through every edge exactly once and starts and ends on the same vertex.

Seven Bridges of Konigsberg redux Which of these puzzles can you draw without lifting your pencil off the paper?

Algorithmic questions related to Euler tours Existence: Does the given graph G contain an Euler tour? Path: Find an Euler tour for the given graph G, if possible. Turns out there are great algorithms for each of these … next!

Algorithmic questions related to Euler tours Hamiltonian tour A Hamiltonian tour is a path where each vertex occurs exactly once. Existence: Does the given graph G contain a Hamiltonian tour? Path: Find a Hamiltonian tour for the given graph G, if possible. These questions turn out to be intractable!!!

Algorithmic questions related to Euler tours Hamiltonian tour Actually, it is not known how to determine in any reasonable amount of time whether a graph G has a Hamilton Tour, or how to find one. An Opportunity: You can earn $1,000,000 if you can give an algorithm that finds a Hamilton Tour (if one exists) in an arbitrary graph on n vertices that takes time O(nk) for constant k.

Light Switches A light bulb is connected to 3 switches in such a way that it lights up only when all the switches are in the proper position. But you don't know what the proper position of each switch is! What's the minimum number of single flips of a switch to guarantee that the light bulb turns on? 4 8 16 64 None of the above

Light Switches Configuration 1 if switch is UP, 0 if DOWN Connect configuration if off by one switch. Rephrasing the problem: Looking for Hamiltonian tour through graph.

Our Strategy Puzzle / Problem Model as a graph Choose vertex set & edge set … sometimes many possible options Use graph algorithms to solve puzzle / problem

DNA Reconstruction Problem Given collection of short DNA strings. Find longer DNA string that includes them all. Many possible formulations as a graph problem. Successful solution was a big step in Human Genome Project.

DNA Reconstruction: as a Hamiltonian tour Given collection of short DNA strings. S = { ATG, AGG, TGC, TCC, GTC, GGT, GCA, CAG } Find longer DNA string that includes them all. Vertex set: S, i.e. a vertex for each short DNA string Edge set: edge from v to w if the first two letters of w equal the last two letters of v ATG AGG TGC TCC GTC GGT GCA CAG

DNA Reconstruction: as a Hamiltonian tour Given collection of short DNA strings. S = { ATG, AGG, TGC, TCC, GTC, GGT, GCA, CAG } Find longer DNA string that includes them all. Vertex set: S, i.e. a vertex for each short DNA string Edge set: edge from v to w if the first two letters of w equal the last two letters of v ATG AGG TGC TCC GTC GGT GCA CAG What's a Hamiltonian tour?

DNA Reconstruction: as an Eulerian tour Given collection of short DNA strings. S = { ATG, AGG, TGC, TCC, GTC, GGT, GCA, CAG } Find longer DNA string that includes them all. Vertex set: All length-two strings that appear in a word in S Edge set: edge from ab to bc if abc is in S. AG GG CA AT TG GC TC GT CC What's an Eulerian tour?

Finding Eulerian tours Consider only undirected graphs. 1st goal: Determine whether a given undirected graph G has an Eulerian tour. 2nd goal: Actually find an Eulerian tour in an undirected graph G, when possible.

Finding Eulerian tours How many paths are there between vertex A and vertex I? None. Exactly one. Exactly two. More than two. None of the above.

Connectedness An undirected graph G is connected if for any ordered pair of vertices (v,w) there is a path from v to w. Connected Not connected

Connectedness An undirected graph G is connected if for any ordered pair of vertices (v,w) there is a path from v to w. An undirected graph G is disconnected if for any ordered pair of vertices (v,w) there is no path from v to w. there is an ordered pair of vertices (v,w) with a path from v to w. there is an ordered pair of vertices (v,w) with no path from v to w. for every ordered pair of vertices (v,w) there is a path from v to w. None of the above.

Connected Components Disconnected graphs can be broken up into pieces where each is connected. Each connected piece of the graph is a connected component.

Finding Eulerian tours Let G = (V,E) be an undirected connected graph with n vertices. 1st goal: Determine whether G has an Eulerian tour. 2nd goal: If yes, find the tour itself.

Finding Eulerian tours Observation: If v is an intermediate* vertex on a path p, then p must enter v the same number of times it leaves v. * not the start vertex, not the end vertex. v

Finding Eulerian tours Observation: If v is an intermediate* vertex on a path p, then p must enter v the same number of times it leaves v. If p is an Eulerian tour, it contains all edges. So, each edge incident with v is in p. * not the start vertex, not the end vertex. v

Recall: Degree The degree of a vertex in an undirected graph is the total number of edges incident with it, except that a loop contributes twice. Rosen p. 652

Finding Eulerian tours Observation: If v is an intermediate* vertex on a path p, then p must enter v the same number of times it leaves v. If p is Eulerian tour, it has all edges: each edge incident with v is in p. * not the start vertex, not the end vertex. There are degree(v) many of these v

Finding Eulerian tours Observation: If v is an intermediate* vertex on a path p, then p must enter v the same number of times it leaves v. If p is Eulerian tour, it has all edges: each edge incident with v is in p. Half these edges are entering v, half are leaving v … degree(v) is even! There are degree(v) many of these

Finding Eulerian tours (Summary of) Observation: In an Eulerian tour, any intermediate vertex has even degree. If tour is a circuit, all vertices are intermediate so all have even degree. If tour is not a circuit, starting and ending vertices will have odd degree.

Finding Eulerian tours Theorem: If G has an Eulerian tour, G has at most two odd degree vertices. Which of the following statements is the converse to the theorem? If G does not have an Eulerian tour, then G does not have at most two odd degree vertices. If G has at most two odd degree vertices, then G has an Eulerian tour. If G does not have at most two odd degree vertices, then G does not have an Eulerian tour. More than one of the above. None of the above.

Finding Eulerian tours Theorem: If G has an Eulerian tour, G has at most two odd degree vertices. Question: is the converse also true? i.e If G has at most two odd degree vertices, then must G have an Eulerian tour?

Finding Eulerian tours Theorem: If G has an Eulerian tour, G has at most two odd degree vertices. Question: is the converse also true? i.e If G has at most two odd degree vertices, then must G have an Eulerian tour? Answer: give algorithm to build the Eulerian tour! We'll develop some more graph theory notions along the way.

Finding Eulerian tours

Finding Eulerian tours Start at 4. Where should we go next? Along edge to 2. Along edge to 3. Along edge to 5. Any of the above.

Bridges A bridge is an edge, which, if removed, would cause G to be disconnected. A D B E C Which of the edges in this graph are bridges? All of them. D, E A, B, C C, D None of the above.

Bridges A bridge is an edge, which, if removed, would cause G to be disconnected. Connection with Eulerian tours: In an Eulerian tour, we have to visit every edge on one side of the bridge before we cross it (because there's no coming back). ** Do you see divide & conquer in here?

Eulerian Tours HOW Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident on v Cross any edge incident on v that is not a bridge and delete it Else, Cross the only edge available from v and delete v.

Eulerian Tours WHY Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident on v Cross any edge incident on v that is not a bridge and delete it Else, Cross the only edge available from v and delete v. Will there always be such an edge? Will go through each edge at most once, so if while loop iterates |E| times, get an Eulerian tour.

Fleury’s algorithm correctness. invariants If v has odd degree then there is exactly one other vertex w of odd degree. If v has even degree, all other vertices have even degree. 2. G stays connected (deleting edges as we use them.)

Fleury’s algorithm correctness. invariants If v has odd degree then there is exactly one other vertex w of odd degree. If v has even degree, all other vertices have even degree. Proof: Base Case: since G has at most 2 odd degree vertices and we pick one as v, there must only be one other. Induction Hypothesis: Suppose after k iterations, the current vertex has odd degree and one other vertex has odd degree or all vertices have even degree. Call the current vertex v. Then we must cross an edge to get to a neighbor of v call it y. If y is not w then y has even degree and when you delete the edge (v,y), v now has even degree and y has odd degree and y is the new current vertex. if y is w then when you delete the edge (v,y) v has even degree and w has even degree so all vertices have even degree.

Fleury’s algorithm correctness. invariants 2. G stays connected (deleting edges as we use them.) Proof: Base Case: G starts as being connected. Inductive hypothesis: Assume after k iterations, G is still connected. If we remove the current vertex v and all the edges from v, the graph could split into connected components C_1,…C_m

Fleury’s algorithm correctness. invariants 2. G stays connected (deleting edges as we use them.) If we remove the current vertex v and all the edges from v, the graph could split into connected components C_1,…C_m

Fleury’s algorithm correctness. invariants 2. G stays connected (deleting edges as we use them.) If we remove the current vertex v and all the edges from v, the graph could split into connected components C_1,…C_m Case 1: There is a single component, m=1 and there is only one edge from v. Then G stays connected because it becomes C_1 and we delete v after the one edge is removed.

Fleury’s algorithm correctness. invariants 2. G stays connected (deleting edges as we use them.) Case 2: There is a component C_i with at least 2 edges from v. Then neither is a bridge and Fleury’s algorithm can take any of these edges and the graph will stay connected.

Fleury’s algorithm correctness. invariants 2. G stays connected (deleting edges as we use them.) Case 3: There are at least 2 components and all have single edges from v. THIS CASE CANNOT HAPPEN!!!!!!!!

Fleury’s algorithm correctness. invariants 2. G stays connected (deleting edges as we use them.) Case 3: There are at least 2 components and all have single edges from v. THIS CASE CANNOT HAPPEN!!!!!!!! w would be in at most one of the at least two components. So pick a component C_i so that there is one edge from v to C_i which has no odd degree vertices. Consider the subgraph consisting just of v and C_i. This graph has only one odd degree vertex. But this contradicts the handshake lemma!!!!!

Fleury’s algorithm correctness. invariants Conclusion: Throughout the algorithm, the graph stays connected. In particular, we end when there are no edges leaving our current vertex v, which means there cannot be any other vertices or the graph would be disconnected. So we have deleted all edges, and hence gone over each edge exactly once. Bridge! v

Eulerian Tours WHY Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident with v Cross any edge incident with v that is not a bridge Else, cross the only edge available from v. Delete the edge just crossed from G, update v. Will there always be such an edge? Bridge! v

Eulerian Tours WHY Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident with v Cross any edge incident with v that is not a bridge Else, cross the only edge available from v. Delete the edge just crossed from G, update v. Will there always be such an edge? Bridge! v

Eulerian Tours WHY Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident with v Cross any edge incident with v that is not a bridge Else, cross the only edge available from v. Delete the edge just crossed from G, update v. Will there always be such an edge? v Bridge!

Eulerian Tours WHY Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident with v Cross any edge incident with v that is not a bridge Else, cross the only edge available from v. Delete the edge just crossed from G, update v. Will there always be such an edge? v

Eulerian Tours WHY Fleury's Algorithm Check that G has at most 2 odd degree vertices. Start at vertex v, an odd degree vertex if possible. While there are still edges in G, If there is more than one edge incident with v Cross any edge incident with v that is not a bridge Else, cross the only edge available from v. Delete the edge just crossed from G, update v. Will there always be such an edge? etc. v

Seven Bridges of Konigsberg 3 3 5 3 Is there a path where each edge occurs exactly once? Eulerian tour No! Rosen p. 693

Seven Bridges of Konigsberg redux 3 3 5 5 2 4 3 3 4 4 4 3 3 3 3 5 5 2 4 2 Which of these puzzles can you draw without lifting your pencil off the paper? A. No B. No C. No D. Yes

Eulerian Tours: recap Consider only undirected graphs. 1st goal: Determine whether a given undirected graph G has an Eulerian tour. G has an Eulerian tour if and only if G has at most 2 odd-degree vertices. 2nd goal: Actually find an Eulerian tour in an undirected graph G, when possible. Fleury's Algorithm: don't burn your bridges.

Eulerian Tours: recap Number of odd degree vertices 1 2 >2, odd 1 2 >2, odd >2, even Is such a graph possible? yes no Is an Eulerian tour possible? yes, an Eulerian circuit