Hamiltonian Cycle

download Hamiltonian Cycle

of 20

  • date post

  • Category


  • view

  • download


Embed Size (px)


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 - PowerPoint PPT Presentation

Transcript of Hamiltonian Cycle

Object-Oriented Programming - Defining Classes

Hamiltonian CyclePenka BorukovaStudent at Telerik Academy

Table of ContentsHistoryHamiltonian CycleHamiltonian GraphTravelling salesman2

*(c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*2##History

HistoryInvented by William Rowan Hamilton in 1859Icosian game = Hamiltons puzzleFinding Hamiltonian cycle in dodecahedron


Hamiltonian Cycle Definition

Hamiltonian CycleHamiltonian 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 existsBoth are NP-complete

6Hamiltonian Graph Definition

Hamiltonian GraphHamiltonian graph is a graph that has Hamiltonian cycleComplexity for finding Hamiltonian cycle O(n!)Works for less than 50 vertices8

Hamiltonian Graph (2)Possibility for Hamiltonian graphComplete graph 100%Almost complete graph high possibilityLess edges => less possibility

9Hamiltonian Graph (3)ExamplesComplete graphCycle graphPlatonic solidPrismMaximal planar graphTournament odd number Hamiltonian paths


Lets find Hamiltonian cycle

Herschel graph


Hamiltonian Graph (4)public static void HamiltonianCycle(Node node, int level, List pathSoFar) { if (level == nodesCount) { foreach (Node neighbor in node.Neighbors) { if (neighbor == startNode) { List p = new List();p.AddRange(pathSoFar);p.Add(startNode);cycles.Add(p); } } return; } 12Hamiltonian Graph (5) for (int i = 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; } }}

13Live Demo

Travelling Salesman Problem

Travelling SalesmanFinding Hamiltonian cycle with minimal costAlso NP-completeHeuristicsGreedyPairwise exchange Randomized improvement

16Live Demo

Hamiltonian Cyclehttp://algoacademy.telerik.com , , SEO - , HTML, CSS, JavaScript, Photoshop ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC " cloud "BG Coder - - online judge , " " , ASP.NET - , , C#, .NET, ASP.NET iPhone, Android, WP7, PhoneGapfree C# book, C#, Java, C# - - C# , , ??????????????????Questions??ResourcesNakovs book: Programming = ++Algorithms;http://en.wikipedia.org/wiki/Hamiltonian_pathhttp://neohumanism.org/h/ha/hamiltonian_path.htmlhttp://en.wikipedia.org/wiki/Travelling_salesman_problemhttp://en.wikipedia.org/wiki/Herschel_graph

19Free Trainings @ Telerik AcademyC# Programming @ Telerik Academycsharpfundamentals.telerik.comTelerik Software Academyacademy.telerik.comTelerik Academy @ Facebookfacebook.com/TelerikAcademyTelerik Software Academy Forumsforums.academy.telerik.com