Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hamiltonian Cycle Penka Borukova Student at Telerik Academy.

Similar presentations


Presentation on theme: "Hamiltonian Cycle Penka Borukova Student at Telerik Academy."— Presentation transcript:

1 Hamiltonian Cycle Penka Borukova Student at Telerik Academy

2 Table of Contents History Hamiltonian Cycle Hamiltonian Graph
* Table of Contents History Hamiltonian Cycle Hamiltonian Graph Travelling salesman (c) 2007 National Academy for Software Development - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

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 Hamiltonian paths

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 (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; }

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

19 Resources Nakov’s book: Programming = ++Algorithms;
th.html an_problem

20 Free Trainings @ Telerik Academy
“C# Telerik Academy csharpfundamentals.telerik.com Telerik Software Academy academy.telerik.com Telerik Facebook facebook.com/TelerikAcademy Telerik Software Academy Forums forums.academy.telerik.com


Download ppt "Hamiltonian Cycle Penka Borukova Student at Telerik Academy."

Similar presentations


Ads by Google