tree - Non recursive Depth first search algorithm -
i looking non recursive depth first search algorithm non binary tree. appreciated.
dfs:
list nodes_to_visit = {root}; while( nodes_to_visit isn't empty ) { currentnode = nodes_to_visit.take_first(); nodes_to_visit.prepend( currentnode.children ); //do }
bfs:
list nodes_to_visit = {root}; while( nodes_to_visit isn't empty ) { currentnode = nodes_to_visit.take_first(); nodes_to_visit.append( currentnode.children ); //do }
the symmetry of 2 quite cool.
update: pointed out, take_first()
removes , returns first element in list.
Comments
Post a Comment