Topological Sort Algorithm | Graph Theory

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024

ความคิดเห็น • 165

  • @translucentleaf6163
    @translucentleaf6163 4 ปีที่แล้ว +40

    The world needs more heroes like you who can spend less than 15 minutes explaining what takes certain professors at least two hours. This was really intuitive for both newcomers and detailed enough to actually wrote code with it. Thank you!

  • @OzoneX4
    @OzoneX4 6 ปีที่แล้ว +237

    Clear, concise, great animation! Thank you so much buddy.

    • @paranormaledits9526
      @paranormaledits9526 ปีที่แล้ว

      I read comments before watching a tutorial, thanks for the comment.

  • @alex_turing
    @alex_turing ปีที่แล้ว +2

    I searched for a video on this topic and this is the only one I found that explained it so well. Great job, I will share it with my classmates.

  • @notalex01
    @notalex01 3 ปีที่แล้ว +8

    These tutorials are excellent. I wish I could thumbs up 10 times. I'm studying for coding interviews and this is the best tool I have come across for understanding graph theory problems.

  • @mohsinhayatt
    @mohsinhayatt 5 ปีที่แล้ว +5

    This is the best explanation video for a graph algorithm. Can't get any better

  • @SrushtiPawar-vi6ns
    @SrushtiPawar-vi6ns 7 หลายเดือนก่อน +1

    The number of times I have watched this video and number of times I have forgotten this concept is really funny!

  • @miltonhuynh4209
    @miltonhuynh4209 6 ปีที่แล้ว +14

    I understood enough to complete my quiz at 1:06, great video!

  • @y2k898
    @y2k898 2 ปีที่แล้ว +2

    The fact you can clearly explain the concept and Algo under 15mins, proves you have mastered this topic and gain deep understanding, kudos.

  • @patrickchan7891
    @patrickchan7891 4 ปีที่แล้ว +13

    Omg!You are just the perfect one demonstrating these concepts so clearly.It's really friendly for beginners to learn.Thank you very much!

  • @aalekhpatel8995
    @aalekhpatel8995 4 ปีที่แล้ว +6

    I understand that I’m a bit late to the party but this is genuinely a brilliant explanation of Top Sort! Thank you so much!❤️❤️

  • @PiyushSharma95
    @PiyushSharma95 4 ปีที่แล้ว +3

    Thanks William. Watched the whole MIT DFS class for Topological sort, finally understood it here.

  • @saravanprathi6956
    @saravanprathi6956 4 ปีที่แล้ว +3

    The way you explain stuff visually helps me understand the algorithms well. Thanks a ton!

  • @akshaymalhotra597
    @akshaymalhotra597 5 ปีที่แล้ว +4

    The best explanation I could find online!

  • @garamburito
    @garamburito 3 ปีที่แล้ว

    It was not clear to me why the sorting process could starts from any node of the graph. I finally found the answear in your animiation. Thanks a lot.

  • @norcal6181
    @norcal6181 5 ปีที่แล้ว +9

    Thank you for this. I have a final in my Data Structures and Algorithms course today, and I didn't understand this subject. Now I do. Thank you.

  • @dirkvanbeveren5042
    @dirkvanbeveren5042 6 ปีที่แล้ว +21

    This is a great tutorial! Really well explained; visually and in detail.

  • @GMatos-qg4ec
    @GMatos-qg4ec ปีที่แล้ว +1

    Finally a great video! Thanks William

  • @umairalvi7382
    @umairalvi7382 3 ปีที่แล้ว +1

    The good things is you went from total basics and that's what matters for understanding

  • @sido7740
    @sido7740 2 ปีที่แล้ว +1

    An application of DAGs is representing circuits as a collection of gates, where subsequent gates require the inputs of previous gates, which is a perfect problem to use topological sorting on as it allows for iterative solutions to circuit propagation!

  • @sarfarazalam6077
    @sarfarazalam6077 4 ปีที่แล้ว +2

    Man you make difficult topic easy to understand, very nice video. It is very great , how you represent topics in abstract way:)

  • @孙贺-g5m
    @孙贺-g5m 2 ปีที่แล้ว +1

    Thank you, very clear and precise explanation.

  • @BATCHFILETUTORIALS
    @BATCHFILETUTORIALS ปีที่แล้ว +1

    Wow this tutorial is amazing! Made perfect sense to me!

  • @mrisaacs3089
    @mrisaacs3089 4 ปีที่แล้ว +1

    Another great mind at explaining things the way I like to understand them.
    First video I've seen on your channel. Instant subscribe and set notification on 'All'!

  • @Kalessin89
    @Kalessin89 4 ปีที่แล้ว +2

    Your videos are very well produced, thank you very much for the efforts you put into them! Like some other folks have said, I wish Kahn's algorithm was also covered, it is pretty intuitive too and allows for cycle detection.

    • @WilliamFiset-videos
      @WilliamFiset-videos  4 ปีที่แล้ว +2

      Thanks for the suggestion Louis, Kahns truly is a really great algorithm. It's especially good for beginners because it's soo simple and intuitive. I'll put together a video if I find the time

  • @davidm.johnston8994
    @davidm.johnston8994 3 ปีที่แล้ว +1

    Thanks a lot William ! This is really helpful.

  • @gokulkumarbhoomibalan5413
    @gokulkumarbhoomibalan5413 3 ปีที่แล้ว +1

    Clean, precise, awesome!!

  • @sanskarsharma9494
    @sanskarsharma9494 3 ปีที่แล้ว +1

    Thanks for this amazing video !

  • @Hugesbaz
    @Hugesbaz 3 หลายเดือนก่อน

    Great explanation! Thank you.

  • @live_mocha
    @live_mocha 5 ปีที่แล้ว +3

    This video saved so much time. God bless you pal : ))

  • @Anubis10110
    @Anubis10110 4 ปีที่แล้ว +1

    Thank you so much, so clear and concise.
    Appreciate it.

  • @chinmaygajjardeveloper
    @chinmaygajjardeveloper 2 ปีที่แล้ว

    Thank you for great explanation!

  • @anthonylee815
    @anthonylee815 3 ปีที่แล้ว +2

    The tree example is unconnected with your algorithm for TopSort; If the TopSort algorithm is using indegree then the tree example will be really good as an introduction as they are using similar idea. It'd be great if you could always explain the runtime complexity. For this one, why it is O(V+E)?

  • @harinijeyaraman8789
    @harinijeyaraman8789 3 ปีที่แล้ว

    Loved this !!!! Thaaaaanks a bunch ! Well explained !!

  • @yangwilliam3137
    @yangwilliam3137 ปีที่แล้ว

    GREAT, love the animation.

  • @khadijaashraf
    @khadijaashraf หลายเดือนก่อน

    nice explanation.!

  • @mtjokro
    @mtjokro 3 ปีที่แล้ว

    Amazing viz, thank you!

  • @08JuHan
    @08JuHan 2 ปีที่แล้ว

    kudos! thanks a lot for posting

  • @rizkimaulana7331
    @rizkimaulana7331 10 หลายเดือนก่อน

    THANK YOU SO MUCH

  • @huuarethey
    @huuarethey 3 ปีที่แล้ว

    thank you william

  • @BreadWinner330
    @BreadWinner330 4 ปีที่แล้ว

    Thanks man, you're the best!

  • @kmishy
    @kmishy 3 ปีที่แล้ว

    Lots of hard work sir

  • @JieWei7912
    @JieWei7912 4 หลายเดือนก่อน

    Thank you.

  • @raymondyoo5461
    @raymondyoo5461 5 ปีที่แล้ว

    Wow Thanks so much. Animation helped a lot

  • @oussamaabdelwahed5594
    @oussamaabdelwahed5594 3 ปีที่แล้ว

    GREAT explanation , Thank's

  • @LightningSpeedtop
    @LightningSpeedtop ปีที่แล้ว

    Simply beautiful

  • @nguyenvankhanhduy3958
    @nguyenvankhanhduy3958 3 ปีที่แล้ว

    Great content man.

  • @japhethobala3753
    @japhethobala3753 3 ปีที่แล้ว

    Thanks a lot.

  • @nursultanmuratov1705
    @nursultanmuratov1705 11 หลายเดือนก่อน

    Hi, First of all thank you for your explanation. I find your videos very helpful. But I have a question about the example code of your git repository about topological sort.
    graph.get(0).add(new Edge(0, 1, 3));
    graph.get(0).add(new Edge(0, 2, 2));
    graph.get(0).add(new Edge(0, 5, 3));
    graph.get(1).add(new Edge(1, 3, 1));
    graph.get(1).add(new Edge(1, 2, 6));
    graph.get(2).add(new Edge(2, 3, 1));
    graph.get(2).add(new Edge(2, 4, 10));
    graph.get(3).add(new Edge(3, 4, 5));
    graph.get(5).add(new Edge(5, 4, 7));
    int[] ordering = topologicalSort(graph, N);
    // // Prints: [6, 0, 5, 1, 2, 3, 4]
    System.out.println(java.util.Arrays.toString(ordering));
    So my question: if node 6 doesn't have relation with any node in any role, why the program return array : [6, 0, 5, 1, 2, 3, 4]?

    • @WilliamFiset-videos
      @WilliamFiset-videos  10 หลายเดือนก่อน

      Node 6 doesn't have any dependencies, and no other node depends on it, therefore it can be placed anywhere in the topological ordering

  • @Mydoritosontheground
    @Mydoritosontheground 27 วันที่ผ่านมา

    Thanks!

  • @ngbtvezadtht
    @ngbtvezadtht 2 หลายเดือนก่อน

    any reason why you use a list and have to worry about/handle an index, when you could just use a stack? and pop from stack to get the ordering? it seems much easier to do without having to code up extra stuff to handle the index.

  • @conde3915
    @conde3915 11 หลายเดือนก่อน +21

    can you explain it in fortnite terms?

  • @gaurishgangwar
    @gaurishgangwar 5 วันที่ผ่านมา

    Will this algorithm work if the graph has cycle? Or being a DAG is a prerequisite for using this algorithm?

  • @greaterthanKTWS
    @greaterthanKTWS 6 ปีที่แล้ว

    Awesome work man.

  • @maksimisayenka2058
    @maksimisayenka2058 2 ปีที่แล้ว

    great video

  • @ra-ph-ael
    @ra-ph-ael 4 ปีที่แล้ว

    This is sooo good!

  • @jasonli1060
    @jasonli1060 3 ปีที่แล้ว

    BEAUTIFUL

  • @contactdi8426
    @contactdi8426 5 หลายเดือนก่อน

    Lovely!

  • @californiaflying6637
    @californiaflying6637 ปีที่แล้ว +1

    Might be good to explain how to use the topo sort result to then actually solve the course scheduling problem (for example).

  • @enoshcohen
    @enoshcohen 3 ปีที่แล้ว

    Thank you for this video!
    What happens in a case that we have a cycle. I'm pretty sure that the algorithm that you provided does not cover this end-case.

    • @deepakr.sastry756
      @deepakr.sastry756 3 ปีที่แล้ว +1

      You can't topologically sort a graph that has a cycle. 3:45

    • @enoshcohen
      @enoshcohen 3 ปีที่แล้ว

      @@deepakr.sastry756 that’s correct.
      You still need to check end cases. A user can input a graph that is not a DAG.

    • @deepakr.sastry756
      @deepakr.sastry756 3 ปีที่แล้ว

      @@enoshcohen 4:39 check using Tarjan's

  • @iitianexplains6405
    @iitianexplains6405 3 ปีที่แล้ว

    THANKS

  • @alicianguyen2625
    @alicianguyen2625 ปีที่แล้ว

    Why is it important that we only append the value when we're finishing the recursive call, and then reverse it, rather than appending when we mark a node as visited and not needing to reverse the output?

  • @jingchaozhang408
    @jingchaozhang408 4 ปีที่แล้ว

    10:59 We already has an array V to record the visited node. Why do you define another array visitedNodes?

  • @usman8872
    @usman8872 2 ปีที่แล้ว

    if i have to reach D, the array says , i have to visit K ???

  • @studytime4048
    @studytime4048 3 ปีที่แล้ว

    In case of a rooted tree, is it sufficient to do the level order traversal to get the topological ordering?

  • @XnDxNdXnD
    @XnDxNdXnD 5 ปีที่แล้ว

    Exellent work

  • @huzaifaaejaz9648
    @huzaifaaejaz9648 6 ปีที่แล้ว +1

    Can you also do a video based on Kahn's Algorithm for topological sort, based on inDegrees rather than outDegrees?

  • @jadanabil8044
    @jadanabil8044 3 ปีที่แล้ว

    SSSP finding using topological sort approach, when would I not use this? Seems fastest for the usecase.

  • @seanfitz81
    @seanfitz81 4 ปีที่แล้ว

    topological orderings are not necessarily unique, but they can be unique.

  • @lautarolavecchia5995
    @lautarolavecchia5995 5 ปีที่แล้ว

    very useful

  • @DiggOlive
    @DiggOlive 5 ปีที่แล้ว +2

    the short form that I've heard is "toposort" rather than "topsort"

  • @giwrgoscy294
    @giwrgoscy294 ปีที่แล้ว

    Thanks mom

  • @aatifnazar8203
    @aatifnazar8203 4 ปีที่แล้ว

    nice! and neat!

  • @a.yashwanth
    @a.yashwanth 4 ปีที่แล้ว +1

    You are 3blue1brown for computer science.

  • @harsha4692
    @harsha4692 4 ปีที่แล้ว

    9:17 from the given solution , K is given before I but K does not have a path to I. Is it supposed to happen,can you please tell me?

  • @ahmedelsabagh6990
    @ahmedelsabagh6990 4 ปีที่แล้ว

    Great

  • @IgraphyRupage
    @IgraphyRupage 6 ปีที่แล้ว

    You rock!

  • @alxous4251
    @alxous4251 2 ปีที่แล้ว

    great video if you play it in 1.5x speed

  • @swordclash6618
    @swordclash6618 5 ปีที่แล้ว

    I don't understand why we need to make a visitedNodes array when we already have V...

  • @amalbiju7805
    @amalbiju7805 ปีที่แล้ว

    python implementation:
    ```graph = [[1, 2, 3], [5], [], [], [2, 3], [2]]
    visited = [False] * len(graph)
    ordering = list()


    def dfs(node):
    visited[node] = True
    for neig in graph[node]:
    if not visited[neig]:
    dfs(neig)
    ordering.insert(0, node)


    for i in range(len(graph)):
    if not visited[i]:
    dfs(i)
    print(ordering)```

  • @DontTakeCrack
    @DontTakeCrack ปีที่แล้ว

    seems like they should just call it a DAG sort instead of topological sort.

  • @hexadecimalhexadecimal5241
    @hexadecimalhexadecimal5241 3 หลายเดือนก่อน

    ......WOW

  • @eug_gino
    @eug_gino 5 ปีที่แล้ว +3

    thanks so much, may I ask, what do you mean by "canonical" example? (1:59)

    • @SchoolVideosGoHere
      @SchoolVideosGoHere 4 ปีที่แล้ว +4

      canonical (adj)
      MATHEMATICS
      relating to a general rule or standard formula.
      Basically, it just means this is a very common example throughout computer science, often used when teaching or describing the topic (toposort that is).

  • @mathuratudu7271
    @mathuratudu7271 6 ปีที่แล้ว

    suscribed

  • @ttsgdksl
    @ttsgdksl ปีที่แล้ว

    I would prefer if you have your voice a little louder

  • @blueyc4rter
    @blueyc4rter 4 ปีที่แล้ว

    Could be more concise, but good video.

  • @PriyanshulGovil
    @PriyanshulGovil 3 ปีที่แล้ว +1

    Could this animation BE ANY better!?

  • @andreibozantan
    @andreibozantan 8 หลายเดือนก่อน

    This is not handling possible cycles in the data. Also, is a recursive approach a good practical choice, considering the possibility of stack overflows?

  • @yanningzhu4940
    @yanningzhu4940 5 ปีที่แล้ว

    why do not start for in-degree is 0??????

  • @MTB_Bay_Area
    @MTB_Bay_Area 2 ปีที่แล้ว

    How will you do this on an unconnected graph? for example if you had 3 more nodes that were graph that stand next to your graph. I think, in this case you will have to have a graph class and run the DFS on each node until you finish the list of nodes.

    • @mprasanth18
      @mprasanth18 ปีที่แล้ว +1

      the algorithm shown in the video will also cover the secnario metioned in this comment.

  • @kicksomeup6998
    @kicksomeup6998 4 ปีที่แล้ว

    Mark Zuckerberg is an awesome teacher.

  • @michi5647
    @michi5647 ปีที่แล้ว

    Bro really said it's not that hard n precedes to say dig until bedrock😂

  • @spacecowboy5863
    @spacecowboy5863 หลายเดือนก่อน

    bro sounds like he divorced the day before

  • @SantoshKumar-bu2qr
    @SantoshKumar-bu2qr 5 ปีที่แล้ว

    oh boi

  • @trevordavis261
    @trevordavis261 2 ปีที่แล้ว +1

    get a pop filter bro

  • @SSky2195
    @SSky2195 6 ปีที่แล้ว +1

    you can't start with H, it depends on D... start with C

    • @WilliamFiset-videos
      @WilliamFiset-videos  6 ปีที่แล้ว +5

      Hi, it doesn't matter where the DFS(s) starts. Remember that we're adding nodes in reverse order to our top sort ordering on the recursive callbacks so that the final result is in the correct ordering.

  • @varunreddy2479
    @varunreddy2479 5 ปีที่แล้ว

    Watch it in 2x.

  • @anuruddhapremalal
    @anuruddhapremalal 5 ปีที่แล้ว +2

    This implementation doesn't take care of the cycles. Here's a link to a good explanation for topsort with cycle handling leetcode.com/articles/course-schedule-ii/?page=2

  • @הדרוויקטורסוקולובסקי
    @הדרוויקטורסוקולובסקי ปีที่แล้ว

    GOOD, BUT YOU SPEAK WAY TO SLOW.

  • @Lime-rr6te
    @Lime-rr6te 4 ปีที่แล้ว +3

    its the best video ever uploaded to you tube.
    EVER,
    LIKE FOR EVER.
    (DABs like a boss)
    God Damm it feels good to be me.

    • @Lime-rr6te
      @Lime-rr6te 4 ปีที่แล้ว +1

      This guy knows how to live life

  • @MotivationYoucanandyouwi-hg2zt
    @MotivationYoucanandyouwi-hg2zt ปีที่แล้ว +1

    Thanks a lot for this video, the algoritham is easy to understand because of the animation!