Last active
August 18, 2017 00:06
-
-
Save lion137/651d537f12ba8ceb9fe9faa502f34ec1 to your computer and use it in GitHub Desktop.
Blog
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
| def afs(g, s): | |
| bag = data_structure() | |
| bag.add(s) | |
| while bag is not empty: | |
| tile = bag.pop() | |
| if tile is not marked: | |
| mark(tile) | |
| for x in adj_list(tile): | |
| bag.add(x) |
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
| dfs(g, v): | |
| if v not marked: | |
| mark(v) | |
| for w in adj_list(v): | |
| dfs(g, w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment