Created
April 2, 2019 05:15
-
-
Save Ashaba/3d8a9afddf81f211b2bce0e2bd5cc4d9 to your computer and use it in GitHub Desktop.
This file contains 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
DFS-iterative (G, s): //Where G is graph and s is source vertex | |
let S be stack | |
S.push( s ) //Inserting s in stack | |
mark s as visited. | |
while ( S is not empty): | |
//Pop a vertex from stack to visit next | |
v = S.top( ) | |
S.pop( ) | |
//Push all the neighbours of v in stack that are not visited | |
for all neighbours w of v in Graph G: | |
if w is not visited : | |
S.push( w ) | |
mark w as visited | |
DFS-recursive(G, s): | |
mark s as visited | |
for all neighbours w of s in Graph G: | |
if w is not visited: | |
DFS-recursive(G, w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment