-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSelf Balancing Search Trees
More file actions
46 lines (30 loc) · 2.14 KB
/
Self Balancing Search Trees
File metadata and controls
46 lines (30 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
First of all let us clear a concept that:
2-3-4(aka 2-4) Trees are search(i.e. left subtree is less than right subtree) trees
but not Binary(i.e. atmost 2 children) Search Trees.
Whereas, both AVL Trees and Red Black Trees are "self balancing" BINARY SEARCH TRESS.
Exact meaning of few IMP words:
Search means "Left subtree is always less than right subtree"
Binary means "Atmost 2 children"
2-3-4(aka 2-4) means "either 2 or 3 or 4 children" (cannot have 0 or 1 children)
In order for the search trees to be effective the MANTRA that everyone teaches is that:
"The height of the tree should be log(n) [to the base 2]" -> Always remember this
If any tree satisfies this MANTRA then its an efficient Tree for searching operations.
Question -> What are some real-world applications of Red-Black trees today?
Answer: There are two popular Balanced Binary Search Tree: AVL Tree and Red-Black Tree.
Both offers O(lg n) search time. But the hidden constant behind Big O makes AVL Tree more
suitable for search and Red-Black Tree for insertion-deletion. Insertion-deletion takes less
time in Red-Black Tree than AVL Tree. That's Red-Black Tree are more popular than AVL Tree although
implementing Red-Black is very complicated task.
Video for understanding balancing in AVL Trees:
http://www.youtube.com/watch?v=ij1gSage9uA
IMP NOTE:
To understand RB Trees, you have to first understand 2-3-4 Trees (aka 2-4 Trees).
The following are the best videos for understanding 2-3-4 (or 2-4) Trees.
Basics of 2-3-4(aka 2-4) Trees -> http://www.youtube.com/watch?v=47u7RU0XNR0
Bottom Up and Top Down 2-3-4(aka 2-4) Trees -> http://www.youtube.com/watch?v=2679VQ26Fp4
IMP concepts of 2-3-4(aka 2-4) Trees -> http://www.youtube.com/watch?v=JZhdUb5F7oY&list=PL104E2710A064F69E [The author talks about 2-3-4(aka 2-4) Tress from the 11th minute in this video]
Insertion in 2-3-4(aka 2-4) Trees -> http://www.youtube.com/watch?v=uIWLCfT9daI
Deletion in 2-3-4(aka 2-4) Trees -> http://www.youtube.com/watch?v=M_z-qYOY5JQ
Video for understanding Red Black Trees:
http://www.youtube.com/watch?v=JRsN4Oz36QU&list=PL104E2710A064F69E
http://www.youtube.com/watch?v=6QOKk_pcv3U&list=PL104E2710A064F69E