Skip to content

Instantly share code, notes, and snippets.

@binary-signal
Created April 27, 2017 18:42
Show Gist options
  • Save binary-signal/1e8aee1e1e3668b095dec5962ae132ca to your computer and use it in GitHub Desktop.
Save binary-signal/1e8aee1e1e3668b095dec5962ae132ca to your computer and use it in GitHub Desktop.
condition to check if graph has hamiltonian cycle
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