@11:54 : It should be "Afterwards loop through all the *nodes* (not edges) of the graph and add all the nodes with an incoming degree of 0" This is a brilliant series. You teach in concise and clear manner. I first studied graphs in 2003 at college but never understood it and had great fear in the mind for graph problems. I found a great teacher after 21 years and I understand it easily. Thank you very much.
Not to undermine William but there’s UA-cam channel “Inside Code”, he explains lot of concepts pretty well. He has dynamic programming content as well. Also a Udemy course on dynamic programming
Great video. Small suggestion - right at the end where you check if index is not equals to n it would be really nice if you also showed an example of what would happen with your code if there was a cycle in the graph.
For anyone wondering about this, if you imagine a 3 node cycle, A -> B -> C -> A. Notice that you will never add these nodes to the queue because their indegree will never be 0. This implies that index will also never be larger than n.
I work from home. Why do I even need this getting dressed algorithm again? What an incredible breakdown, thank you so much for simplifying this complex topic so much for complete beginners like me.
HI ! Really nice explanation but I was wondering about the complexity why is it O(E+V) ? Shouldn't be O(V) since we iteratre of the nodes twice to set the degrees, then the while loop iterates exactly V times ?
We have to loop through once to find the vertices which have indegree of zero and put it in queue. After that we just have to pop the element and decrement in-degree of its dependent nodes. When you are decrementing you can check if it is zero or not. If it is zero than you can put that node into queue. This way you dont need priority queue. Only using queue will work in O(N+E) I guess.
Will this approach also work for cyclic graphs? *When I say it will work, I mean it will let us determine whether the graph is cyclic or not, or if a DAG will provide valid ordering.
Thanks a lot, William for all these golden videos. I recently came across Aho- corasick and finding it really difficult to umderstand it properly. So I am commenting on the latest vdo here...hoping u would see my comment. We would be really grateful if u could pull up a vdo on Aho-Corasick. Thanks in advance.
Nice video. Is there a reason not to use Kahn's algorithm instead of the DFS topological sort in an interview since this is easier to memorize and code?
What is the time complexity of calculating indegree? O(V^2) or O(V + E)? V = no of vertices E = no of edges Since there are two for loops, ig it should be v^2
Even tho you say that the in-degree array has to be number of nodes the current index is connected to indegree[0] = 0 Actually in code it seems like you're populating the in-degree by adding the number of nodes connected to the current index indegree[0] = 3
This video is simply great. When I read it first, it took 3-4 hrs to fully understand the algorithm. The video has done the same in 14min.
Repeated the same feat, UA-cam recommendation to the rescue. PS Thanks @WilliamFiset
@@Aldrin32f did the same and now I am here😁
I just now Solved Course Schedule II on leetcode using this algo
@11:54 : It should be "Afterwards loop through all the *nodes* (not edges) of the graph and add all the nodes with an incoming degree of 0"
This is a brilliant series. You teach in concise and clear manner. I first studied graphs in 2003 at college but never understood it and had great fear in the mind for graph problems. I found a great teacher after 21 years and I understand it easily. Thank you very much.
My favourite ordering is to Keep Sleeping.
Wow. I understood that. Great way of teaching. You’re amazing. Thank you, sir.
Underwear -> pants -> shirt -> hoodie -> socks -> shoes -> school
William, really appreciate your effort in making this Video! Effort behind this Animation is awesome, explanation is awesome too!
The way you explained is simply superb!! especially the "getting ready for school" example..
Clean and concise explanation. Easy to comprehend and remember. Thank you!
TIL Superman didn't know topological sort
What an example to start with. Thanks for not starting with gibberish numbers. This makes more sense than all the other videos
Really takes an effort to make it sooooooooooooo
SIMPLE🙏🙏🙏🙏🙏🙌🙌🙌🙌🙌
Thanks!
Appreciate from Brazil! In the next week I'll have the last graph exam in Pontifical Catholic University, and you helped me a lot
Лучший канал по алгоритмам! Thank you William!
Your videos and your teaching style are amazing!!
Thank you for a very clear explanation. Implementation was easy once I grasped the concept you've laid out in this video.
This video helped a lot since before I would constantly wake up in the morning and put on my school before my socks
Thanks! It is great to see how the algorithm works in practice.
just looking at the playlists you made motivates me
amazing explanation and visualization of the algorithm! a video unlike no other
I'm about to binge watch all your videos. Thanks for the awesome content!
Hey William, just wanted to say thank you. If it's possible could you make a series on DP like the one you're doing for graph theory.
That would surely be the best DP course on UA-cam. I love how he explains
Not to undermine William but there’s UA-cam channel “Inside Code”, he explains lot of concepts pretty well. He has dynamic programming content as well. Also a Udemy course on dynamic programming
The freecodecamp video from Alvin Zablan on DP is as good as it gets
Was following a course and couldn't understand this concept there but this video was so simple and better explained
Great video. Small suggestion - right at the end where you check if index is not equals to n it would be really nice if you also showed an example of what would happen with your code if there was a cycle in the graph.
For anyone wondering about this, if you imagine a 3 node cycle, A -> B -> C -> A. Notice that you will never add these nodes to the queue because their indegree will never be 0. This implies that index will also never be larger than n.
Thanks William for the visualization and Animation! I clearly understand the concept now!
I work from home. Why do I even need this getting dressed algorithm again?
What an incredible breakdown, thank you so much for simplifying this complex topic so much for complete beginners like me.
Thanks a lot for the explanation. You've got a great gift of explaining complicated thing easy (which IMO is the sign of a genius mind)
great explanation as always. please make a video on segment trees next! such a powerful yet simple data structure
Great clarity - quality content.
I hope all of my professors are teaching the same as you. I really need a data structure 1 on 1 teacher to teach me everything
this is 1 on 1 teaching i believe
Wow great explanation in only 13 mins!
Animation you conduct has heart beat sound as background. I like it :)
Keep it up William. May you reach million subs next year !
This is an excellent explanation, thanks!
Easy and simple. Marvelous.
10/10 beautifully explained!
thank you so much William! this is extremely helpful for beginners!
Awesome content! Thank you for putting in so much effort. Appreciate it!
Thank you so much, it is the most clear explanation I've found.
This video is a gem, thanks! You have a new fan :)
That was a great example(dressing up) at the start of video.
amazing explanation!
Thank you Wiliam, I finally understand what Topological Sort is!
Thank you so much, I really appreciate your video. Please continue...
Very nice explanation. please make a video on articulation point and bridges
This was awesome! Subscribed!
Good as always. So easy to understand.
Thanks Mr. Fiset really awesome explanation
Nicely explained - thanks for this.
Clean and simple
thanks for explaning this so clearly!!
I recommend this.........to all the before_watching_read_comments_section people 🙌🙌🙌
Awesome, keep it up!
It was clear, thanks again man
this is 100 times better than my algo professor
Thanks this video helped me optimize my sort code for leetcode course scheduling
Thank you for your video, great explanation!
Kahn : Implements Topological Sort.
Superman : Am i a joke to you ? Wears underwear after pants.
great work !!
Thanks a lot man! I really appreciate your work!
Very nice explanation. Thanks
HI ! Really nice explanation but I was wondering about the complexity
why is it O(E+V) ? Shouldn't be O(V) since we iteratre of the nodes twice to set the degrees, then the while loop iterates exactly V times ?
Nice animation and great explanation, thank you
최고의 영상
FANTASTIC. The problem with DFS on topological sort is that the recursion is too expensive, BFS is faster in all other aspects
Alternatively, we can implement the DFS topological sort algo, using stack.
beautiful explanation .. keep up the good work.. subscribed as well
We have to loop through all vertices to find those who have in degree of zero. Can we optimize this using heap or priority queue?
We have to loop through once to find the vertices which have indegree of zero and put it in queue. After that we just have to pop the element and decrement in-degree of its dependent nodes. When you are decrementing you can check if it is zero or not. If it is zero than you can put that node into queue. This way you dont need priority queue. Only using queue will work in O(N+E) I guess.
What tool have you used to draw and animate these graphs? Thanks
Best explanation ever, thank you!
Came here from advent of code day 5 ☺
Same
Bit late but same
great video! Thanks man!
Thank you for this awesome video!
Great Video!
Thanks, You explained it really perfectly
Will this approach also work for cyclic graphs?
*When I say it will work, I mean it will let us determine whether the graph is cyclic or not, or if a DAG will provide valid ordering.
What is run time , O(V+E) ? can someone explain line by line using the pseudocode if possible
You're the best man
fabulous !
Thanks a lot, William for all these golden videos. I recently came across Aho- corasick and finding it really difficult to umderstand it properly. So I am commenting on the latest vdo here...hoping u would see my comment. We would be really grateful if u could pull up a vdo on Aho-Corasick. Thanks in advance.
holy shit this was such a great explanation, tysm!!
Can we get the ppt which is being used in the video?
Nice video. Is there a reason not to use Kahn's algorithm instead of the DFS topological sort in an interview since this is easier to memorize and code?
What is the time complexity of calculating indegree? O(V^2) or O(V + E)?
V = no of vertices
E = no of edges
Since there are two for loops, ig it should be v^2
just realized you have a similar algorithm for the dfs approach as well? , But I really like this, feels intuitive
wonderful explanation, thanks man:)
Beautiful
can u post videos on identifying kadane's algorithm for dynamic programming
Where did you find the intro music for your videos?
Regarding the DAG, isn't the (3) also not he DAG as the same reason that (4) one has?
hi there, quick question, based on the code, how do we make sure that we are not adding vertices that we've already visited?
Nice video, how is this different from another video you have on top sort using dfs?
Best😭❤❤❤❤
can we remove 2 before 3?
What drawing software to use? The picture is very nice
Even tho you say that the in-degree array has to be number of nodes the current index is connected to indegree[0] = 0
Actually in code it seems like you're populating the in-degree by adding the number of nodes connected to the current index indegree[0] = 3
amazing.
very good video
Awsm!
Dude just increase ur volume .no other complains .👍