Created
April 27, 2017 18:42
-
-
Save binary-signal/1e8aee1e1e3668b095dec5962ae132ca to your computer and use it in GitHub Desktop.
condition to check if graph has hamiltonian cycle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_hamiltonian(path, v, n): | |
""" | |
:param path: a list nodes in path | |
:param v: current head | |
:param n: total number of nodes in the graph | |
:return: True if it's a hamiltonian path False otherwise | |
""" | |
if path[0] == v and len(path) == n: | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment