Eulerian Tours By Shaylan Lalloo. What is an Eulerian Tour? A path that uses every edge exactly once is called an eularian tour. Furthermore, a path that.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Discrete Maths Chapter 5: Route Inspection Lesson 1: Chinese Postman.
Graph-02.
Routing in a Parallel Computer. A network of processors is represented by graph G=(V,E), where |V| = N. Each processor has unique ID between 1 and N.
Depth-First Search1 Part-H2 Depth-First Search DB A C E.
Graph Theory: Euler Circuits Christina Mende Math 480 April 15, 2013.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Excursions in Modern Mathematics(Tannenbaum) and Thinking Mathematically (Blitzer)
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Tyler Robison Summer
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Dan Grossman Spring 2010.
What is the first line of the proof? a). Assume G has an Eulerian circuit. b). Assume every vertex has even degree. c). Let v be any vertex in G. d). Let.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
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.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
The Travelling Salesman Algorithm A Salesman has to visit lots of different stores and return to the starting base On a graph this means visiting every.
Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Eulerian Tour What is a Eulerian tour and how to find one.
Search Related Algorithms. Graph Code Adjacency List Representation:
The Traveling Salesman Problem Approximation
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we can find a path that goes over all.
CSE, IIT KGP Euler Graphs and Digraphs. CSE, IIT KGP Euler Circuit We use the term circuit as another name for closed trail.We use the term circuit as.
Euler and Hamilton Paths. Euler Paths and Circuits The Seven bridges of Königsberg a b c d A B C D.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Made up of vertices and arcs Digraph (directed graph) –All arcs have arrows that give direction –You can only traverse the graph in the direction.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
1.5 Graph Theory. Graph Theory The Branch of mathematics in which graphs and networks are used to solve problems.
Week 12 - Wednesday.  What did we talk about last time?  Matching  Stable marriage  Started Euler paths.
CIRCUITS, PATHS, AND SCHEDULES Euler and Königsberg.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
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.
COSC 2007 Data Structures II
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.
Topological Sort: Definition
Chapter 6: Graphs 6.1 Euler Circuits
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
Review Euler Graph Theory: DEFINITION: A NETWORK IS A FIGURE MADE UP OF POINTS (VERTICES) CONNECTED BY NON-INTERSECTING CURVES (ARCS). DEFINITION: A VERTEX.
Graphs Upon completion you will be able to:
Introduction to Graph Theory
EULER PATHS & CHINESE POSTMAN SOL: DM.2 CLASSWORK WORKSHEET HOMEWORK (DAY 59) WORKSHEET.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Lecture 9: Graphs & Graph Models. Definition of a Graph edge vertex cycle path.
Hamilton Paths and Circuits 1 Click to Start 2 3 Start End.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Graph Representations adjacency matrix node list edge list ADF CH BEG A B C D E F G H A B C D
Data Structures Graphs - Terminology
Eulerian tours Miles Jones MTThF 8:30-9:50am CSE 4140 August 15, 2016.
12. Graphs and Trees 2 Summary
CS120 Graphs.
More Graph Algorithms.
Graphs Representation, BFS, DFS
Genome Assembly.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Search Related Algorithms
Depth-First Search Graph Traversals Depth-First Search DFS.
A path that uses every vertex of the graph exactly once.
Graphs.
Route Inspection Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we introduce a vertex.
Cheapest-Link Algorithm/Sorted Edges (Unit 10) SOL: DM.2
Euler and Hamilton Paths
Hamilton Paths and Circuits
Graph Theory: Euler Graphs and Digraphs
Presentation transcript:

Eulerian Tours By Shaylan Lalloo

What is an Eulerian Tour? A path that uses every edge exactly once is called an eularian tour. Furthermore, a path that starts and ends at the same vertex and is an eularian tour but is called an eulerian circuit.

When does there exist an eulerian tour? An eulerian tour exists when the degree of all vertices except for exactly 2 are even and the graph is connected An eularian circuit exists when the degree of all the vertices are even and the graph is connected

Proof This can be seen from the fact that every time you enter a vertex in a path, you must be able to leave it unless you are at the beginning or end of the path so this adds 2 to the degree of the vertices on the path not being the starting or ending vertex.

Algorithm for finding eulerian tours Find the starting node. Then recurse using the following rule – If a node has no neighbours, push it onto the answer vector – If a node has a neighbour, throw the neighbours onto a stack and process them – Processing a node consists of deleting the edge between the current node and neighbour, then recursing on the neighbour. Once that is done, pushing the current node onto the answer vector

Code(Variables) vector mygraph[10]; int n; vector mystack; vector myans; int curpos = 0;

Reading Inputs ifstream fin ("myin.txt"); fin >> n; for (int i = 0; i < n; ++i){ int f, t; fin >> f >> t; mygraph[f - 1].push_back(t - 1); mygraph[t - 1].push_back(f - 1); } for (int i = 0; i < 7; ++i){ sort(mygraph[i].begin(), mygraph[i].end(), cmp); }

Recursion algorithm but using stack mystack.push_back(0); while (!mystack.empty()){ curpos = mystack.back(); if (mygraph[curpos].size() == 0){ myans.push_back(curpos); mystack.pop_back(); } else { int neigh = mygraph[curpos].back(); mystack.push_back(neigh); mygraph[curpos].pop_back(); for (int i = 0; i < mygraph[neigh].size(); ++i){ if (mygraph[neigh][i] == curpos){ mygraph[neigh].erase(mygraph[neigh].begin() + i); break; }

Outputting result cout << "MYANS: "; for (int i = 0; i < myans.size(); ++i){ cout << myans[i] + 1 << " "; } cout << endl;

Pseudocode # circuit is a global array find_euler_circuit circuitpos = 0 find_circuit(node 1) # nextnode and visited is a local array # the path will be found in reverse order find_circuit(node i) if node i has no neighbors then circuit(circuitpos) = node i circuitpos = circuitpos + 1 else while (node i has neighbors) pick a random neighbor node j of node i delete_edges (node j, node i) find_circuit (node j) circuit(circuitpos) = node i circuitpos = circuitpos + 1

Visual representation of algorithm

Stack: Location: 1 Circuit:

Stack: 1 Location: 4 Circuit:

Stack: 1 4 Location: 2 Circuit:

Stack: Location: 5 Circuit:

Stack: Location: 1 Circuit:

Stack: Location: 5 Circuit: 1

Stack: Location: 6 Circuit: 1

Stack: Location: 2 Circuit: 1

Stack: Location: 7 Circuit: 1

Stack: Location: 3 Circuit: 1

Stack: Location: 4 Circuit: 1

Stack: Location: 6 Circuit: 1

Stack: Location: 7 Circuit: 1

Stack: Location: 5 Circuit: 1

Stack: Location: Circuit:

Problem involving Eulerian Tour USACO Riding Fences Farmer John owns a large number of fences that must be repaired annually. He traverses the fences by riding a horse along each and every one of them (and nowhere else) and fixing the broken parts. Farmer John is as lazy as the next farmer and hates to ride the same fence twice. Your program must read in a description of a network of fences and tell Farmer John a path to traverse each fence length exactly once, if possible. Farmer J can, if he wishes, start and finish at any fence intersection. Every fence connects two fence intersections, which are numbered inclusively from 1 through 500 (though some farms have far fewer than 500 intersections). Any number of fences (>=1) can meet at a fence intersection. It is always possible to ride from any fence to any other fence (i.e., all fences are "connected"). Your program must output the path of intersections that, if interpreted as a base 500 number, would have the smallest magnitude. There will always be at least one solution for each set of input data supplied to your program for testing.