Red-black trees in 4 minutes - Intro

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

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

  • @arpitchristy9788
    @arpitchristy9788 3 года назад +131

    I still remember in past, I had to go through a long list to find his video. Now, when I searched it, it came on top! :D

    • @ThomasEdits
      @ThomasEdits 9 месяцев назад +4

      if only you could go through a red black tree instead

    • @dennisekiller
      @dennisekiller 9 месяцев назад

      @@ThomasEdits GO SLEEP, UNI TOMORROW

  • @DarkDay2012
    @DarkDay2012 3 года назад +34

    Studying for a Data Structures Final and your videos are really about to save me. Thanks man

  • @EskyDinpuiaChhangte
    @EskyDinpuiaChhangte 5 лет назад +90

    A red-black tree is a binary tree that satisfies the following red-black properties:
    1. Every node is either red or black.
    2. The root is black.
    3. Every leaf (NIL) is black.
    4. If a node is red, then both its children are black.
    5. For each node, all simple paths from the node to descendant leaves contain the
    same number of black nodes.

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

      Y’all be qouting CLRS for real

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

      y u repeating the vid is 4 min long

  • @sj1997
    @sj1997 7 лет назад +2

    dude you just nailed it simple short precise and a clear explanation no trash talking respect from india man

  • @ata500
    @ata500 7 лет назад +16

    Thank you! This was so much easier to understand then my school textbook. You speak clearly and concisely. Great visuals and loved the short video time!

  • @ante1337
    @ante1337 6 лет назад +27

    Note: Leafs with value Null (aka NIL) are by default Black. This means a representation of a tree with a red "Leaf" can correctly be a Red-Black Tree since its children are Null, which are Black.

  • @EskyDinpuiaChhangte
    @EskyDinpuiaChhangte 5 лет назад +64

    A red-black tree is a binary search tree with one extra bit of storage per node: its
    color, which can be either RED or BLACK. By constraining the node colors on any
    simple path from the root to a leaf, red-black trees ensure that no such path is more
    than twice as long as any other, so that the tree is approximately balanced.

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

      Y’all be qouting CLRS for real

  • @Tourach74
    @Tourach74 3 года назад +5

    I am struggling for few hours ow to understand Red-black trees, and your videos are finally the ones that made it clear to me. Thanks and congrats! You won a new subscriber :)

  • @MichaJabczynski
    @MichaJabczynski 8 лет назад +89

    Great videos, very clear and understandable. Keep up the good work!

  • @Salamandolo
    @Salamandolo 6 лет назад +318

    rut

  • @ca4307
    @ca4307 3 года назад +3

    u say root funny, but thanks for the clear and concise explanation!

  • @yadhunandhanr7590
    @yadhunandhanr7590 6 лет назад +5

    I love the way the video is made. Perfect!!

  • @honglichen4670
    @honglichen4670 5 лет назад +3

    I was confused that the Node 5 is black. However, when I watched the video again, It just said all red nodes have black nodes children, but not all black nodes have red children. So, the reason why Node 5 is black is to have the same black height. Right?

  • @juliajeehyunkim
    @juliajeehyunkim 3 года назад

    This is AWESOME. Love this video, hope you become more famous

  • @NirajSingh-nv2jb
    @NirajSingh-nv2jb 6 лет назад +7

    Best and simplest explanation on insertion of R-B tree on youtube. Please upload video on deletion.

  • @ryandavis7506
    @ryandavis7506 8 лет назад +9

    Absolutely killing it, dude. Keep going and don't stop. Easy subscribe. Thx.

    • @regisschulze6678
      @regisschulze6678 7 лет назад +4

      yeah man I feel ya even subscribed my grandma without her knowing

  • @muralikrishnaraju
    @muralikrishnaraju 7 лет назад +19

    Aren't 9,13 and 23 leaf nodes.. Can I know why they are in red and not in black ? Please help me understand..

    • @MichaelSambol
      @MichaelSambol  7 лет назад +5

      The leaf nodes are actually their NIL children.

    • @muralikrishnaraju
      @muralikrishnaraju 7 лет назад

      Thanks for the answer. Isn't the same case for 5 as well? Can I know why 5 is seen as a leaf node when it is having NIL children?

    • @MichaelSambol
      @MichaelSambol  7 лет назад +3

      5 isn't a leaf. Just because a node is black doesn't mean it's a leaf (see: 8, 12, 19).

    • @muralikrishnaraju
      @muralikrishnaraju 7 лет назад

      Thank you

    • @jbob2015
      @jbob2015 7 лет назад

      These videos are amazing keep up the good work and you'll make it big in no time

  • @firezdog
    @firezdog 5 лет назад +4

    I'm not sure what you mean when you say they have a guaranteed height of O(log n) -- I thought O() is used to characterize performance -- and you could just say that the guaranteed height is < log n...

    • @matthewrenze5922
      @matthewrenze5922 4 года назад +1

      It is, but the definition of O(n) is more general than that. Most functions f(x) are equal to O(g(x)) for some g(x), and in a balanced binary search tree such as a red-black tree, height is a function of the number of nodes.

  • @ethanraymosqueda3780
    @ethanraymosqueda3780 7 лет назад +1

    when it says that all paths from a node to its NIL descendants contain the same number of black nodes, how many black nodes does node(9) have? Does it have 1? if so doesn't node(8) have 2 black nodes to NILL?

  • @Makwayne
    @Makwayne 2 года назад +1

    Me watching on 2x "red-black trees in 2 minutes"

  • @fasihkhan8633
    @fasihkhan8633 6 лет назад +1

    No words ... hoW to be thankful
    Great tutorial🔥👍

  • @王冠信-o1c
    @王冠信-o1c 4 года назад +1

    Why the 5 on the left side isn't red?

  • @Cyber_Jutsu
    @Cyber_Jutsu Год назад

    excellent series!

  • @billpetrak
    @billpetrak 6 лет назад +3

    I wish you had also included deletions in your r-b trees series. Good explanations though.

  • @mohammadmohammadian6706
    @mohammadmohammadian6706 Год назад

    upload more man you are amazing

  • @jackc451
    @jackc451 3 года назад +1

    Am I right in saying that the example is not a R-B Tree because it's not balanced? There is a difference in height of 2 between the left and right sub trees from the root. The video is like 5 years old now, but I just wanted to ask for my own clarity :)

    • @Kikiri197
      @Kikiri197 Год назад

      i don't know if it would be still helpfull, but R-B tree doesn't have to be AVL tree (the condition you have mentioned). R-B trees have different conditions for "being balanced"

  • @stephenhowe4107
    @stephenhowe4107 4 года назад

    Insert and Delete require rotations and recolorations, sometimes both.

  • @shivanshpradhan8860
    @shivanshpradhan8860 7 лет назад +1

    very well explained in short time

  • @geezer2450
    @geezer2450 7 лет назад

    This (and your other videos) were very helpful! Thank you very much.

  • @Kevin-jf6jw
    @Kevin-jf6jw 4 года назад

    Wonderful one! Btw, where is the node-removing part? Thanks.

  • @mrmansir3734
    @mrmansir3734 Год назад

    I know you mentioned that the RBTs are balanced, but it should also be one of the criteria at 1:15

    • @ThomasEdits
      @ThomasEdits 9 месяцев назад

      due to the criteria 3 + criteria 4, it must always be the case that it is roughly balanced since worst case longest path alternates black and red nodes while the shortest one has full black
      -> height ratio between the two children of a node can never be worse off than 1:2

  • @mrmansir3734
    @mrmansir3734 Год назад

    but why do nodes turn red sometimes? wasnt explained it NVM seems you explain it in diff video. Thats just the algorithm, we insert each node as red but change it to black if we have to match the rules.

  • @rishabhjain2404
    @rishabhjain2404 7 лет назад +3

    One of the best sources to learn and revise. Kindly add more videos on concepts like AVL trees, Splay trees etc. Also, can you do a video on random sampling, which is hot topic of interviews these days and I see no one has made on it on RUclips yet.

  • @thomasfischer9289
    @thomasfischer9289 6 лет назад +1

    What about node 5? That node is black and has two black children (both nil). It seems like it should be red as well.

    • @oliverm4633
      @oliverm4633 5 лет назад

      I had the same question.... Please somebody explain

  • @drrpedpeppadsa
    @drrpedpeppadsa 2 года назад

    Good video. I wish you revisited the unbalanced example that is the reason for using a red-black tree (binary search tree with all children nodes being lesser).

  • @ruiqiliu3114
    @ruiqiliu3114 2 года назад

    Clearly explained, thank you!

  • @toastyshrimp1882
    @toastyshrimp1882 2 года назад

    what are the other ways to balance a BST besides red black trees?

  • @antwanwimberly1729
    @antwanwimberly1729 Год назад

    Can you clarify what a NIL descendant is instructor ?? We need more context and clarity.

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

      "NIL" is just the term used for any empty (not used) slots
      if a node does not have a left-child, the left-child is "NIL" / NULL

  • @anukoolsrivastava4235
    @anukoolsrivastava4235 7 лет назад

    to the point and clear enough

  • @KingUnity22
    @KingUnity22 4 года назад

    but how do we determine whether a node is red or black?

  • @markmcdonnell
    @markmcdonnell 5 лет назад

    For point 4. "All paths from a node to its NIL descendants contain the same number of black nodes" is that meaning counting from _any_ node to a nil or specifically from the root to a nil?
    Because if it's the latter, then in the given example that makes sense (5 to nil = 2, 12 to nil = 2, 19 to nil = 2), but then what happens if I insert "24" to this tree and it's added to the right of the red "23"?
    As far as I can tell we no longer have root to nil counts being 2, but 3 if we were to look for "24" (e.g. 19 to 24 to nil = 3).
    It seems I have misunderstood the meaning behind this particular point?

    • @harbl2479
      @harbl2479 5 лет назад

      @Mark McDonnell When inserting there are specific rules to follow as well. Are you sure you got those right? Otherwise you don’t end up with a valid rb tree

  • @marcofontana8308
    @marcofontana8308 4 года назад

    frate ti adooroo sei un grande

  • @palandersmuhlbradt5705
    @palandersmuhlbradt5705 6 лет назад

    why is node red and black? have the colour any meaning?

  • @tecnaharmonix3416
    @tecnaharmonix3416 3 года назад

    Please make a video on deletion too

  • @jackkirby5287
    @jackkirby5287 3 года назад

    What is a NIL node?

  • @TheLoyalpain
    @TheLoyalpain 7 лет назад +125

    I liked everything except the way you pronounce root... Otherwise very helpful!

    • @MichaelSambol
      @MichaelSambol  7 лет назад +33

      I've always said it weird. :)

    • @nabinkhadka7168
      @nabinkhadka7168 6 лет назад +20

      What is weird about the way he pronounces root? Sounds normal to me.

    • @antoniojg-b8284
      @antoniojg-b8284 6 лет назад +3

      "rewt" vs "ruet"

    • @codyromano7868
      @codyromano7868 6 лет назад +1

      I didn't mind that at all. It added character to the (already well done) explanation. :)

    • @valeskavictoria1278
      @valeskavictoria1278 5 лет назад +7

      @@nabinkhadka7168 He pronounces it as if there aren't any "o"s in the word. It isn't correct or considered to be a normal pronunciation in most of the anglophone world. It's not bad or ugly, but it isn't correct and is indicative of his dialect and region. I would imagine he is from some place in the south of the US, though there are other pockets of similar dialects in the U.S (I don't know about other countries, maybe Canadians do that too sometimes.) I don't say this to shame him or anything, he speaks perfectly fine and I sort of like that pronunciation a little bit, I am only saying this because it seems like English might not be your first language so I just wanted to help. That's all :)

  • @ahmadrezamoodi6603
    @ahmadrezamoodi6603 6 лет назад

    nice and simple.it was all i needed thanks

  • @leenlovesdancing3561
    @leenlovesdancing3561 6 месяцев назад

    Thank you so much! ☺

  • @CaveDave
    @CaveDave 3 года назад +2

    to be honest, I did not understand everything in this video. E.g. 1:50 . All paths from a node..... then you add "1" and a "2" next to the five. Don't know what are you counting there, dont know what the numbers are related to?! If you count the NILs then just put the 1 to the left NIL and the 2 to the right NIL....

  • @Do-Your-Work
    @Do-Your-Work Год назад +1

    This line " red nodes have black children ".

  • @daniellarson8291
    @daniellarson8291 4 года назад +1

    Shouldn't 5 be red?

  • @ayushagarwal4253
    @ayushagarwal4253 Год назад

    Nice video.
    Can you also make one on Tries please?

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

      will add it to the list 👍🏼 taking a small break to finish some other projects, but will be back.

  • @randomhappyguy6719
    @randomhappyguy6719 5 лет назад

    Update: I see. A "Nil" node is black.
    I don't understand 2:27 about the Black Height. Not counting the root, the black height of the tree should be 1 instead of 2?

    • @Vipe12358
      @Vipe12358 5 лет назад +1

      nil is a black node, so you have to count them as well

  • @dogemaester
    @dogemaester 6 лет назад

    Wow great job! I love this!

  • @alfredoespinozapelayo
    @alfredoespinozapelayo 5 лет назад

    Why is node 5 black?

  • @melbexdeleon8951
    @melbexdeleon8951 6 лет назад

    GREAT videos man!

  • @crunkbucha4667
    @crunkbucha4667 5 лет назад

    why is the height two when there's only one black root in the paths to the NIL nodes not counting the root

    • @lzurzolo
      @lzurzolo 5 лет назад

      Because every NIL leaf is itself black and is therefore counted in the black height of a node

  • @chrisjasonmcqueen
    @chrisjasonmcqueen 5 лет назад

    Awesome video thanks for sharing!

  • @pedroalbertogomes3809
    @pedroalbertogomes3809 6 лет назад +1

    Hi, I'm teacher at a public university in Brazil. May use your material?

    • @MichaelSambol
      @MichaelSambol  6 лет назад +1

      Sure! Just let them know where you found it.

  • @lingyongwang2817
    @lingyongwang2817 6 лет назад

    This is great! Thanks for sharing!

  • @bipinkori4060
    @bipinkori4060 6 лет назад

    Thank you very much

  • @RedPandaDesu
    @RedPandaDesu 6 лет назад

    Good summary of CLRS 3e chapter 13.1.

  • @ultrafalling
    @ultrafalling 6 лет назад

    Great useful content! Thanks

  • @ioanabiris3472
    @ioanabiris3472 Год назад

    Thank you!!

  • @kaustubhpandey9654
    @kaustubhpandey9654 5 лет назад

    Great video!

  • @trollerninja4356
    @trollerninja4356 6 лет назад +1

    y is 5 not red?

  • @oliveruhlar351
    @oliveruhlar351 5 лет назад

    Can R-B Tree contain only black nodes ?

    • @77Raffi77
      @77Raffi77 5 лет назад

      Yes, e.g. if the tree only has a root

  • @Aerosmithism
    @Aerosmithism 7 лет назад

    Why do NILs have no values (and are not represented as regular Nodes)?

    • @ThomasEdits
      @ThomasEdits 9 месяцев назад

      "NIL" is just the term used for any empty (not used) slots
      if a node does not have a left-child, the left-child is "NIL" / NULL

  • @alandawkins8297
    @alandawkins8297 6 лет назад

    very elegant.

  • @jeremylee4048
    @jeremylee4048 2 года назад

    thank you

  • @de9989
    @de9989 5 лет назад

    nice video,thanks bro

  • @Jeff-zc6rr
    @Jeff-zc6rr 9 месяцев назад +1

    You actually don't explain why a node is red.

    • @iulianalexandrudragan5531
      @iulianalexandrudragan5531 8 месяцев назад +1

      I think it arises naturally from the 4th rule

    • @Craffunky
      @Craffunky 6 месяцев назад

      To have the same number of black nodes you need to add red nodes

  • @buzayehuyitbarek3877
    @buzayehuyitbarek3877 5 лет назад

    10q Mr Michael

  • @dmytromarchuk3023
    @dmytromarchuk3023 4 года назад

    succinctly, like

  • @mohamednofal5256
    @mohamednofal5256 5 лет назад

    thanks mic

  • @hurrykrishna
    @hurrykrishna 8 лет назад

    thank you. made easy!!

  • @pustkaimrok
    @pustkaimrok 6 месяцев назад

    still no answer why a node is red

  • @fireguardianx
    @fireguardianx 3 года назад

    I might be wrong, but you sound just like the Khan Academy guy for calculus...

  • @harrisonn9792
    @harrisonn9792 2 года назад

    Thank YOu

  • @fethiourghi
    @fethiourghi 5 лет назад

    thanx

  • @Nevverglow
    @Nevverglow 4 года назад

    this is gonna be called Red-block tree soon

    • @jmm00702
      @jmm00702 4 года назад

      red-afroamerican tree 4Head

  • @rohitippili3834
    @rohitippili3834 6 лет назад

    Thanks sir

  • @ZandPyr
    @ZandPyr 11 месяцев назад

    This is helpful but the talking is very slow.

  • @dhruvamishra5857
    @dhruvamishra5857 7 лет назад

    pls upload more videos

  • @TonyKaku-g8n
    @TonyKaku-g8n 5 лет назад

    You know, every node has a black parent at height 1

  • @RobertPodosek
    @RobertPodosek 2 года назад

    >Every leaf (NIL) is black
    has 3 red leaf nodes, wut

  • @IjzerKeizer
    @IjzerKeizer 6 лет назад +29

    root (r-uu-t)

  • @motoliao
    @motoliao 8 лет назад

    Nice!!

  • @marco.nascimento
    @marco.nascimento 5 лет назад

    nice

  • @FightTheByte_
    @FightTheByte_ 2 года назад

    I'm literally looking at 3 red nill nodes...?

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

    Notice we’re all still alive. Heaven on Earth is real. Germanic Europe approaches

  • @matejbolta
    @matejbolta 4 года назад

    AVL > R-B :)

  • @mati124
    @mati124 2 года назад

    i hate my life. why i have to learn this nub trees

  • @kafychannel
    @kafychannel Год назад

    interesting )

  • @thezman2759
    @thezman2759 Год назад

    What is the point of these!? I don't get why you would want to manage more information and increase complexity.

  • @player6769
    @player6769 6 лет назад +1

    if you watch at 2x speed he says root right 😂

  • @waleedkhan6819
    @waleedkhan6819 3 года назад

    ROOT ROOT ROOT ROOT ITS PRONOUNCED ROOT IM SORRY THANK YOU FOR THE VIDEO BUT PLS

  • @isaacruelascastillo4952
    @isaacruelascastillo4952 4 года назад

    he said my children were black

  • @hangchen
    @hangchen 5 лет назад

    😊

  • @xiaoyuyang7676
    @xiaoyuyang7676 6 лет назад +1

    比较基础