Hi, everyone.
So in this video, we are going to write the call for the Dijkstra's algorithm.
So let's start.
So in the Dijkstra algorithm, what will be the input?
So I think I will take two things as input.
I will take what is the graph?
And second thing is, I will take this also vertex, the source city, the city from which I have to
find out the distance of all of the cities.
Right.
So the source of the graph and the source vertex.
Now, what we need to do, as I told you, for each vertex.
For each city, for each vertex, we what do we need to do?
I will Mark visited as falls because currently I have not visited any of the city, any of the vertex.
Similarly, that distance at a distance of all the vertex is initially infinity now for the source node.
But I need to do so for the source node.
Basically you will mark the distance distance of source node from itself will obviously be zero.
Right.
So sorry.
This I want to write source here.
Some distance off source node from itself will obviously be zero.
Right.
What else.
What to do.
We need to create a minimum heap now to create.
Create minimum hip and let's say the name of the hip is cool and what they will do.
You will push these sorts of attacks.
So we are going to push you don't push the salsa vortex.
So I am pushing the salsa vortex.
And breast is pretty much simple.
We decided that while the que is not empty, while my minimum hip is not empty, what we will do, we
will pick, we will pick the minimum vertex.
So.
We will pick the minimum city minimum vortex.
What do I mean by minimum vortex whose distances minimum?
Right.
So after picking this one to go to all the neighbors, so go to all the neighbors.
So for each neighbor, for each neighbor, Vertex V of you, first of all, what do we need to check?
We need to check whether the neighbor has been visited already or not visited.
So if the neighbor is not visited, then only I will do something right.
And one more thing that I forgot to do here is after picking the element from the minimum heap, we
need to mark this vertex as visited.
So visited of you is basically true.
We have visited this vertex.
So if the neighbor has not been visited, then only I will do something and I will do I will check if
my distance, if my distance plus the word.
Between you and me is less than your distance.
If that is the case, then I am of going to update your distance so your distance should have been updated,
some distance of me will be my distance, plus the distance between us.
That is the word between us, the number of kilometers between us.
And one more thing we need to push.
We need to push this vortex inside.
He also inside the medium also.
So it could not push this vortex rate, could not push this vortex.
So this if and this for loop ends here and this via loop answer and this function answer.
And we are done and our code is ready.
So this is the code for the Dijkstra algorithm.
Right.
If you have any doubt in this code, you can definitely ask me.
This is the complete code for Dijkstra.
So this is it from this device.
I will see you in the next one.
Thank you.