# Dawn J' Lawrie - PowerPoint PPT Presentation

Loading...

PPT – Dawn J' Lawrie PowerPoint presentation | free to view - id: 164f44-ZDc1Z

The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

## Dawn J' Lawrie

Description:

### Euler path. Classic problem studied by Leonhard Euler and presented to Russian Academy in ... A graph has a Euler tour if and only if it is connected and all ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 18
Provided by: dawnjl
Category:
User Comments (0)
Transcript and Presenter's Notes

Title: Dawn J' Lawrie

1
Announcements
• Programming Assignment 3
• Code due tonight at midnight
• Print out and Analysis due Friday beginning of
class
• Today's Office Hours
• 11-12 and 2-3 PM

2
Nontrivial Graph-Processing
• Lecture 17

3
Simple Path
• What is a simple path?
• Given what we have studied so far, can we answer
the question
• Does a simple path exist between v and w?

4
Find a Specific Simple Path
• Use Depth-First-Search
• Solve the recursive problem
• Assume I know a path from v to t, is there a path
from t to w?

0
6
1
2
3
4
5
5
Simple path search
• template ltclass GraphTypegt
• class SPath
• private
• const GraphType graph
• vector ltboolgt visited
• vector ltintgt path
• int length
• bool found

6
Simple path search
• bool searchR(int v, int w, int depth)
• if (v w) // base case
• pathdepth v
• length depth1
• return true
• visitedv true
• typename GraphadjIterator adj(graph, v)
• for (int t adj.beg() !adj.end() t
adj.nxt())
• if (!visitedt)
• if (searchR(t, w, depth1))
• pathdepth v
• return true
• return false

7
Simple path search
• public
• SPath(const Graph G, int v, int w)
• graph(G), visited(G.V(), false), path(G.V(),
-1),
• length(0)
• found searchR(v,w,0)
• bool exists() const
• return found
• void displayPath() const
• for (int i 0 i lt length i)
• if (i ! 0)
• cout ltlt " - "
• cout ltlt pathi
• cout ltlt endl

8
Hamiltonian Path
• Given two vertices, is there a simple path
connecting them that visits every vertex in the
graph exactly once?
• Hamiltonian Tour Is there a cycle that visits
every vertex in the graph exactly oncegt

9
Hamiltonian Path
• bool searchR(int v, int w, int depth)
• if (v w) // base case
• pathdepth v
• length depth1
• return true // remove
line
• return (length graph.V()) // new line
• visitedv true
• typename GraphadjIterator adj(graph, v)
• for (int t adj.beg() !adj.end() t
adj.nxt())
• if (!visitedt)
• if (searchR(t, w, depth1))
• pathdepth v
• return true
• visitedv false // new line
• return false

10
Euler path
• Classic problem studied by Leonhard Euler and
presented to Russian Academy in 1735

11
Euler path
• Is there a path connecting two given vertices
that used each edge in the graph exactly once?
• Not necessarily a simple path
• A graph has a Euler tour if and only if it is
connected and all its vertices are of even degree

12
Proof
• Must be connected
• By definition a tour is a path connecting each
pair of vertices
• Vertex v must be of even degree
• When we traverse the tour (starting from anywhere
else), we enter v on one edge and leave on a
different edge
• Number of edges incident on the vertex must be
twice the number of visits

13
Proof of converse
• Consider any connected graph that has more than
one edge, with all vertices of even degree
• Starting at any vertex v, we follow and remove
any edge
• Continue until arriving at a vertex that has no
more edges
• Process terminates
• Outcomes
• We must end up back a v because v is the only
vertex of odd degree

14
Converse Proof continued
• We may not have a full tour
• All the vertices in the group that remain have
even degree but may not be connected
• Each connected component is a Euler tour by
inductive hypothesis
• Consider these detours

15
Finding a Euler Path
• Cannot implement a direct recursive method
because it would be as slow as the algorithm for
finding Hamiltonian Path
• Is there a linear time solution?

0
6
1
2
3
4
5
16
Linear-time Euler path
• template ltclass Graphgt
• int EPathltGraphgttour(int v)
• bool finished false
• while (!finished)
• typename GraphadjInterator adj(graph, v)
• int w adj.beg()
• if (adj.end())
• finished true
• else
• pStack.push(v)
• graph.remove(Edge(v, w))
• v w
• return v

17
Linear-time Euler path
• template ltclass Graphgt
• void EPathltGraphgtshow()
• int curV v
• if (!found)
• return
• while(tour(curV) curV !pStack.empty())
• curV sStack.pop()
• cout ltlt "-" ltlt curV
• cout ltlt endl
About PowerShow.com