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
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…
P.S.: have made this mistake many times…
ohh… thank you kunal and I was unable to figure out that… really thanks
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++)
if(!visited[u])
dfs(u);
But, u is just index to adjeceny list, not actuall vertex. So you should write:
for(u=0; u != adj[v].size(); u++)
if(!visited[adj[v][u]])
dfs(adj[v][u]);
Because adj[v][u] store real vertex.
glad could help…