new implementation of bfs and dfs with arbitrary number of children