Problem In DFS

Hi @all
I studied DFS and tried to implement it, but I think I am doing some mistake and thus unable to find all vertices, please check my code

With Regars
Thank you

this is ur corrected code…LINK…hope u understand the mistake u were making…:slight_smile:

P.S.: have made this mistake many times…:stuck_out_tongue:

1 Like

When you’re trying to debug your code, you should realized that you “Find vertex 0”, but there is no such vertex.

So when you look to your code, where you starting new dfs you find:

for(u=0; u != adj[v].size(); u++)

But, u is just index to adjeceny list, not actuall vertex. So you should write:

for(u=0; u != adj[v].size(); u++)

Because adj[v][u] store real vertex.

ohh… thank you kunal and I was unable to figure out that… :slight_smile: really thanks :slight_smile:

glad could help…:slight_smile: