Graph Traverse DFS Recursive vs Iterative different sequence in the results

Going through both videos of different approach to solve DFS I’ve notice the output sequence is different

They should be the same sequence since it’s just implementation details

Please advise why it’s show different sequence

1 Like

Graphs do not have a fixed order for traversals since there is no guarantees on ordering within the same level. The traversal only requires that everything at level n be traversed before everything at level n+1.

Therefore the reordering is acceptable. I believe Mosh mentioned it in passing in one of the videos.