AVL trees in 5 minutes - Intro & Search

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • Introduction to AVL trees including the search method.
    Code: github.com/msambol/dsa/tree/m...
    Sources:
    1. UW-Madison Data Structures 2011 [web.archive.org/web/201907311...]
    2. Ben Pfaff, Performance Analysis of BSTs in System Software [web.stanford.edu/~blp/papers/...]
    3. Shivali Bhadaniya & FavTutor, AVL Tree in Python [favtutor.com/blogs/avl-tree-p...]
    4. en.wikipedia.org/wiki/AVL_tree
    LinkedIn: / michael-sambol

Комментарии • 33

  • @Nickdabulder
    @Nickdabulder 5 месяцев назад +2

    Thank you so much, idk why I was struggling so much with other explanations

  • @sarvarbazarov8858
    @sarvarbazarov8858 10 месяцев назад +1

    thanks a lot for your videos, they are quite simple and informative !

  • @imnotme9757
    @imnotme9757 9 месяцев назад +1

    I just discover this channel and u, thanks a lot for this video so clean. Big up for u!!!!

  • @zivmax
    @zivmax 8 месяцев назад

    Great video, brilliant teacher

  • @DominicI1
    @DominicI1 Год назад +1

    Awesome video, thanks.

  • @bennikllr5509
    @bennikllr5509 Год назад +6

    Nice Video! i like your short videos.
    isn`t the height defined as number of edges from the root node to the leaf node, so in your example it would be 4 at 50?

  • @slightly_trash5173
    @slightly_trash5173 Год назад +1

    Heyy just in time🎉

  • @migueltmpereira
    @migueltmpereira 4 месяца назад +1

    My professor shows us some of your videos sometimes during class ( algortithms and data structures). Big up!

  • @NZ-bg9ec
    @NZ-bg9ec 5 месяцев назад

    in 02:35 in the not avl tree, is it not avl tree to becuase the left child (25) and the right child (75) differs also more than 1? as 3-1=2

  • @VaibhavS28
    @VaibhavS28 7 месяцев назад +1

    Thanks!

  • @ayoub8393
    @ayoub8393 Год назад +2

    To calculate the Balance factor, dont we need to use "Right subtree - Left subtree"? Because in ur example it seems like ur calculating it with "Left subtree - Right subtree". Thats the values are inverted when it comes to positive or negative. Or am I just tripping??
    Still very nice playlist, the RB Tree one was very useful.

    • @MichaelSambol
      @MichaelSambol  Год назад +3

      can go either way! just requires some code changes. github.com/msambol/dsa/blob/master/trees/avl_tree.py

  • @kvelez
    @kvelez 7 месяцев назад

    Perfect.

  • @artem2060
    @artem2060 Год назад +6

    He is alive

  • @jamesclarit1619
    @jamesclarit1619 3 месяца назад

    why is height not zero at leaf nodes?

  • @triple7triple3zero
    @triple7triple3zero Месяц назад

    Am I tweaking? I thought the height was the number of edges. Like if you had A->B->C, the height would be 2.

  • @fredericoamigo
    @fredericoamigo 7 месяцев назад

    Great vid! But why is the height variable set to 1 upon instantiation?

    • @aghaaslam9575
      @aghaaslam9575 7 месяцев назад +1

      Most of the time you would set height of the leaf to 0 but you could say leaf height is 1 if you actually count Null-Nodes (meaning: in this case both of children are null, because we are talking about leaf) as height of 0. Nevertheless if we are trying to calculate the balance factor, we only need the difference between the height of right children and left children.
      I encourage you to try to visualize your self (draw a tree, and calculate the balance tree. Try to change the leaf default heights), you will see that both cases will result in the same balance factor if by both cases you are using the same tree. I hope it explained your concern. If you still have doubts, try to ask someone or use AI to have it visualize for you.

  • @oanminhquan1217
    @oanminhquan1217 7 месяцев назад

    Is there any difference between the big-O with the "-" in the middle with the big-O without it?

    • @David-hl9iv
      @David-hl9iv 5 месяцев назад +3

      Yes, there is a significant difference. The big-O complexity gives you the upper bound on time complexity of your function given an input of size n, for example O(n^2), meaning that the function will perform at most c*n^2 operations.
      Big-Theta on the other hand gives you both the upper and the lower bound for the time complexity. That means that if the function runs in big-Theta of n^2 then you have to perform a minimum of c_0*n^2 operations and a maximum of c_1*n^2 operations. In time complexity analysis though the constants are ignored because the primary goal of analyzing time complexity is finding out how much slower we get as we make the input larger and not the precise number of operations. If you are interested in learning more I would suggest you read the Wikipedia article on Big O notation where each notation is explained and where you can see more examples, as well as the mathematical definitions of big-O and such.

    • @oanminhquan1217
      @oanminhquan1217 5 месяцев назад

      ​@@David-hl9iv Thanks a lot. Really appreciate your explanation!

    • @skatlag
      @skatlag 9 дней назад

      @@David-hl9iv, well is it possible to go from log(n) insert and delete operations, to constant? 2:50

  • @Vincent-qh4rg
    @Vincent-qh4rg 11 месяцев назад

    🐐

  • @ccs8766
    @ccs8766 11 месяцев назад +4

    shouldn't the height of the first node will be 4?

    • @JM-nn4oe
      @JM-nn4oe 9 месяцев назад

      yes the height of the root should be 4. the height of an empty tree is -1, leaf nodes is 0. he still gets the same balance factors though via his approach.

  • @rahilhil1085
    @rahilhil1085 8 месяцев назад

    Plz do the root insertion

  • @jimj2683
    @jimj2683 8 месяцев назад +7

    Wrong! The height of leaf nodes is always 0. Not 1.

    • @epotnwarlock
      @epotnwarlock 8 месяцев назад

      What does this change?

    • @jwine1957
      @jwine1957 8 месяцев назад +3

      ​@@epotnwarlockwhen you compute the total height of the tree you get the correct value instead of the wrong value 😂

    • @epotnwarlock
      @epotnwarlock 8 месяцев назад

      crazy i guess 2 - 1 is different than 1 - 0 @@jwine1957​

    • @aghaaslam9575
      @aghaaslam9575 7 месяцев назад

      It depends on how you code (implement) this AVL-Tree. Most of the time you would set height of the leaf to 0 but you could say leaf height is 1 if you actually count Null-Nodes (meaning: in this case both of children are null, because we are talking about leaf) as height of 0. Nevertheless if we are trying to calculate the balance factor, we only need the difference between the height of right children and left children.
      I encourage you to try to visualize your self (draw a tree, and calculate the balance tree. Try to change the leaf default heights), you will see that both cases will result in the same balance factor if by both cases you are using the same tree. I hope it explained your concern. If you still have doubts, try to ask someone or use AI to have it visualize for you.