Search code examples
algorithmdepth-first-search

what is the depth first search node expansion sequence of this graph


I am trying to figure out the sequence of nodes expansion of this graph when using applying DFS.

enter image description here Should the sequence be A, B, C, D, E, G or A, B, D, E, G

Assuming ties are resolved in alphabetical order.


Solution

  • If you do DFS, choosing nodes in alphabetical order, the first path you find to G will be A, B, C, D, E, G.