Skip to content

Instantly share code, notes, and snippets.

@Satshabad
Created January 31, 2013 18:47
Show Gist options
  • Save Satshabad/4685253 to your computer and use it in GitHub Desktop.
Save Satshabad/4685253 to your computer and use it in GitHub Desktop.
Worklist algorithm
def worklist(graph, s, get_edge_state):
q = [s]
v = set()
enter_state = {}
old = None
while q:
curr = q.pop(0)
state = get_edge_state(old, curr)
for adj in graph[curr]:
if adj not in q and adj not in v:
q.append(adj)
elif get_edge_state(curr, adj) != enter_state[adj]:
q.append(adj)
v.add(curr)
old = curr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment