Topological Sort | Kahn's Algorithm | Graph Theory

  Рет қаралды 128,689

WilliamFiset

WilliamFiset

Күн бұрын

Пікірлер: 147
@puneetkumarsingh1484
@puneetkumarsingh1484 4 жыл бұрын
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.
@Aldrin32f
@Aldrin32f 2 жыл бұрын
Repeated the same feat, KZbin recommendation to the rescue. PS Thanks @WilliamFiset
@democreation3594
@democreation3594 Ай бұрын
@@Aldrin32f did the same and now I am here😁
@shouryasingh2193
@shouryasingh2193 4 жыл бұрын
I just now Solved Course Schedule II on leetcode using this algo
@williamadams5034
@williamadams5034 4 жыл бұрын
My favourite ordering is to Keep Sleeping.
@AtharvaRao0104
@AtharvaRao0104 2 ай бұрын
@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.
@geniamartynova8844
@geniamartynova8844 2 жыл бұрын
Clean and concise explanation. Easy to comprehend and remember. Thank you!
@njkevlani
@njkevlani 4 жыл бұрын
TIL Superman didn't know topological sort
@dheerajgopinath1892
@dheerajgopinath1892 2 жыл бұрын
The way you explained is simply superb!! especially the "getting ready for school" example..
@LUKFUNTV
@LUKFUNTV 4 жыл бұрын
Really takes an effort to make it sooooooooooooo SIMPLE🙏🙏🙏🙏🙏🙌🙌🙌🙌🙌
@m.movsar
@m.movsar 10 ай бұрын
Лучший канал по алгоритмам! Thank you William!
@KevinDesai
@KevinDesai 2 жыл бұрын
What an example to start with. Thanks for not starting with gibberish numbers. This makes more sense than all the other videos
@1hpdell
@1hpdell 3 жыл бұрын
William, really appreciate your effort in making this Video! Effort behind this Animation is awesome, explanation is awesome too!
@abhishektiwari7643
@abhishektiwari7643 8 ай бұрын
Was following a course and couldn't understand this concept there but this video was so simple and better explained
@AbrahamWilson
@AbrahamWilson 4 жыл бұрын
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.
@vedantsharma5876
@vedantsharma5876 3 жыл бұрын
That would surely be the best DP course on KZbin. I love how he explains
@sandeepjnv13
@sandeepjnv13 2 жыл бұрын
Not to undermine William but there’s KZbin channel “Inside Code”, he explains lot of concepts pretty well. He has dynamic programming content as well. Also a Udemy course on dynamic programming
@pelvispresley22
@pelvispresley22 Жыл бұрын
The freecodecamp video from Alvin Zablan on DP is as good as it gets
@robaczliwy
@robaczliwy 4 жыл бұрын
Thank you for a very clear explanation. Implementation was easy once I grasped the concept you've laid out in this video.
@Sunny-vl1ff
@Sunny-vl1ff 3 жыл бұрын
Thanks! It is great to see how the algorithm works in practice.
@njww13
@njww13 2 жыл бұрын
This video helped a lot since before I would constantly wake up in the morning and put on my school before my socks
@justarandomguyofficial1058
@justarandomguyofficial1058 3 жыл бұрын
just looking at the playlists you made motivates me
@David-fy1sn
@David-fy1sn 2 жыл бұрын
Wow great explanation in only 13 mins!
@przemekbary
@przemekbary Жыл бұрын
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)
@emwistu22
@emwistu22 2 ай бұрын
Your videos and your teaching style are amazing!!
@mercyomwoyo985
@mercyomwoyo985 Жыл бұрын
Thanks William for the visualization and Animation! I clearly understand the concept now!
@mister_mad
@mister_mad Жыл бұрын
amazing explanation and visualization of the algorithm! a video unlike no other
@kartarsingh7776
@kartarsingh7776 3 жыл бұрын
That was a great example(dressing up) at the start of video.
@JeremyIglehart
@JeremyIglehart 2 жыл бұрын
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.
@jamesbon68
@jamesbon68 2 жыл бұрын
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.
@agnelamodia
@agnelamodia 3 жыл бұрын
Easy and simple. Marvelous.
@centr0
@centr0 Жыл бұрын
Wow. I understood that. Great way of teaching. You’re amazing. Thank you, sir.
@leducphuclong
@leducphuclong Жыл бұрын
Thank you so much, I really appreciate your video. Please continue...
@northridgefield
@northridgefield Жыл бұрын
Great clarity - quality content.
@LUKFUNTV
@LUKFUNTV 4 жыл бұрын
I recommend this.........to all the before_watching_read_comments_section people 🙌🙌🙌
@Sauce-ke
@Sauce-ke 3 жыл бұрын
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
@yamatolowa2256
@yamatolowa2256 3 жыл бұрын
this is 1 on 1 teaching i believe
@zy3749
@zy3749 4 жыл бұрын
Thank you so much, it is the most clear explanation I've found.
@fantasy9960
@fantasy9960 2 жыл бұрын
thank you so much William! this is extremely helpful for beginners!
@shnerdz
@shnerdz 4 жыл бұрын
great explanation as always. please make a video on segment trees next! such a powerful yet simple data structure
@neerajkulkarni6506
@neerajkulkarni6506 4 жыл бұрын
10/10 beautifully explained!
@avipatel1534
@avipatel1534 3 жыл бұрын
Thanks this video helped me optimize my sort code for leetcode course scheduling
@Junposs
@Junposs 4 жыл бұрын
Thank you Wiliam, I finally understand what Topological Sort is!
@markwillis2336
@markwillis2336 Жыл бұрын
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.
@abhinavboyed6624
@abhinavboyed6624 2 жыл бұрын
I'm about to binge watch all your videos. Thanks for the awesome content!
@spicy_wizard
@spicy_wizard 4 жыл бұрын
FANTASTIC. The problem with DFS on topological sort is that the recursion is too expensive, BFS is faster in all other aspects
@puneetkumarsingh1484
@puneetkumarsingh1484 4 жыл бұрын
Alternatively, we can implement the DFS topological sort algo, using stack.
@Learner010
@Learner010 4 жыл бұрын
Very nice explanation. please make a video on articulation point and bridges
@twistedlog24
@twistedlog24 8 ай бұрын
thanks for explaning this so clearly!!
@soanonso
@soanonso 2 жыл бұрын
Nicely explained - thanks for this.
@atharvas4399
@atharvas4399 3 жыл бұрын
this is 100 times better than my algo professor
@sstp105
@sstp105 3 жыл бұрын
amazing explanation!
@mickeynig1
@mickeynig1 3 жыл бұрын
Thanks Mr. Fiset really awesome explanation
@NoName-ip4tt
@NoName-ip4tt 3 жыл бұрын
Animation you conduct has heart beat sound as background. I like it :)
@lazysky1234
@lazysky1234 Жыл бұрын
Thank you for your video, great explanation!
@babumon5351
@babumon5351 3 жыл бұрын
Very nice explanation. Thanks
@jeehar1
@jeehar1 23 күн бұрын
It was clear, thanks again man
@nehascorpion
@nehascorpion 2 жыл бұрын
Awesome content! Thank you for putting in so much effort. Appreciate it!
@hix0071
@hix0071 3 жыл бұрын
Keep it up William. May you reach million subs next year !
@mostafaarafa1461
@mostafaarafa1461 3 жыл бұрын
Thanks, You explained it really perfectly
@djklsdf-32sdf
@djklsdf-32sdf Ай бұрын
최고의 영상
@cardel-qq6xp
@cardel-qq6xp 11 ай бұрын
Underwear -> pants -> shirt -> hoodie -> socks -> shoes -> school
@kevintran6102
@kevintran6102 4 жыл бұрын
Good as always. So easy to understand.
@jabir5768
@jabir5768 2 жыл бұрын
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 ?
@30天冥想练习
@30天冥想练习 3 жыл бұрын
Kahn : Implements Topological Sort. Superman : Am i a joke to you ? Wears underwear after pants.
@ksenthu
@ksenthu 4 жыл бұрын
Best explanation ever, thank you!
@algorithmscasts902
@algorithmscasts902 3 жыл бұрын
Nice animation and great explanation, thank you
@m-meier
@m-meier 2 жыл бұрын
This was awesome! Subscribed!
@shantanubapat6937
@shantanubapat6937 4 жыл бұрын
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?
@WhyAnkurGautam
@WhyAnkurGautam 2 жыл бұрын
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.
@jisanson
@jisanson 3 жыл бұрын
Thank you for this awesome video!
@tanmaykharshikar9419
@tanmaykharshikar9419 3 жыл бұрын
This video is a gem, thanks! You have a new fan :)
@yujianzhao6461
@yujianzhao6461 4 жыл бұрын
Thanks a lot man! I really appreciate your work!
@geomichelon
@geomichelon 2 жыл бұрын
great video! Thanks man!
@ricardo7240
@ricardo7240 4 жыл бұрын
Awesome, keep it up!
@VijayKiran225
@VijayKiran225 2 жыл бұрын
beautiful explanation .. keep up the good work.. subscribed as well
@akshatmehra3951
@akshatmehra3951 Жыл бұрын
You're the best man
@migzleon4047
@migzleon4047 3 жыл бұрын
Excellent content.!
@akidanis6984
@akidanis6984 8 ай бұрын
holy shit this was such a great explanation, tysm!!
@prabhat2342
@prabhat2342 3 жыл бұрын
wonderful explanation, thanks man:)
@FaustoCarvalho
@FaustoCarvalho Жыл бұрын
What tool have you used to draw and animate these graphs? Thanks
@il5083
@il5083 Жыл бұрын
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?
@droy7528
@droy7528 4 жыл бұрын
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.
@soumyajitchatterjee5822
@soumyajitchatterjee5822 2 ай бұрын
Beautiful
@vm7240
@vm7240 2 жыл бұрын
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
@AryanPatel-wb5tp
@AryanPatel-wb5tp Ай бұрын
What is run time , O(V+E) ? can someone explain line by line using the pseudocode if possible
@ameynaik2743
@ameynaik2743 3 жыл бұрын
Nice video, how is this different from another video you have on top sort using dfs?
@pankajpanwar9385
@pankajpanwar9385 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
@bullymaguire2335
@bullymaguire2335 Жыл бұрын
Dude just increase ur volume .no other complains .👍
@akashshirale1927
@akashshirale1927 4 жыл бұрын
can u post videos on identifying kadane's algorithm for dynamic programming
@WebSurfingIsMyPastime
@WebSurfingIsMyPastime Жыл бұрын
Great Video!
@amanbhatia7442
@amanbhatia7442 7 ай бұрын
just realized you have a similar algorithm for the dfs approach as well? , But I really like this, feels intuitive
@saralee548
@saralee548 3 жыл бұрын
amazing.
@ManishaSingh-yk5en
@ManishaSingh-yk5en 2 жыл бұрын
Can we get the ppt which is being used in the video?
@76lunagogogo
@76lunagogogo 7 ай бұрын
Regarding the DAG, isn't the (3) also not he DAG as the same reason that (4) one has?
@alifrahman7099
@alifrahman7099 3 ай бұрын
Amazing
@zappist751
@zappist751 Жыл бұрын
MAH MANNN
@无名-c1f
@无名-c1f 3 жыл бұрын
What drawing software to use? The picture is very nice
@pamp3657
@pamp3657 Жыл бұрын
very good video
@tarunstv796
@tarunstv796 2 жыл бұрын
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.
@shreyashachoudhary480
@shreyashachoudhary480 3 жыл бұрын
Awsm!
@nitika9769
@nitika9769 Жыл бұрын
my Saviour
@krealle
@krealle Ай бұрын
Thanks!
@mnchester
@mnchester 3 жыл бұрын
great vid
@bxfootballphenom
@bxfootballphenom 2 жыл бұрын
I've been running into a problem with this algorithm when there is no node 0. In this case, the inDegrees array will always have the 0th index be 0, and since there is no "0" node to add any incoming dependencies it will incorrectly add it to the queue. This also ends up breaking the rest of the algorithm since the true size of the inDegrees array is 1 less than what we were expecting. For example if our vertices are [1,2,3,4] the inDegree array at initialization will be [0,0,0,0] and will only match up to vertex 3, since at iteration it will be expecting i to start at 0. Has anyone else come across this and how have you solved this?
@WilliamFiset-videos
@WilliamFiset-videos 2 жыл бұрын
Hey Cesar, when labelling the nodes of the graph you should always label the first node as node 0, the second node as node 1, the third node as node 2 and etc... This should ensure that you always have a node 0, does this resolve your problem?
@bxfootballphenom
@bxfootballphenom 2 жыл бұрын
@@WilliamFiset-videos Thanks!
@andreyvalverde4780
@andreyvalverde4780 2 жыл бұрын
hi there, quick question, based on the code, how do we make sure that we are not adding vertices that we've already visited?
@RushOrbit
@RushOrbit Жыл бұрын
Where did you find the intro music for your videos?
@karankanojiya7672
@karankanojiya7672 2 жыл бұрын
Respect++
@enlgn7050
@enlgn7050 3 жыл бұрын
Okay....Now I get it. Superman got his DAG messed up
Topological Sort Algorithm | Graph Theory
14:09
WilliamFiset
Рет қаралды 472 М.
Каха и лужа  #непосредственнокаха
00:15
G-22. Kahn's Algorithm | Topological Sort Algorithm | BFS
13:50
take U forward
Рет қаралды 266 М.
Dijkstra's Shortest Path Algorithm | Graph Theory
24:47
WilliamFiset
Рет қаралды 209 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 500 М.
Course Schedule II - Topological Sort - Leetcode 210
17:09
NeetCode
Рет қаралды 162 М.
Breadth First Search grid shortest path | Graph Theory
16:51
WilliamFiset
Рет қаралды 338 М.
You Must Learn This Pattern | Topological Sort
10:12
Kantan Coding
Рет қаралды 3,8 М.
The Midpoint Circle Algorithm Explained Step by Step
13:33
NoBS Code
Рет қаралды 132 М.