Skip to content

Instantly share code, notes, and snippets.

@mlconnor
Created August 14, 2014 20:24
Show Gist options
  • Save mlconnor/7e97ca78ac86b93ded90 to your computer and use it in GitHub Desktop.
Save mlconnor/7e97ca78ac86b93ded90 to your computer and use it in GitHub Desktop.
depth first search vs breadth first search
list nodes_to_visit = {root};
while( nodes_to_visit isn't empty ) {
currentnode = nodes_to_visit.first();
nodes_to_visit.prepend( currentnode.children );
//do something
}
BFS:
list nodes_to_visit = {root};
while( nodes_to_visit isn't empty ) {
currentnode = nodes_to_visit.first();
nodes_to_visit.append( currentnode.children );
//do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment