2.1k likes | 5.72k Views
Hamiltonian Cycle. Penka Borukova. Student at Telerik Academy. Table of Contents. History Hamiltonian Cycle Hamiltonian Graph Travelling salesman. History. History. Invented by William Rowan Hamilton in 1859 Icosian game = Hamilton’s puzzle
E N D
Hamiltonian Cycle PenkaBorukova Student at Telerik Academy
Table of Contents • History • Hamiltonian Cycle • Hamiltonian Graph • Travelling salesman
History • Invented by William Rowan Hamilton in 1859 • Icosian game = Hamilton’s puzzle • Finding Hamiltonian cycle in dodecahedron
Hamiltonian Cycle • Hamiltonian path is a path in a graph that visits each vertex exactly once • Hamiltonian cycle is a cycle in a graph that visits each vertex exactly once • Hamiltonian path/cycle problem – determining if Hamiltonian path/cycle exists • Both are NP-complete
Hamiltonian Graph • Hamiltonian graph is a graph that has Hamiltonian cycle • Complexity for finding Hamiltonian cycle – O(n!) • Works for less than 50 vertices
Hamiltonian Graph (2) • Possibility for Hamiltonian graph • Complete graph – 100% • Almost complete graph – high possibility • Less edges => less possibility
Hamiltonian Graph (3) • Examples • Complete graph • Cycle graph • Platonic solid • Prism • Maximal planar graph • Tournament – odd number Hamiltonianpaths
Let’s find Hamiltonian cycle Herschel graph
Hamiltonian Graph (4) public static void HamiltonianCycle(Node node, int level, List<Node> pathSoFar) { if (level == nodesCount) { foreach(Node neighbor in node.Neighbors) { if (neighbor == startNode) { List<Node> p = new List<Node>(); p.AddRange(pathSoFar); p.Add(startNode); cycles.Add(p); } } return; }
Hamiltonian Graph (5) for (inti = 0; i < node.Neighbors.Count; i++) { if (!node.Neighbors[i].Visited) { node.Neighbors[i].Visited = true; pathSoFar.Add(node.Neighbors[i]); HamiltonianCycle(node.Neighbors[i], level + 1, pathSoFar); pathSoFar.Remove(node.Neighbors[i]); node.Neighbors[i].Visited = false; } } }
Travelling Salesman • Finding Hamiltonian cycle with minimal cost • Also NP-complete • Heuristics • Greedy • Pairwise exchange • Randomized improvement
Hamiltonian Cycle http://algoacademy.telerik.com
Resources • Nakov’s book: Programming = ++Algorithms; • http://en.wikipedia.org/wiki/Hamiltonian_path • http://neohumanism.org/h/ha/hamiltonian_path.html • http://en.wikipedia.org/wiki/Travelling_salesman_problem • http://en.wikipedia.org/wiki/Herschel_graph
Free Trainings @ Telerik Academy • “C# Programming @ Telerik Academy • csharpfundamentals.telerik.com • Telerik Software Academy • academy.telerik.com • Telerik Academy @ Facebook • facebook.com/TelerikAcademy • Telerik Software Academy Forums • forums.academy.telerik.com