educative.io

Why traverse back

in the example implementation of dfs, since we’re begining our search from 1, why are we returning back to cover 0?

Hi @Dot_East !!
Thanks for pointing it out. Yes, the loop will start from the source node + 1 and only visit the nodes that are reachable from the source. Node 0 will not be included in this loop and the code has been fixed.
Happy Learning :blush: