1 / 20

Hamiltonian Cycle

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

spence
Download Presentation

Hamiltonian Cycle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hamiltonian Cycle PenkaBorukova Student at Telerik Academy

  2. Table of Contents • History • Hamiltonian Cycle • Hamiltonian Graph • Travelling salesman

  3. History

  4. History • Invented by William Rowan Hamilton in 1859 • Icosian game = Hamilton’s puzzle • Finding Hamiltonian cycle in dodecahedron

  5. Hamiltonian Cycle Definition

  6. 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

  7. Hamiltonian Graph Definition

  8. Hamiltonian Graph • Hamiltonian graph is a graph that has Hamiltonian cycle • Complexity for finding Hamiltonian cycle – O(n!) • Works for less than 50 vertices

  9. Hamiltonian Graph (2) • Possibility for Hamiltonian graph • Complete graph – 100% • Almost complete graph – high possibility • Less edges => less possibility

  10. Hamiltonian Graph (3) • Examples • Complete graph • Cycle graph • Platonic solid • Prism • Maximal planar graph • Tournament – odd number Hamiltonianpaths

  11. Let’s find Hamiltonian cycle Herschel graph

  12. 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; }

  13. 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; } } }

  14. Live Demo

  15. Travelling Salesman Problem

  16. Travelling Salesman • Finding Hamiltonian cycle with minimal cost • Also NP-complete • Heuristics • Greedy • Pairwise exchange • Randomized improvement

  17. Live Demo

  18. Hamiltonian Cycle http://algoacademy.telerik.com

  19. 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

  20. 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

More Related