Skip to content

Instantly share code, notes, and snippets.

@wilderfield
Created June 6, 2020 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilderfield/fc1755449da2241ba41ed5ad7f485313 to your computer and use it in GitHub Desktop.
Save wilderfield/fc1755449da2241ba41ed5ad7f485313 to your computer and use it in GitHub Desktop.
Adjacency List
graph = [[1,3,5], # node 0 connects out to node 1,3,5
[2,4], # node 1 connects out to node 2,4
[4], # node 2 connects out to node 4
[1], # node 3 connects out to node 1
[5], # node 4 connects out to node 5
[]] # node 5 connects out to nothing
# This function returns the neighbors of a given node in a list
def getNeighbors(node):
return graph[node]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment