Topological Sort | Kahn's Algorithm | Graph Theory

Поділитися
Вставка
  • Опубліковано 29 січ 2025

КОМЕНТАРІ • 156

  • @puneetkumarsingh1484
    @puneetkumarsingh1484 4 роки тому +68

    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 роки тому +2

      Repeated the same feat, UA-cam recommendation to the rescue. PS Thanks @WilliamFiset

    • @democreation3594
      @democreation3594 3 місяці тому

      @@Aldrin32f did the same and now I am here😁

  • @shouryasingh2193
    @shouryasingh2193 4 роки тому +76

    I just now Solved Course Schedule II on leetcode using this algo

  • @AtharvaRao0104
    @AtharvaRao0104 4 місяці тому

    @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.

  • @williamadams5034
    @williamadams5034 4 роки тому +61

    My favourite ordering is to Keep Sleeping.

  • @centr0
    @centr0 Рік тому

    Wow. I understood that. Great way of teaching. You’re amazing. Thank you, sir.

  • @cardel-qq6xp
    @cardel-qq6xp Рік тому +4

    Underwear -> pants -> shirt -> hoodie -> socks -> shoes -> school

  • @1hpdell
    @1hpdell 3 роки тому +8

    William, really appreciate your effort in making this Video! Effort behind this Animation is awesome, explanation is awesome too!

  • @dheerajgopinath1892
    @dheerajgopinath1892 2 роки тому +1

    The way you explained is simply superb!! especially the "getting ready for school" example..

  • @geniamartynova8844
    @geniamartynova8844 2 роки тому +2

    Clean and concise explanation. Easy to comprehend and remember. Thank you!

  • @njkevlani
    @njkevlani 4 роки тому +48

    TIL Superman didn't know topological sort

  • @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

  • @LUKFUNTV
    @LUKFUNTV 4 роки тому +4

    Really takes an effort to make it sooooooooooooo
    SIMPLE🙏🙏🙏🙏🙏🙌🙌🙌🙌🙌

  • @krealle
    @krealle 3 місяці тому

    Thanks!

  • @arthurcosta6185
    @arthurcosta6185 2 місяці тому

    Appreciate from Brazil! In the next week I'll have the last graph exam in Pontifical Catholic University, and you helped me a lot

  • @m.movsar
    @m.movsar Рік тому

    Лучший канал по алгоритмам! Thank you William!

  • @emwistu22
    @emwistu22 5 місяців тому

    Your videos and your teaching style are amazing!!

  • @robaczliwy
    @robaczliwy 4 роки тому +3

    Thank you for a very clear explanation. Implementation was easy once I grasped the concept you've laid out in this video.

  • @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

  • @Sunny-vl1ff
    @Sunny-vl1ff 3 роки тому +2

    Thanks! It is great to see how the algorithm works in practice.

  • @randm6uy
    @randm6uy 3 роки тому

    just looking at the playlists you made motivates me

  • @mister_mad
    @mister_mad Рік тому +1

    amazing explanation and visualization of the algorithm! a video unlike no other

  • @abhinavboyed6624
    @abhinavboyed6624 3 роки тому

    I'm about to binge watch all your videos. Thanks for the awesome content!

  • @AbrahamWilson
    @AbrahamWilson 4 роки тому +47

    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 роки тому +3

      That would surely be the best DP course on UA-cam. I love how he explains

    • @sandeepjnv13
      @sandeepjnv13 3 роки тому +3

      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

    • @pelvispresley22
      @pelvispresley22 2 роки тому

      The freecodecamp video from Alvin Zablan on DP is as good as it gets

  • @abhishektiwari7643
    @abhishektiwari7643 10 місяців тому

    Was following a course and couldn't understand this concept there but this video was so simple and better explained

  • @JeremyIglehart
    @JeremyIglehart 2 роки тому +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 роки тому +8

      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.

  • @mercyomwoyo985
    @mercyomwoyo985 Рік тому

    Thanks William for the visualization and Animation! I clearly understand the concept now!

  • @markwillis2336
    @markwillis2336 Рік тому +1

    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.

  • @przemekbary
    @przemekbary 2 роки тому

    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)

  • @shnerdz
    @shnerdz 4 роки тому +3

    great explanation as always. please make a video on segment trees next! such a powerful yet simple data structure

  • @northridgefield
    @northridgefield Рік тому

    Great clarity - quality content.

  • @Sauce-ke
    @Sauce-ke 4 роки тому

    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

  • @David-fy1sn
    @David-fy1sn 2 роки тому

    Wow great explanation in only 13 mins!

  • @NoName-ip4tt
    @NoName-ip4tt 3 роки тому

    Animation you conduct has heart beat sound as background. I like it :)

  • @hix0071
    @hix0071 4 роки тому

    Keep it up William. May you reach million subs next year !

  • @SupremeMaykr
    @SupremeMaykr Місяць тому

    This is an excellent explanation, thanks!

  • @agnelamodia
    @agnelamodia 3 роки тому

    Easy and simple. Marvelous.

  • @neerajkulkarni6506
    @neerajkulkarni6506 4 роки тому +2

    10/10 beautifully explained!

  • @fantasy9960
    @fantasy9960 2 роки тому +1

    thank you so much William! this is extremely helpful for beginners!

  • @nehascorpion
    @nehascorpion 2 роки тому +1

    Awesome content! Thank you for putting in so much effort. Appreciate it!

  • @zy3749
    @zy3749 4 роки тому +2

    Thank you so much, it is the most clear explanation I've found.

  • @tanmaykharshikar9419
    @tanmaykharshikar9419 4 роки тому

    This video is a gem, thanks! You have a new fan :)

  • @kartarsingh7776
    @kartarsingh7776 3 роки тому +1

    That was a great example(dressing up) at the start of video.

  • @sstp105
    @sstp105 3 роки тому +2

    amazing explanation!

  • @Junposs
    @Junposs 4 роки тому

    Thank you Wiliam, I finally understand what Topological Sort is!

  • @leducphuclong
    @leducphuclong Рік тому

    Thank you so much, I really appreciate your video. Please continue...

  • @Learner010
    @Learner010 4 роки тому +1

    Very nice explanation. please make a video on articulation point and bridges

  • @m-meier
    @m-meier 2 роки тому

    This was awesome! Subscribed!

  • @kevintran6102
    @kevintran6102 4 роки тому

    Good as always. So easy to understand.

  • @mickeynig1
    @mickeynig1 3 роки тому

    Thanks Mr. Fiset really awesome explanation

  • @soanonso
    @soanonso 2 роки тому

    Nicely explained - thanks for this.

  • @lambar0
    @lambar0 17 днів тому

    Clean and simple

  • @twistedlog24
    @twistedlog24 10 місяців тому

    thanks for explaning this so clearly!!

  • @LUKFUNTV
    @LUKFUNTV 4 роки тому +2

    I recommend this.........to all the before_watching_read_comments_section people 🙌🙌🙌

  • @ricardo7240
    @ricardo7240 4 роки тому +2

    Awesome, keep it up!

  • @jeehar1
    @jeehar1 3 місяці тому

    It was clear, thanks again man

  • @atharvas4399
    @atharvas4399 3 роки тому

    this is 100 times better than my algo professor

  • @avipatel1534
    @avipatel1534 3 роки тому

    Thanks this video helped me optimize my sort code for leetcode course scheduling

  • @lazysky1234
    @lazysky1234 Рік тому

    Thank you for your video, great explanation!

  • @30天冥想练习
    @30天冥想练习 3 роки тому +1

    Kahn : Implements Topological Sort.
    Superman : Am i a joke to you ? Wears underwear after pants.

  • @adityatripathi9045
    @adityatripathi9045 2 місяці тому

    great work !!

  • @yujianzhao6461
    @yujianzhao6461 4 роки тому

    Thanks a lot man! I really appreciate your work!

  • @babumon5351
    @babumon5351 4 роки тому

    Very nice explanation. Thanks

  • @jabir5768
    @jabir5768 2 роки тому +1

    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 ?

  • @algorithmscasts902
    @algorithmscasts902 4 роки тому

    Nice animation and great explanation, thank you

  • @djklsdf-32sdf
    @djklsdf-32sdf 3 місяці тому

    최고의 영상

  • @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.

  • @VijayKiran225
    @VijayKiran225 2 роки тому

    beautiful explanation .. keep up the good work.. subscribed as well

  • @shantanubapat6937
    @shantanubapat6937 4 роки тому +2

    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 3 роки тому +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.

  • @FaustoCarvalho
    @FaustoCarvalho Рік тому +1

    What tool have you used to draw and animate these graphs? Thanks

  • @ksenthu
    @ksenthu 4 роки тому

    Best explanation ever, thank you!

  • @djchrisi
    @djchrisi Місяць тому +2

    Came here from advent of code day 5 ☺

  • @geomichelon
    @geomichelon 2 роки тому

    great video! Thanks man!

  • @jisanson
    @jisanson 4 роки тому

    Thank you for this awesome video!

  • @WebSurfingIsMyPastime
    @WebSurfingIsMyPastime Рік тому

    Great Video!

  • @mostafaarafa1461
    @mostafaarafa1461 3 роки тому

    Thanks, You explained it really perfectly

  • @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.

  • @AryanPatel-wb5tp
    @AryanPatel-wb5tp 3 місяці тому

    What is run time , O(V+E) ? can someone explain line by line using the pseudocode if possible

  • @akshatmehra3951
    @akshatmehra3951 Рік тому

    You're the best man

  • @thetrainoflife8327
    @thetrainoflife8327 День тому

    fabulous !

  • @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.

  • @akidanis6984
    @akidanis6984 10 місяців тому

    holy shit this was such a great explanation, tysm!!

  • @ManishaSingh-yk5en
    @ManishaSingh-yk5en 2 роки тому

    Can we get the ppt which is being used in the video?

  • @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?

  • @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

  • @amanbhatia7442
    @amanbhatia7442 9 місяців тому

    just realized you have a similar algorithm for the dfs approach as well? , But I really like this, feels intuitive

  • @prabhat2342
    @prabhat2342 3 роки тому

    wonderful explanation, thanks man:)

  • @soumyajitchatterjee5822
    @soumyajitchatterjee5822 5 місяців тому

    Beautiful

  • @akashshirale1927
    @akashshirale1927 4 роки тому

    can u post videos on identifying kadane's algorithm for dynamic programming

  • @RushOrbit
    @RushOrbit Рік тому

    Where did you find the intro music for your videos?

  • @76lunagogogo
    @76lunagogogo 9 місяців тому

    Regarding the DAG, isn't the (3) also not he DAG as the same reason that (4) one has?

  • @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?

  • @ameynaik2743
    @ameynaik2743 3 роки тому

    Nice video, how is this different from another video you have on top sort using dfs?

  • @richa2950
    @richa2950 9 місяців тому

    Best😭❤❤❤❤

  • @aaryaibtedafoyez855
    @aaryaibtedafoyez855 20 днів тому

    can we remove 2 before 3?

  • @无名-c1f
    @无名-c1f 4 роки тому

    What drawing software to use? The picture is very nice

  • @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

  • @saralee548
    @saralee548 3 роки тому

    amazing.

  • @pamp3657
    @pamp3657 Рік тому

    very good video

  • @shreyashachoudhary480
    @shreyashachoudhary480 3 роки тому

    Awsm!

  • @bullymaguire2335
    @bullymaguire2335 Рік тому +1

    Dude just increase ur volume .no other complains .👍