def postorder(graph, root):
 visited = set()
 order = []
 def dfs_walk(node):
  visited.add(node)
  for succ in graph.successors(node):
   if (not (succ in visited)):
    dfs_walk(succ)
  order.append(node)
 dfs_walk(root)
 return order

def postorder ( graph , root ) : visited = set ( ) order = [ ] def dfs_walk ( node ) : visited . add ( node ) for succ in graph . successors ( node ) : if ( not ( succ in visited ) ) : dfs_walk ( succ ) order . append ( node ) dfs_walk ( root ) return order
return a post-order ordering of nodes in the graph .