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

Viewers also liked

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

Viewers also liked (16)

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

Similar to Graphs: Cycles

ch10.5.pptx
ch10.5.pptxch10.5.pptx
ch10.5.pptx
GauravGautam216125
 
Representing and visiting graphs
Representing and visiting graphsRepresenting and visiting graphs
Representing and visiting graphs
Fulvio Corno
 
Graphs: Finding shortest paths
Graphs: Finding shortest pathsGraphs: Finding shortest paths
Graphs: Finding shortest paths
Fulvio Corno
 
5. Signal flow graph, Mason’s gain formula.pptx
5. Signal flow graph, Mason’s gain formula.pptx5. Signal flow graph, Mason’s gain formula.pptx
5. Signal flow graph, Mason’s gain formula.pptx
AMSuryawanshi
 
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdfISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
murniatimurni9
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
Muhammad Danish Badar
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
PriyadharshiniVS
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
MJeyavarthini
 
nossi ch 6
nossi ch 6nossi ch 6
nossi ch 6
lesaturner
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8Bianca Teşilă
 
Graph ds
Graph dsGraph ds
Simplex algorithm
Simplex algorithmSimplex algorithm
Simplex algorithm
Khwaja Bilal Hassan
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
Aizaz Ahmad
 
Umap traversabilityin graph
Umap traversabilityin graphUmap traversabilityin graph
Umap traversabilityin graphKaya Ota
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
Premsankar Chakkingal
 
Graph
GraphGraph
AGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHM
AGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHMAGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHM
AGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHM
ijseajournal
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
B.Kirron Reddi
 

Similar to Graphs: Cycles (20)

ch10.5.pptx
ch10.5.pptxch10.5.pptx
ch10.5.pptx
 
Representing and visiting graphs
Representing and visiting graphsRepresenting and visiting graphs
Representing and visiting graphs
 
Graphs: Finding shortest paths
Graphs: Finding shortest pathsGraphs: Finding shortest paths
Graphs: Finding shortest paths
 
5. Signal flow graph, Mason’s gain formula.pptx
5. Signal flow graph, Mason’s gain formula.pptx5. Signal flow graph, Mason’s gain formula.pptx
5. Signal flow graph, Mason’s gain formula.pptx
 
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdfISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
ISOMORFISME, CONNECTIVITY EULER HAMILTON.pdf
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
 
Advance analysis of algo
Advance analysis of algoAdvance analysis of algo
Advance analysis of algo
 
nossi ch 6
nossi ch 6nossi ch 6
nossi ch 6
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8
 
Graph ds
Graph dsGraph ds
Graph ds
 
Simplex algorithm
Simplex algorithmSimplex algorithm
Simplex algorithm
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
 
Umap traversabilityin graph
Umap traversabilityin graphUmap traversabilityin graph
Umap traversabilityin graph
 
Na ch02
Na ch02Na ch02
Na ch02
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Graph
GraphGraph
Graph
 
AGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHM
AGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHMAGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHM
AGV PATH PLANNING BASED ON SMOOTHING A* ALGORITHM
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 

Recently uploaded

Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 

Recently uploaded (20)

Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 

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/