SlideShare a Scribd company logo
Graphs: Cycles
Tecniche di Programmazione – A.A. 2012/2013
Summary
A.A. 2012/2013Tecniche di programmazione2
 Definitions
 Algorithms
Definitions
Graphs: Cycles
Cycle
A.A. 2012/2013Tecniche di programmazione4
 A cycle of a graph, sometimes also called a circuit, is a
subset of the edge set of that forms a path such that the
first node of the path corresponds to the last.
Hamiltonian cycle
A.A. 2012/2013Tecniche di programmazione5
 A cycle that uses each graph vertex of a graph exactly
once is called a Hamiltonian cycle.
Hamiltonian path
A.A. 2012/2013Tecniche di programmazione6
 A Hamiltonian path, also called a Hamilton path, is a path
between two vertices of a graph that visits each vertex
exactly once.
 N.B. does not need to return to the starting point
Eulerian Path and Cycle
A.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 each
graph edge in the original graph exactly once.
 An Eulerian cycle, also called an Eulerian circuit, Euler
circuit, Eulerian tour, or Euler tour, is a trail which starts
and ends at the same graph vertex.
Theorem
A.A. 2012/2013Tecniche di programmazione8
 A connected graph has an Eulerian cycle if and only if it
all vertices have even degree.
 A connected graph has an Eulerian path if and only if it
has at most two graph vertices of odd degree.
 …easy to check!
Königsberg Bridges
Weighted vs. Unweighted
A.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)
Algorithms
Graphs: Cycles
Eulerian cycles: Hierholzer's algorithm (1)
A.A. 2012/2013Tecniche di programmazione11
 Choose any starting vertex v, and follow a trail of edges
from 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 the
trail enters another vertex w there must be an unused edge
leaving w.
 The tour formed in this way is a closed tour, but may not
cover all the vertices and edges of the initial graph.
Eulerian cycles: Hierholzer's algorithm (2)
A.A. 2012/2013Tecniche di programmazione12
 As long as there exists a vertex v that belongs to the
current tour but that has adjacent edges not part of the
tour, start another trail from v, following unused
edges until returning to v, and join the tour formed in
this 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 JGraphT
A.A. 2012/2013Tecniche di programmazione16
Hamiltonian Cycles
A.A. 2012/2013Tecniche di programmazione17
 There are theorems to identify whether a graph is
Hamiltonian (i.e., whether it contains at least one
Hamiltonian Cycle)
 Finding such a cycle has no known efficient solution, in
the general case
 Example: the Traveling Salesman Problem (TSP)
A.A. 2012/2013Tecniche di programmazione18
Weighted or
unweighted
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
Resources
A.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’uso
A.A. 2012/2013Tecniche di programmazione22
 Queste diapositive sono distribuite con licenza Creative Commons
“Attribuzione - Non commerciale - Condividi allo stesso modo (CC
BY-NC-SA)”
 Sei libero:
 di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico,
rappresentare, eseguire e recitare quest'opera
 di modificare quest'opera
 Alle seguenti condizioni:
 Attribuzione — Devi attribuire la paternità dell'opera agli autori originali
e in modo tale da non suggerire che essi avallino te o il modo in cui tu
usi l'opera.
 Non commerciale — Non puoi usare quest'opera per fini commerciali.
 Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se la
usi per crearne un'altra, puoi distribuire l'opera risultante solo con una
licenza identica o equivalente a questa.
 http://creativecommons.org/licenses/by-nc-sa/3.0/

More Related Content

PDF
17444 power electronics
soni_nits
 
PDF
17414 industrial instrumentation
soni_nits
 
PDF
Me2305 APPLIED HYDRAULICS AND PNEUMATICS
BIBIN CHIDAMBARANATHAN
 
PPT
Semet Cec05
ysemet
 
PPT
Lecture 12
Faisal Mehmood
 
PDF
Hamilton circuits7 19and22
shivam19942
 
PDF
Ambient intelligence - an overview
Fulvio Corno
 
17444 power electronics
soni_nits
 
17414 industrial instrumentation
soni_nits
 
Me2305 APPLIED HYDRAULICS AND PNEUMATICS
BIBIN CHIDAMBARANATHAN
 
Semet Cec05
ysemet
 
Lecture 12
Faisal Mehmood
 
Hamilton circuits7 19and22
shivam19942
 
Ambient intelligence - an overview
Fulvio Corno
 

Viewers also liked (16)

PDF
La shell Bash - Comandi base - Comandi avanzati - Espressioni regolari
Fulvio Corno
 
PDF
Introduction to Graphs
Fulvio Corno
 
PDF
Tecnologie e applicazioni domotiche: potenzialità ed approcci industriali a c...
Fulvio Corno
 
PDF
Approcci ed applicazioni per l’Ambient Intelligence
Fulvio Corno
 
PDF
La percezione sensoriale
Fulvio Corno
 
PDF
Tecnologie per la disabilita' nella formazione ingegneristica di base
Fulvio Corno
 
PDF
Primi passi - VirtualBox - Installazione Ubuntu 12.04 LTS - Shell
Fulvio Corno
 
PDF
AmI 2015 - Course Introduction
Fulvio Corno
 
PDF
Introduction to JDBC and database access in web applications
Fulvio Corno
 
PDF
Moduli del kernel - Boot del sistema
Fulvio Corno
 
PDF
Introduzione ai Web Information Systems
Fulvio Corno
 
PDF
Programming with JavaFX
Fulvio Corno
 
PDF
Java collections framework
Fulvio Corno
 
PDF
Introduction to JavaFX
Fulvio Corno
 
PDF
Programmazione in C (corso 12BHD Informatica)
Fulvio Corno
 
PDF
Esercizi di programmazione in C (v. 2.01)
Fulvio Corno
 
La shell Bash - Comandi base - Comandi avanzati - Espressioni regolari
Fulvio Corno
 
Introduction to Graphs
Fulvio Corno
 
Tecnologie e applicazioni domotiche: potenzialità ed approcci industriali a c...
Fulvio Corno
 
Approcci ed applicazioni per l’Ambient Intelligence
Fulvio Corno
 
La percezione sensoriale
Fulvio Corno
 
Tecnologie per la disabilita' nella formazione ingegneristica di base
Fulvio Corno
 
Primi passi - VirtualBox - Installazione Ubuntu 12.04 LTS - Shell
Fulvio Corno
 
AmI 2015 - Course Introduction
Fulvio Corno
 
Introduction to JDBC and database access in web applications
Fulvio Corno
 
Moduli del kernel - Boot del sistema
Fulvio Corno
 
Introduzione ai Web Information Systems
Fulvio Corno
 
Programming with JavaFX
Fulvio Corno
 
Java collections framework
Fulvio Corno
 
Introduction to JavaFX
Fulvio Corno
 
Programmazione in C (corso 12BHD Informatica)
Fulvio Corno
 
Esercizi di programmazione in C (v. 2.01)
Fulvio Corno
 
Ad

Similar to Graphs: Cycles (20)

PPTX
ch10.5.pptx
GauravGautam216125
 
PDF
Representing and visiting graphs
Fulvio Corno
 
PDF
Graphs: Finding shortest paths
Fulvio Corno
 
PPTX
5. Signal flow graph, Mason’s gain formula.pptx
AMSuryawanshi
 
PDF
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
murniatimurni9
 
PPTX
graph theory presentation master MMR.pptx
radia raguigue
 
DOCX
Graphs and eularian circuit & path with c++ program
Muhammad Danish Badar
 
PPTX
VANU no sql ppt.pptx
MJeyavarthini
 
PPTX
Vanmathy no sql
PriyadharshiniVS
 
PPTX
CONTOUR-INTEGRATION-VIVIAN-A.-LAGING-.pptx
JoelynRubio1
 
PDF
An introduction to the graph theory in discrete mathematics
hassanbokhari14
 
PPS
nossi ch 6
lesaturner
 
PPTX
Data structures and algorithms lab8
Bianca Teşilă
 
PPTX
Simplex algorithm
Khwaja Bilal Hassan
 
PPTX
Simplex Algorithm
Aizaz Ahmad
 
DOCX
Umap traversabilityin graph
Kaya Ota
 
PPTX
Na ch02
mboland7777777
 
PPTX
Introduction to Graph Theory
Premsankar Chakkingal
 
PPTX
Graph
Usha Mahalingam
 
ch10.5.pptx
GauravGautam216125
 
Representing and visiting graphs
Fulvio Corno
 
Graphs: Finding shortest paths
Fulvio Corno
 
5. Signal flow graph, Mason’s gain formula.pptx
AMSuryawanshi
 
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
murniatimurni9
 
graph theory presentation master MMR.pptx
radia raguigue
 
Graphs and eularian circuit & path with c++ program
Muhammad Danish Badar
 
VANU no sql ppt.pptx
MJeyavarthini
 
Vanmathy no sql
PriyadharshiniVS
 
CONTOUR-INTEGRATION-VIVIAN-A.-LAGING-.pptx
JoelynRubio1
 
An introduction to the graph theory in discrete mathematics
hassanbokhari14
 
nossi ch 6
lesaturner
 
Data structures and algorithms lab8
Bianca Teşilă
 
Simplex algorithm
Khwaja Bilal Hassan
 
Simplex Algorithm
Aizaz Ahmad
 
Umap traversabilityin graph
Kaya Ota
 
Introduction to Graph Theory
Premsankar Chakkingal
 
Ad

Recently uploaded (20)

PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Basics and rules of probability with real-life uses
ravatkaran694
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
How to Apply for a Job From Odoo 18 Website
Celine George
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Virus sequence retrieval from NCBI database
yamunaK13
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 

Graphs: Cycles

  • 1. Graphs: Cycles Tecniche di Programmazione – A.A. 2012/2013
  • 2. Summary A.A. 2012/2013Tecniche di programmazione2  Definitions  Algorithms
  • 4. Cycle A.A. 2012/2013Tecniche di programmazione4  A cycle of a graph, sometimes also called a circuit, is a subset of the edge set of that forms a path such that the first node of the path corresponds to the last.
  • 5. Hamiltonian cycle A.A. 2012/2013Tecniche di programmazione5  A cycle that uses each graph vertex of a graph exactly once is called a Hamiltonian cycle.
  • 6. Hamiltonian path A.A. 2012/2013Tecniche di programmazione6  A Hamiltonian path, also called a Hamilton path, is a path between two vertices of a graph that visits each vertex exactly once.  N.B. does not need to return to the starting point
  • 7. Eulerian Path and Cycle A.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 each graph edge in the original graph exactly once.  An Eulerian cycle, also called an Eulerian circuit, Euler circuit, Eulerian tour, or Euler tour, is a trail which starts and ends at the same graph vertex.
  • 8. Theorem A.A. 2012/2013Tecniche di programmazione8  A connected graph has an Eulerian cycle if and only if it all vertices have even degree.  A connected graph has an Eulerian path if and only if it has at most two graph vertices of odd degree.  …easy to check! Königsberg Bridges
  • 9. Weighted vs. Unweighted A.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)
  • 11. Eulerian cycles: Hierholzer's algorithm (1) A.A. 2012/2013Tecniche di programmazione11  Choose any starting vertex v, and follow a trail of edges from 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 the trail enters another vertex w there must be an unused edge leaving w.  The tour formed in this way is a closed tour, but may not cover all the vertices and edges of the initial graph.
  • 12. Eulerian cycles: Hierholzer's algorithm (2) A.A. 2012/2013Tecniche di programmazione12  As long as there exists a vertex v that belongs to the current tour but that has adjacent edges not part of the tour, start another trail from v, following unused edges until returning to v, and join the tour formed in this way to the previous tour.
  • 13. A.A. 2012/2013Tecniche di programmazione13
  • 14. A.A. 2012/2013Tecniche di programmazione14
  • 15. A.A. 2012/2013Tecniche di programmazione15
  • 16. Eulerian Circuits in JGraphT A.A. 2012/2013Tecniche di programmazione16
  • 17. Hamiltonian Cycles A.A. 2012/2013Tecniche di programmazione17  There are theorems to identify whether a graph is Hamiltonian (i.e., whether it contains at least one Hamiltonian Cycle)  Finding such a cycle has no known efficient solution, in the general case  Example: the Traveling Salesman Problem (TSP)
  • 18. A.A. 2012/2013Tecniche di programmazione18 Weighted or unweighted
  • 19. 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)
  • 20. A.A. 2012/2013Tecniche di programmazione20
  • 21. Resources A.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/
  • 22. Licenza d’uso A.A. 2012/2013Tecniche di programmazione22  Queste diapositive sono distribuite con licenza Creative Commons “Attribuzione - Non commerciale - Condividi allo stesso modo (CC BY-NC-SA)”  Sei libero:  di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico, rappresentare, eseguire e recitare quest'opera  di modificare quest'opera  Alle seguenti condizioni:  Attribuzione — Devi attribuire la paternità dell'opera agli autori originali e in modo tale da non suggerire che essi avallino te o il modo in cui tu usi l'opera.  Non commerciale — Non puoi usare quest'opera per fini commerciali.  Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una licenza identica o equivalente a questa.  http://creativecommons.org/licenses/by-nc-sa/3.0/