Red-black trees in 4 minutes - Intro

  Рет қаралды 767,087

Michael Sambol

Michael Sambol

Күн бұрын

Пікірлер: 181
@arpitchristy9788
@arpitchristy9788 3 жыл бұрын
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 10 ай бұрын
if only you could go through a red black tree instead
@dennisekiller
@dennisekiller 10 ай бұрын
@@ThomasEdits GO SLEEP, UNI TOMORROW
@DarkDay2012
@DarkDay2012 3 жыл бұрын
Studying for a Data Structures Final and your videos are really about to save me. Thanks man
@EskyDinpuiaChhangte
@EskyDinpuiaChhangte 5 жыл бұрын
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 Жыл бұрын
Y’all be qouting CLRS for real
@Lanaohla
@Lanaohla Жыл бұрын
y u repeating the vid is 4 min long
@ata500
@ata500 7 жыл бұрын
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!
@sj1997
@sj1997 7 жыл бұрын
dude you just nailed it simple short precise and a clear explanation no trash talking respect from india man
@Tourach74
@Tourach74 4 жыл бұрын
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 жыл бұрын
Great videos, very clear and understandable. Keep up the good work!
@thomasjinton3862
@thomasjinton3862 Жыл бұрын
Totally agree :D
@ante1337
@ante1337 6 жыл бұрын
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 жыл бұрын
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 Жыл бұрын
Y’all be qouting CLRS for real
@ryandavis7506
@ryandavis7506 8 жыл бұрын
Absolutely killing it, dude. Keep going and don't stop. Easy subscribe. Thx.
@regisschulze6678
@regisschulze6678 7 жыл бұрын
yeah man I feel ya even subscribed my grandma without her knowing
@yadhunandhanr7590
@yadhunandhanr7590 6 жыл бұрын
I love the way the video is made. Perfect!!
@juliajeehyunkim
@juliajeehyunkim 3 жыл бұрын
This is AWESOME. Love this video, hope you become more famous
@ca4307
@ca4307 3 жыл бұрын
u say root funny, but thanks for the clear and concise explanation!
@fasihkhan8633
@fasihkhan8633 6 жыл бұрын
No words ... hoW to be thankful Great tutorial🔥👍
@Salamandolo
@Salamandolo 6 жыл бұрын
rut
@ryanbarry7670
@ryanbarry7670 5 жыл бұрын
really understandable tutorial? I agree!
@RaleighLittles
@RaleighLittles 4 жыл бұрын
1:57
@NirajSingh-nv2jb
@NirajSingh-nv2jb 6 жыл бұрын
Best and simplest explanation on insertion of R-B tree on youtube. Please upload video on deletion.
@CaveDave
@CaveDave 4 жыл бұрын
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....
@geezer2450
@geezer2450 7 жыл бұрын
This (and your other videos) were very helpful! Thank you very much.
@ToonGnarizard
@ToonGnarizard Жыл бұрын
excellent series!
@shivanshpradhan8860
@shivanshpradhan8860 7 жыл бұрын
very well explained in short time
@mohammadmohammadian6706
@mohammadmohammadian6706 Жыл бұрын
upload more man you are amazing
@ruiqiliu3114
@ruiqiliu3114 2 жыл бұрын
Clearly explained, thank you!
@firezdog
@firezdog 5 жыл бұрын
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 жыл бұрын
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.
@Makwayne
@Makwayne 3 жыл бұрын
Me watching on 2x "red-black trees in 2 minutes"
@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 10 ай бұрын
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
@dogemaester
@dogemaester 6 жыл бұрын
Wow great job! I love this!
@melbexdeleon8951
@melbexdeleon8951 6 жыл бұрын
GREAT videos man!
@muralikrishnaraju
@muralikrishnaraju 8 жыл бұрын
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 8 жыл бұрын
The leaf nodes are actually their NIL children.
@muralikrishnaraju
@muralikrishnaraju 8 жыл бұрын
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 8 жыл бұрын
5 isn't a leaf. Just because a node is black doesn't mean it's a leaf (see: 8, 12, 19).
@muralikrishnaraju
@muralikrishnaraju 8 жыл бұрын
Thank you
@jbob2015
@jbob2015 7 жыл бұрын
These videos are amazing keep up the good work and you'll make it big in no time
@honglichen4670
@honglichen4670 5 жыл бұрын
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?
@anukoolsrivastava4235
@anukoolsrivastava4235 7 жыл бұрын
to the point and clear enough
@ahmadrezamoodi
@ahmadrezamoodi 6 жыл бұрын
nice and simple.it was all i needed thanks
@rishabhjain2404
@rishabhjain2404 8 жыл бұрын
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 KZbin yet.
@chrisjasonmcqueen
@chrisjasonmcqueen 5 жыл бұрын
Awesome video thanks for sharing!
@lingyongwang2817
@lingyongwang2817 6 жыл бұрын
This is great! Thanks for sharing!
@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 жыл бұрын
nil is a black node, so you have to count them as well
@Mattamorphosis
@Mattamorphosis Ай бұрын
Q: Why is the longest path no more than twice the length of the shortest path? A: Consider an arbitrary red-black tree. Notice the following: Each red node has a black node as its child. Therefore, the number of red nodes is less than or equal to the number of black nodes in a root-to-leaf path (justification: each red node can be paired up with a black node, and there could exist unpaired black nodes). Now, consider the shortest path in the tree. Since each path has the same number of black nodes, the shortest path must contain the least amount of red nodes. The longest path, on the other hand, contains the most amount of red nodes. Due to our upper bound on the number of red nodes, and the fact that the shortest path could theoretically contain no red nodes, then there are at most twice as many nodes in total in the longest path versus the shortest path.
@ultrafalling
@ultrafalling 6 жыл бұрын
Great useful content! Thanks
@stephenhowe4107
@stephenhowe4107 4 жыл бұрын
Insert and Delete require rotations and recolorations, sometimes both.
@billpetrak
@billpetrak 6 жыл бұрын
I wish you had also included deletions in your r-b trees series. Good explanations though.
@leenlovesdancing3561
@leenlovesdancing3561 8 ай бұрын
Thank you so much! ☺
@marcofontana8308
@marcofontana8308 4 жыл бұрын
frate ti adooroo sei un grande
@Do-Your-Work
@Do-Your-Work Жыл бұрын
This line " red nodes have black children ".
@kaustubhpandey9654
@kaustubhpandey9654 5 жыл бұрын
Great video!
@jackc451
@jackc451 3 жыл бұрын
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 :)
@eklipina
@eklipina Жыл бұрын
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"
@thomasfischer9289
@thomasfischer9289 6 жыл бұрын
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
@RedPandaDesu
@RedPandaDesu 6 жыл бұрын
Good summary of CLRS 3e chapter 13.1.
@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).
@王冠信-o1c
@王冠信-o1c 4 жыл бұрын
Why the 5 on the left side isn't red?
@ethanray19
@ethanray19 7 жыл бұрын
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?
@tecnaharmonix3416
@tecnaharmonix3416 4 жыл бұрын
Please make a video on deletion too
@Kevin-jf6jw
@Kevin-jf6jw 4 жыл бұрын
Wonderful one! Btw, where is the node-removing part? Thanks.
@TheLoyalpain
@TheLoyalpain 7 жыл бұрын
I liked everything except the way you pronounce root... Otherwise very helpful!
@MichaelSambol
@MichaelSambol 7 жыл бұрын
I've always said it weird. :)
@nabinkhadka7168
@nabinkhadka7168 6 жыл бұрын
What is weird about the way he pronounces root? Sounds normal to me.
@antoniojg-b8284
@antoniojg-b8284 6 жыл бұрын
"rewt" vs "ruet"
@codyromano7868
@codyromano7868 6 жыл бұрын
I didn't mind that at all. It added character to the (already well done) explanation. :)
@valeskavictoria1278
@valeskavictoria1278 5 жыл бұрын
@@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 :)
@de9989
@de9989 5 жыл бұрын
nice video,thanks bro
@ayushagarwal4253
@ayushagarwal4253 Жыл бұрын
Nice video. Can you also make one on Tries please?
@MichaelSambol
@MichaelSambol Жыл бұрын
will add it to the list 👍🏼 taking a small break to finish some other projects, but will be back.
@antwanwimberly1729
@antwanwimberly1729 Жыл бұрын
Can you clarify what a NIL descendant is instructor ?? We need more context and clarity.
@ThomasEdits
@ThomasEdits 10 ай бұрын
"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
@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.
@bipinkori4060
@bipinkori4060 6 жыл бұрын
Thank you very much
@KingUnity22
@KingUnity22 4 жыл бұрын
but how do we determine whether a node is red or black?
@markmcdonnell
@markmcdonnell 6 жыл бұрын
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 6 жыл бұрын
@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
@alandawkins8297
@alandawkins8297 6 жыл бұрын
very elegant.
@daniellarson8291
@daniellarson8291 4 жыл бұрын
Shouldn't 5 be red?
@hurrykrishna
@hurrykrishna 8 жыл бұрын
thank you. made easy!!
@toastyshrimp1882
@toastyshrimp1882 3 жыл бұрын
what are the other ways to balance a BST besides red black trees?
@pedroalbertogomes3809
@pedroalbertogomes3809 6 жыл бұрын
Hi, I'm teacher at a public university in Brazil. May use your material?
@MichaelSambol
@MichaelSambol 6 жыл бұрын
Sure! Just let them know where you found it.
@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
@Jeff-zc6rr
@Jeff-zc6rr 10 ай бұрын
You actually don't explain why a node is red.
@iulianalexandrudragan5531
@iulianalexandrudragan5531 9 ай бұрын
I think it arises naturally from the 4th rule
@Craffunky
@Craffunky 7 ай бұрын
To have the same number of black nodes you need to add red nodes
@palandersmuhlbradt5705
@palandersmuhlbradt5705 6 жыл бұрын
why is node red and black? have the colour any meaning?
@ioanabiris3472
@ioanabiris3472 Жыл бұрын
Thank you!!
@Nevverglow
@Nevverglow 4 жыл бұрын
this is gonna be called Red-block tree soon
@jmm00702
@jmm00702 4 жыл бұрын
red-afroamerican tree 4Head
@trollerninja4356
@trollerninja4356 6 жыл бұрын
y is 5 not red?
@jackkirby5287
@jackkirby5287 4 жыл бұрын
What is a NIL node?
@TonyKaku-g8n
@TonyKaku-g8n 5 жыл бұрын
You know, every node has a black parent at height 1
@alfredoespinozapelayo
@alfredoespinozapelayo 5 жыл бұрын
Why is node 5 black?
@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 10 ай бұрын
"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
@mohamednofal5256
@mohamednofal5256 6 жыл бұрын
thanks mic
@pustkaimrok
@pustkaimrok 7 ай бұрын
still no answer why a node is red
@buzayehuyitbarek3877
@buzayehuyitbarek3877 5 жыл бұрын
10q Mr Michael
@fireguardianx
@fireguardianx 3 жыл бұрын
I might be wrong, but you sound just like the Khan Academy guy for calculus...
@jeremylee4048
@jeremylee4048 2 жыл бұрын
thank you
@IjzerKeizer
@IjzerKeizer 6 жыл бұрын
root (r-uu-t)
@player6769
@player6769 6 жыл бұрын
if you watch at 2x speed he says root right 😂
@dmytromarchuk3023
@dmytromarchuk3023 4 жыл бұрын
succinctly, like
@RobertPodosek
@RobertPodosek 2 жыл бұрын
>Every leaf (NIL) is black has 3 red leaf nodes, wut
@FightTheByte_
@FightTheByte_ 2 жыл бұрын
I'm literally looking at 3 red nill nodes...?
@ondrejmatousek9723
@ondrejmatousek9723 7 ай бұрын
where?
@dhruvamishra5857
@dhruvamishra5857 7 жыл бұрын
pls upload more videos
@motoliao
@motoliao 8 жыл бұрын
Nice!!
@ZandPyr
@ZandPyr Жыл бұрын
This is helpful but the talking is very slow.
@mati124
@mati124 3 жыл бұрын
i hate my life. why i have to learn this nub trees
@rohitippili3834
@rohitippili3834 6 жыл бұрын
Thanks sir
@vijaysaikonatham68
@vijaysaikonatham68 6 жыл бұрын
Your concept is wrong , because in red black trees root and leaf nodes should have same color
@KublaiKhan2025
@KublaiKhan2025 6 ай бұрын
At 1:31 the leafes 9, 13, 23 are NOT black
@isaacruelascastillo4952
@isaacruelascastillo4952 4 жыл бұрын
he said my children were black
@matejbolta
@matejbolta 4 жыл бұрын
AVL > R-B :)
@harrisonn9792
@harrisonn9792 2 жыл бұрын
Thank YOu
@waleedkhan6819
@waleedkhan6819 4 жыл бұрын
ROOT ROOT ROOT ROOT ITS PRONOUNCED ROOT IM SORRY THANK YOU FOR THE VIDEO BUT PLS
@antwanwimberly1729
@antwanwimberly1729 Жыл бұрын
Notice we’re all still alive. Heaven on Earth is real. Germanic Europe approaches
@thezman2759
@thezman2759 Жыл бұрын
What is the point of these!? I don't get why you would want to manage more information and increase complexity.
@MichaelSambol
@MichaelSambol Жыл бұрын
So your professors can grill you 😅
@fethiourghi
@fethiourghi 5 жыл бұрын
thanx
@marco.nascimento
@marco.nascimento 5 жыл бұрын
nice
Red-black trees in 3 minutes - Rotations
3:05
Michael Sambol
Рет қаралды 322 М.
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
БАБУШКА ШАРИТ #shorts
0:16
Паша Осадчий
Рет қаралды 4,1 МЛН
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН
Lecture 6: AVL Trees, AVL Sort
51:59
MIT OpenCourseWare
Рет қаралды 674 М.
Quick sort in 4 minutes
4:24
Michael Sambol
Рет қаралды 2 МЛН
Red-black trees in 5 minutes - Insertions (strategy)
5:38
Michael Sambol
Рет қаралды 502 М.
Binary search in 4 minutes
4:00
Michael Sambol
Рет қаралды 144 М.
Red-black trees in 8 minutes - Deletions
8:13
Michael Sambol
Рет қаралды 119 М.
AVL Trees & Rotations (Self-Balancing Binary Search Trees)
20:38
Back To Back SWE
Рет қаралды 362 М.
Heap sort in 4 minutes
4:13
Michael Sambol
Рет қаралды 1 МЛН