Directed Graph - course schedules

BFS

two hash maps

  • parent to children
  • indegree map

add nodes with 0 indegree into queue

poll out the top node of the queue

  • if it has children, children's indegree minus one
  • if one of its children's indegree equals to zero, add to queue

check sth.

DFS

Undirected Graph - graph valid tree

results matching ""

    No results matching ""