TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
The implementation of Hamilton's cycle dynamic solution for vertices number less than 20. More...
#include <cassert>
#include <iostream>
#include <vector>
Go to the source code of this file.
Functions | |
bool | hamilton_cycle (const std::vector< std::vector< bool > > &routes) |
static void | test1 () |
static void | test2 () |
static void | test3 () |
int | main (int argc, char **argv) |
The implementation of Hamilton's cycle dynamic solution for vertices number less than 20.
I use \(2^n\times n\) matrix and for every \([i, j]\) ( \(i < 2^n\) and \(j < n\)) in the matrix I store true
if it is possible to get to all vertices on which position in i
's binary representation is 1
so as \(j\) would be the last one.
In the the end if any cell in \((2^n - 1)^{\mbox{th}}\) row is true
there exists hamiltonian cycle.
Definition in file hamiltons_cycle.cpp.
bool hamilton_cycle | ( | const std::vector< std::vector< bool > > & | routes | ) |
The function determines if there is a hamilton's cycle in the graph
routes | nxn boolean matrix of \([i, j]\) where \([i, j]\) is true if there is a road from \(i\) to \(j\) |
true
if there is Hamiltonian cycle in the graph false
if there is no Hamiltonian cycle in the graph Definition at line 30 of file hamiltons_cycle.cpp.
int main | ( | int | argc, |
char ** | argv ) |
Main function
argc | commandline argument count (ignored) |
argv | commandline array of arguments (ignored) |
Definition at line 142 of file hamiltons_cycle.cpp.
|
static |
this test is testing if hamilton_cycle returns true
for graph: 1 -> 2 -> 3 -> 4
Definition at line 81 of file hamiltons_cycle.cpp.
|
static |
this test is testing if hamilton_cycle returns false
for
graph:
1 -> 2 -> 3 | V 4
Definition at line 103 of file hamiltons_cycle.cpp.
|
static |
this test is testing if hamilton_cycle returns true
for clique with 4 vertices
Definition at line 122 of file hamiltons_cycle.cpp.