Data Structures- A Look At Hamiltonian Circuits - Java Tutorials | Dream.In.Code



Data Structures- A Look At Hamiltonian Circuits - Java Tutorials | Dream.In.Code

What Is a Hamiltonian Circuit?
A Hamiltonian Circuit is a cyclic Graph (or sub-graph) such that each vertex can only be accessed in a single path. They also contain all the vertices in the given graph. As such, all Graphs containing Hamiltonian Circuits have at least three vertices. Hamiltonian circuits are cyclic graphs with n vertices and edges. As such, each vertex in the circuit has a degree of two.

There are a number of different theorems that can be used to determine the Hamiltonicity of a graph. The two simplest theorems to look at are Dirac's Theorem and Ore's Theorem. Dirac's Theorem states that a simple graph has a Hamiltonian circuit if it has at least three vertices, all of which have a degree of at least number of vertices/2. Ore's Theorem states that for a simple graph with at least three vertices, the graph has a Hamiltonian circuit if each pair of vertices that are not adjacent have a combined degree greater than or equal to the number of vertices.

Finding Hamiltonian Circuits in Unweighted Graphs
Based on the above properties of Hamiltonian circuits, let's examine an algorithm to find these circuits in unweighted graphs. Kruskal's algorithm to find a minimum spanning tree is a good place to start because it deals with reassembling edges on a graph. Simply by applying Kruskal's algorithm with a couple checks, finding a Hamiltonian circuit in a graph becomes pretty simple. Simply reassemble the edges such that no Vertex has a degree of two, and that no circuit is created. Order the vertices based on degree, and deal with the vertices of degree two first using Kruskal's algorithm. This helps assure that at the end, no additional vertices will have a degree that isn't two. Next, deal with the vertices of degree greater than two. For each vertex, choose an edge that satisfies the above conditions. Repeat until any edge choice would violate the tree property.

Wait, the purpose of the algorithm is to find a Hamiltonian circuit though? By the time this portion of the algorithm finishes, the final result will be a singly-linked list with a head and tail node. Every other vertex will have a degree of two. Simply connect the head and tail nodes to complete the Hamiltonian circuit.

Travelling Salesman Problem
The goal in finding Hamiltonian circuits in weighted graphs is to find the circuit with the lowest total cost. This is also called the Travelling Salesman Problem, and it is considered an NP problem, meaning there is no known polynomial time solution. In this section, we will explore the Held-Karp algorithm, which is the best known solution, solving the Travelling Salesman Problem within 0.5% of the optimal solution. It has a runtime complexity of O(n2 * 2n).

The Held-Karp algorithm works by finding a Vertex such that the sum of the distances across its two lowest-cost Edges is less than that of any other Vertex. It then finds the minimum spanning tree along the remaining Vertices using Prim's algorithm, which is essentially the same as Dijkstra's algorithm except it doesn't violate the Tree property. The other constraint it places is that no Vertex can have a degree greater than two in the final Hamiltonian circuit.


Read full article from Data Structures- A Look At Hamiltonian Circuits - Java Tutorials | Dream.In.Code


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts