Great video, however I would use letters to represent the vertices(A, B, C...) to avoid confusion. Also you can increase the readability by representing a node like this: pair node. This way your graph would contain nodes instead of edges.
Just to be inline with your graphical representation since it's an undirected graph when adding an edge we have to add 2 links like that : void Graph::addEdge(int v1, int v2, int weight){ adj[v1].push_back(make_pair(v2, weight)); adj[v2].push_back(make_pair(v1, weight)); }
Hey, love the vid! Would you mind explaining how one could take your current implementation and potentially add a way to describe each path as it passes through the iteration? Instead of displaying the distance would it be possible to output the route?
You would have to use an array of size V to keep track for each node from which node we have come. You can then implement a function to print recursively the path.
This comment is over 1 year old and there is a 99% chance you already got the answer, but yes, it would work. However, in an unweighted graph is would be more effective to use breadth-first search instead.
I don't know what codeblocks is, but this is just C++ code (not platform specific). If codeblocks just uses a mainstream C++ compiler, I don't see why not.
@@zomy2k You would have to use an array of size V to keep track for each node from which node we have come. You can then implement a function to print recursively the path.
Thank you so much for your help! Thanks to this, I understand the dijkstra algo better
Great video, however I would use letters to represent the vertices(A, B, C...) to avoid confusion.
Also you can increase the readability by representing a node like this: pair node.
This way your graph would contain nodes instead of edges.
Just to be inline with your graphical representation since it's an undirected graph when adding an edge we have to add 2 links like that :
void Graph::addEdge(int v1, int v2, int weight){
adj[v1].push_back(make_pair(v2, weight));
adj[v2].push_back(make_pair(v1, weight));
}
Such great video bro, leaved a like.
the code is perfect but visual studio is showing "can not open or find the pdb file"
what should i do ?
please help
Hey, love the vid! Would you mind explaining how one could take your current implementation and potentially add a way to describe each path as it passes through the iteration? Instead of displaying the distance would it be possible to output the route?
You would have to use an array of size V to keep track for each node from which node we have come. You can then implement a function to print recursively the path.
Shouldn't the set be sorting the pair according to the weight, not the vertex? Are you sure this works?
the extract_set has weight as first and vertex as second. So it's sorted according to the weights.
Will this implementation work for unweighted graph by inserting all weights as "1" ?
This comment is over 1 year old and there is a 99% chance you already got the answer, but yes, it would work. However, in an unweighted graph is would be more effective to use breadth-first search instead.
How can I print the path it took?
how can we also print the shortest path it takes and not only the cost...
Hi.. can we use this C++ code on codeblocks ?
I don't know what codeblocks is, but this is just C++ code (not platform specific). If codeblocks just uses a mainstream C++ compiler, I don't see why not.
It doesn't show the "Path" (vertices from origin to destiny) just the total distance.
Yep!
@@CoffeeBeforeArch How would you go about printing the paths?
@@zomy2k You would have to use an array of size V to keep track for each node from which node we have come. You can then implement a function to print recursively the path.