Hi, everyone.
So in this video, we are going to write the code for topological sword, so the return type will be
void.
We will be just printing the order and then let's say the name of the function is topological.
Certainly.
It will take Gadhafi's and input.
So what is the first step that we need to do, the first step is basically like it depends how you have
implemented it.
If you can implement my ideas and say metrics or you can implement a graph or a list, so what are you
to do?
You need to treat, you know, to trade audio graph basically uninterrupted or all the witnesses I read
or whatever it is and what you need to do.
The first step is basically you need to fill this in degree at a lightweight over vertices and you need
to fill the value of integrity degree.
Right.
So first of all, we need to populate this integrity and that we can easily do.
You just need to it or whatever it is and just start filling, start filling this very simple.
Right now, the next step, what you need to do, you will iterate.
You will iterate over this in degree at.
You will outrage over this integrity and what you are going to do is you will push all the vertex in
the queue, which are independent.
Right, so if the integrity
for a Vortex V is basically zero, that means this node is independent.
If it is independent, it has to be present in the queue.
So could not push this vertex.
And here you need to create one queue which will store Vertex after this is done, what we need to do
while the queue is not empty.
So while my queue is not empty.
While my view is not empty, what do you need to do?
You need to pick the value from the queue.
So let's say you so what is you?
You is basically to stop and remove this value from the queue.
So called ARTPOP.
Sorry, it will not be to the top.
Actually it will be good old friend and stack we have to keep in queue.
We have friend so this will be good.
Our friend.
And then culotte pop, simple.
So for this vertex, what is the next step?
Next step is basically go to all other neighbors, go to all the neighbors, so go to all neighbors.
Go to all neighbors, let's say all neighbor vortex, we what we need to do, you need to reduce there
in degree by one.
So you need to reduce in degree of violence or any degree of B minus minus simple.
I'm repeating myself after popping the N word to go to all the neighbors and reduce their degree by
even so in degree of minus minus and and and end after reducing the degree by one if the degree.
If the degree for this vertex becomes zero, that means this vertex is now independent.
If this vertex has now become independent, then it should be part of.
Q So we will push in the queue.
Simple, right?
One thing that we forgot to miss here is we forgot to print.
So after getting Vertex, you you need to print also.
Right.
That was the whole team.
So see out your vertex you and that's all you need to do that it.
Right.
So I'm repeating myself.
You will take a graph as input then the first thing is basically to fill this A.R.T. how are you going
to fill this area.
You can just iterate over the edges or vertices basically depending upon how you are implementing your
graph, and then you can populate this integrity after creating the integrity, create 22, iterate
over the integrity area that you have created.
If it is independent, if anything that is independent.
That has to be the part of.
Q So you will push inside the queue while the Q is not empty.
The first element of the element on the Q and print that element.
Print that element.
Right, because we need to print the order, we need to print the order.
So we need to print here then we're going to do since we have completed the task, we have enrolled
in this course, we have completed this course.
So what I will do, I will go to the rest of the courses, so I will go to all my neighbors and I will
reduce their integrity by one.
Now, after reducing the degree by one degree minus minus, it might be possible that the cause has
now become independent.
Right.
So if for that cause now the end degree becomes zero, that means the cost can be enrolled and completed
now.
So we will push in the queue.
We will push the course in the queue so that we can enroll in that course and complete that course.
And there is already enough to do that.
Is all about topological thought.
You can implement this code in any language and if you face problem in implementing this code, then
do let me know.
I will provide you the code.
So that is all about topological sorting.
Right.
So this is it from this video.
Guys, I will see you in the next one.
Thank you.