Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Topological sort DFS

Chen
November 16, 2022

Topological sort DFS

Chen

November 16, 2022
Tweet

More Decks by Chen

Other Decks in Science

Transcript

  1. Modified DFS for Topological Sort Visited is an empty set

    For each startvertex in verticies: if startvertex in visited continue Push (visit,startvertex) Repeat until stack is empty (action,curr) = pop from stack if action==visit if curr is not in visited add curr to visited Push (finish,curr) for each v adjacent to curr push (visit,v) else Put curr on front of todolist Stack is empty, so outer loop goes to next vertex If we pick Belt (already visited), we just go to the next vertex 38 / 71