Last active
August 29, 2015 14:04
-
-
Save kartikkukreja/029e79090b7ab8d75e6e to your computer and use it in GitHub Desktop.
Topological Sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let L be an empty list | |
Let all vertices be initially unmarked | |
while there are unmarked vertices: | |
select an unmarked vertex u | |
dfs(u) | |
def dfs(vertex u): | |
mark u | |
foreach edge u -> v | |
if v is unmarked: | |
dfs(v) | |
add u to head of L | |
L represents the topological order of the DAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment