• Like
  • Save
Graphs: Cycles
Upcoming SlideShare
Loading in...5
×
 

Graphs: Cycles

on

  • 798 views

Graphs: Cycles

Graphs: Cycles

Teaching material for the course of "Tecniche di Programmazione" at Politecnico di Torino in year 2012/2013. More information: http://bit.ly/tecn-progr

Statistics

Views

Total Views
798
Views on SlideShare
798
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Graphs: Cycles Graphs: Cycles Presentation Transcript

    • Graphs: CyclesTecniche di Programmazione – A.A. 2012/2013
    • SummaryA.A. 2012/2013Tecniche di programmazione2 Definitions Algorithms
    • DefinitionsGraphs: Cycles
    • CycleA.A. 2012/2013Tecniche di programmazione4 A cycle of a graph, sometimes also called a circuit, is asubset of the edge set of that forms a path such that thefirst node of the path corresponds to the last.
    • Hamiltonian cycleA.A. 2012/2013Tecniche di programmazione5 A cycle that uses each graph vertex of a graph exactlyonce is called a Hamiltonian cycle.
    • Hamiltonian pathA.A. 2012/2013Tecniche di programmazione6 A Hamiltonian path, also called a Hamilton path, is a pathbetween two vertices of a graph that visits each vertexexactly once. N.B. does not need to return to the starting point
    • Eulerian Path and CycleA.A. 2012/2013Tecniche di programmazione7 An Eulerian path, also called an Euler chain, Euler trail,Euler walk, or "Eulerian" version of any of these variants,is a walk on the graph edges of a graph which uses eachgraph edge in the original graph exactly once. An Eulerian cycle, also called an Eulerian circuit, Eulercircuit, Eulerian tour, or Euler tour, is a trail which startsand ends at the same graph vertex.
    • TheoremA.A. 2012/2013Tecniche di programmazione8 A connected graph has an Eulerian cycle if and only if itall vertices have even degree. A connected graph has an Eulerian path if and only if ithas at most two graph vertices of odd degree. …easy to check!Königsberg Bridges
    • Weighted vs. UnweightedA.A. 2012/2013Tecniche di programmazione9 Classical versions defined on Unweighted graphs Unweighted: Does such a cycle exist? If yes, find at least one Optionally, find all of them Weighted Does such a cycle exist? Often, the graph is complete  If yes, find at least one If yes, find the best one (with minimum weight)
    • AlgorithmsGraphs: Cycles
    • Eulerian cycles: Hierholzers algorithm (1)A.A. 2012/2013Tecniche di programmazione11 Choose any starting vertex v, and follow a trail of edgesfrom that vertex until returning to v. It is not possible to get stuck at any vertex other than v,because the even degree of all vertices ensures that, when thetrail enters another vertex w there must be an unused edgeleaving w. The tour formed in this way is a closed tour, but may notcover all the vertices and edges of the initial graph.
    • Eulerian cycles: Hierholzers algorithm (2)A.A. 2012/2013Tecniche di programmazione12 As long as there exists a vertex v that belongs to thecurrent tour but that has adjacent edges not part of thetour, start another trail from v, following unusededges until returning to v, and join the tour formed inthis way to the previous tour.
    • A.A. 2012/2013Tecniche di programmazione13
    • A.A. 2012/2013Tecniche di programmazione14
    • A.A. 2012/2013Tecniche di programmazione15
    • Eulerian Circuits in JGraphTA.A. 2012/2013Tecniche di programmazione16
    • Hamiltonian CyclesA.A. 2012/2013Tecniche di programmazione17 There are theorems to identify whether a graph isHamiltonian (i.e., whether it contains at least oneHamiltonian Cycle) Finding such a cycle has no known efficient solution, inthe general case Example: the Traveling Salesman Problem (TSP)
    • A.A. 2012/2013Tecniche di programmazione18Weighted orunweighted
    • What about JGraphT ?A.A. 2012/2013Tecniche di programmazione19 org.jgrapht.alg.HamiltonianCycle static <V,E> java.util.List<V>getApproximateOptimalForCompleteGraph(SimpleWeightedGraph<V,E> g) But… g must be a complete graph g must satisfy the “triangle inequality”: d(x,y)+d(y,z)<d(x,z)
    • A.A. 2012/2013Tecniche di programmazione20
    • ResourcesA.A. 2012/2013Tecniche di programmazione21 http://mathworld.wolfram.com/ http://en.wikipedia.org/wiki/Euler_cycle Mircea MARIN, GraphTheory and Combinatorics,Lectures 9 and 10, http://web.info.uvt.ro/~mmarin/
    • Licenza d’usoA.A. 2012/2013Tecniche di programmazione22 Queste diapositive sono distribuite con licenza Creative Commons“Attribuzione - Non commerciale - Condividi allo stesso modo (CCBY-NC-SA)” Sei libero: di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico,rappresentare, eseguire e recitare questopera di modificare questopera Alle seguenti condizioni: Attribuzione — Devi attribuire la paternità dellopera agli autori originalie in modo tale da non suggerire che essi avallino te o il modo in cui tuusi lopera. Non commerciale — Non puoi usare questopera per fini commerciali. Condividi allo stesso modo — Se alteri o trasformi questopera, o se lausi per crearne unaltra, puoi distribuire lopera risultante solo con unalicenza identica o equivalente a questa. http://creativecommons.org/licenses/by-nc-sa/3.0/