Topological Sort Visualized and Explained

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

КОМЕНТАРІ • 55

  • @nivethanyogarajah1493
    @nivethanyogarajah1493 Рік тому +40

    Best explanation/visualization by far! Thank you my G!

  • @cameron7131
    @cameron7131 8 місяців тому +10

    Excellent visualization, seen many videos and this is by far the clearest. Well done

  • @eshwarprasad2541
    @eshwarprasad2541 8 днів тому

    Best explanation of Topological sort, its just DFS in reverse completion of node. That so fundamental and simple to understand

  • @thiagaodavez5465
    @thiagaodavez5465 9 місяців тому +146

    "we have explored all the children" ok then ...

    • @minimaxcoder
      @minimaxcoder 4 місяці тому +10

      bro?

    • @imralav
      @imralav 3 місяці тому +7

      hahah yeah algorithms or IT are often pretty weird when it comes to parent-children relationship

    • @thatkindcoder7510
      @thatkindcoder7510 2 місяці тому +38

      Topological sort with the Diddy algorithm

  • @mehakkamran3929
    @mehakkamran3929 2 місяці тому +3

    Nice explanation , concise and clear , suitable for learning concept ,one day before exam.

  • @evamkaushik5392
    @evamkaushik5392 Рік тому +3

    Awesome! This is spot on fundamental.
    Thanks

  • @emirhan2884
    @emirhan2884 11 місяців тому +7

    thanks carl the person😄

    • @ENTJ616
      @ENTJ616 11 місяців тому

      You are a politecnico di torino student?

    • @emirhan2884
      @emirhan2884 11 місяців тому

      @@ENTJ616 nope

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

    thank you for this visual and explaination!

  • @frozenkale9675
    @frozenkale9675 Місяць тому +3

    I am here to learn topological sort after advent of code day 5. 📝

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

      Haha same

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

      @taxatogaming I might have to write that solution! If you do write it, I'd love to see your code. As it turns out, though, day 5 was a total ordering, so I ended up solving it with quicksort.

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

    thank you! this really helped.

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

    Nice explanation.

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

    Thanks so much 🙏🙏🙏

  • @SartajGulati
    @SartajGulati 24 дні тому

    Is there any way to start on a node that has dependencies, or do you always need to start on a node with no dependncies?

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

    If I have a list of valid output nodes, how do I identify dead ends (paths that don't lead to a single valid output node) and skip them in the algorithm?

  • @hainguyendong3716
    @hainguyendong3716 Рік тому +4

    i just wonder that in the ABC, E come first so why would you choose to go with F.

    • @adhyadhyaksa
      @adhyadhyaksa Рік тому +4

      Since topological sort usually tends to have multiple solutions im guessing he just want to go to F first

    • @Oscar-vs5yw
      @Oscar-vs5yw Рік тому +2

      dfs doesn't need to occur in any order, you're fully exploring the graph anyways, there are many valid solutions, so, it just doesn't matter

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

      You can also do it that way. Please learn DFS before this algorithm

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

      you always have to go in an alpabetical order genraly

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

    Well explained

  • @MuhammadSqlain
    @MuhammadSqlain 6 місяців тому +1

    thanks!

  • @ForTheRepublicCT-4382
    @ForTheRepublicCT-4382 Рік тому +1

    good shit

  • @Oscar-vs5yw
    @Oscar-vs5yw Рік тому +2

    I guess it was as I expected, the recursive implementation seems trivial enough, I wonder how you would implement topological sort via iteration, the "go backwards" with dfs using iteration seems challenging

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

      backtracking

    • @somebodyelse9130
      @somebodyelse9130 7 місяців тому

      Backtracking is also often implemented recursively, though it doesn't have to be

  • @ohmegatech666
    @ohmegatech666 3 місяці тому +1

    So you literally just do depth-first traversal of the whole thing and store the nodes in that order?

  • @henrywillis2226
    @henrywillis2226 11 місяців тому +6

    Why did your DFS explore F before E? Am I wrong in assuming it's going in alphabetical order?

    • @jlee-mp4
      @jlee-mp4 11 місяців тому +2

      I was wondering this too… I think it just worked better with his demonstration. E being searched first would still result in a valid topological sort since B is it’s only prerequisite

    • @OatmealTheCrazy
      @OatmealTheCrazy 10 місяців тому +11

      It's arbitrary, you can flip the E and F. Them being letters is just a way to label them to communicate here. They could just as well have been farm animals or colors

    • @jlee-mp4
      @jlee-mp4 10 місяців тому

      yes! agreed@@OatmealTheCrazy

    • @Code-y4v
      @Code-y4v 5 місяців тому +2

      Yes E must be visited first . Point is dfs is always unique but topsort is not unique , we can have many topological sort sequences

    • @Code-y4v
      @Code-y4v 5 місяців тому

      Is dfs for a directed graph unique? (Considering ascii values) I’m not sure

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

    Thanks ❤

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

    great vid :)

  • @sol-iv-3609
    @sol-iv-3609 Рік тому +3

    but how are you going to K even if G points to it and he have not visited it yet?

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

    Yeah, but how we go from array to graph, we need additional functions.

  • @matinaminsabouri
    @matinaminsabouri 8 місяців тому

    thanks💯

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

    thanks broooo

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

    nice

  • @jonathanwang3714
    @jonathanwang3714 4 місяці тому +1

    Hope you always have toilet paper in the public restroom!!!

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

    i think there was a mistake:
    the first one which you return from to parent should be added to the stack, accordingly 'E' was the first one to come back after exploring to 'B' . i don't know if i am right or not but yes your ans would be right if you had not visited 'E' first. if you had visited 'F' first from 'B' then the order would have been the same as yours.

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

    I love u