Hamiltonian loop algorithm

**Concept:** A **Hamiltonian graph** is a graph that contains a Hamiltonian cycle, which is a closed loop that visits each vertex exactly once. In other words, the graph must have a path that starts at one node, traverses through all other nodes exactly once, and returns to the starting point. Some edges may not be used, but no edge can be traversed more than once. This differs from an **Eulerian graph**, where the focus is on traversing every edge exactly once, rather than visiting every node. ![Hamiltonian Loop Algorithm](http://i.bosscdn.com/blog/o4/YB/AF/pyzGiAShVaAAEKBYfRxnE954.png) **Determination:** 1. **Dirac's Theorem (Sufficient Condition):** If an undirected graph has N vertices, and every vertex has a degree of at least N/2 (rounded up), then the graph is guaranteed to have a Hamiltonian cycle. 2. **Basic Necessary Conditions:** For a graph G = (V, E) to be Hamiltonian, for any non-empty subset S of V, if W(G - S) denotes the number of connected components in the subgraph formed by removing the nodes in S, then W(G - S) ≤ |S|. This condition ensures that the graph remains sufficiently connected to allow a Hamiltonian cycle. 3. **Competition Graphs (Hamiltonian Path):** A competition graph of order N is a directed graph where there is an edge between every pair of vertices. It is known that such graphs always contain a Hamiltonian path. **Algorithm:** **1. Constructing a Hamiltonian Cycle under Dirac’s Theorem:** - Step 1: Start with two adjacent nodes S and T, and build the longest possible path without repeating nodes. Extend both ends of the path until they cannot be extended further. - Step 2: If S and T are adjacent, the path forms a cycle. - Step 3: If S and T are not adjacent, find a node vi in the path such that vi is adjacent to T and vi+1 is adjacent to S. Then, rearrange the path to form a cycle. - Step 4: If the cycle is shorter than N, look for a node outside the cycle that is adjacent to the cycle and extend it. Repeat the process until all nodes are included. The algorithm relies on the pigeonhole principle to ensure that a Hamiltonian cycle can be constructed. **Pseudocode:** ```cpp const int maxN = 100; void reverse(int arr[maxN + 7], int s, int t) { int temp; while (s < t) { temp = arr[s]; arr[s] = arr[t]; arr[t] = temp; s++; t--; } } void Hamilton(int ans[maxN + 7], bool map[maxN + 7][maxN + 7], int n) { int s = 1, t; int ansi = 2; bool visit[maxN + 7] = {false}; for (int i = 1; i <= n; i++) if (map[s][i]) { t = i; break; } visit[s] = visit[t] = true; ans[0] = s; ans[1] = t; while (true) { while (true) { int i; for (i = 1; i <= n; i++) { if (map[t][i] && !visit[i]) { ans[ansi++] = i; visit[i] = true; t = i; break; } } if (i > n) break; } int w = ansi - 1; reverse(ans, 0, w); int temp = s; s = t; t = temp; while (true) { int i; for (i = 1; i <= n; i++) { if (map[t][i] && !visit[i]) { ans[ansi++] = i; visit[i] = true; t = i; break; } } if (i > n) break; } if (!map[s][t]) { for (int i = 1; i < ansi - 1; i++) if (map[ans[i]][t] && map[s][ans[i + 1]]) break; int w = ansi - 1; int i++; t = ans[i]; reverse(ans, i, w); } if (ansi == n) return; int j, i; for (j = 1; j <= n; j++) { if (visit[j]) continue; for (i = 1; i < ansi - 1; i++) if (map[ans[i]][j]) break; if (map[ans[i]][j]) break; } s = ans[i - 1]; t = j; reverse(ans, 0, i - 1); reverse(ans, i, ansi - 1); ans[ansi++] = j; visit[j] = true; } } ``` **Time Complexity:** The algorithm runs in O(n²) time, as each iteration adds at least one new node to the path, and the maximum number of iterations is bounded by n. The adjacency matrix is preferred for efficient edge lookups. **2. Constructing a Hamiltonian Path in a Competition Graph (N-order):** A **competition graph** of order N is a directed graph where there is a directed edge between every pair of nodes. Such graphs are guaranteed to have a Hamiltonian path. **Proof by Induction:** - Base case (n = 2): Trivially true. - Assume true for n = k. Add the (k+1)-th node. Depending on its connections, insert it into the existing Hamiltonian path. **Example:** Given a sequence V1 → V2 → V3 → V4, adding V5 based on its connections to the existing nodes allows for the construction of a new Hamiltonian path. **Code Example (C++):** ```cpp #include #include using namespace std; const int maxN = 200; void Insert(int arr[], int &len, int index, int key) { if (index > len) index = len; len++; for (int i = len - 1; i >= 0; --i) { if (i != index) arr[i] = arr[i - 1]; else { arr[i] = key; return; } } } void Hamilton(int ans[maxN + 7], bool map[maxN + 7][maxN + 7], int n) { int ansi = 1; ans[ansi++] = 1; for (int i = 2; i <= n; i++) { if (map[i][ans[ansi - 1]] == 1) ans[ansi++] = i; else { int flag = 0; for (int j = ansi - 2; j > 0; --j) { if (map[i][ans[j]] == 1) { flag = 1; Insert(ans, ansi, j + 1, i); break; } } if (!flag) Insert(ans, ansi, 1, i); } } } ``` This code constructs a Hamiltonian path in a competition graph by inserting new nodes into the appropriate position in the existing path.

Quartz Fiber Braided Sleeve

Quartz fiber Braided Sleeve is a type of protective sleeve made from high-purity quartz fibers. It is commonly used in high-temperature applications where excellent thermal and electrical insulation properties are required.


Quartz Fiber Braided Mesh,Quartz Fiber Braided Sleeve,Quartz Fiber Sleeving,Quartz Fiber Cable Sleeve

Dongguan Liansi Electronics Co.,Ltd , https://www.liansisleeve.com