You are on page 1of 23

(NIT- 2

DATA
AoVANGED
TRUCTURE

RED- BLACK TRE E


Searhh toee,
alLso

Complexity 0(gn).
t the
fer binary search toee

whese h w the
tme cornpdexy
the

balaned ew
Ried black tree
than t.
but AVby stabl
t6ee

ase
daletons
there then We

Sne 6t the

intomatfon the
whicl ae blaak
AVh- tree

More balaned

MOTe otatns,
AV- toee wsed Cae

frequont odaletion

PhOþe otes R&- toee

|ivery node ethies black

an Root aw ys blaak.
3.
ks Veng aat Cnie) black.
4.It node eol then both the hilorQny
we be blaekyo

5.os eaah nbole all


ale aths foo thhe
noole. to
t the d e candant leaves centan

the Same no blaek node.


BLack hefg ht -(bh)
uced to babang
RBtoee
back, nodes the
Total no
(ether la<t S ub tse,
w ay
Sub sub-tee) fem he toot t
to the
Lat node
la bLaek heigd
Bla
Black heigut oB ajt subtoee =
height ot ught subtree
total heigt R-B toee
* I h
ther bhh
2

Theot em
The ed- bleok with n nOdea

at
has he ght
he subtoee Ho0tRd at nade
any
Cort afros atleaAt bh) t e n a
hode.

then 2-1= te onal


nade
(no
hduton step U
conser <denal
4hat has p t e heigt an
each
node with 2 hlren heatheh
has black helght bh(x) os bh ()-\
uhethea the hild
depenang o
b laak

Sence. heght e a cheld


than the
hefght &elt, so,
atleat (2 bh a)- |
I

each child hai


n ten al

C
Tot al
ae no' e% = bh () bh()- I
nteonlnodes
intesnal bhla) hoot
node.
Total no ol node, = 3 -|

whery "h' the height RB- treo


node the

RB- tree are -|9 then

bh=

bh

n2

(n+) 2
Log nt) og,2.
h 2log nt)|

the
kotal n0" nodey
whede

RB

R B- toeee

Toseron Re- toee Samme

-nseston
new node, cOlor ef
*uÜhen
thet interthg
new Dode Red

aluays deapende
balontng Re- tree

Color wcle

bleek
beeslorhg
otation H
Ln deletPon, balanhg et dependa
upe the coler
cslor

NOTE
In AV toee Nsertory we o0tatfon
to d balancng atter Bserton
Cezt belaNei
RB- tyee We

balanng) Pseceloring
) Rotat>en.
)
f'ost.
seestonhg not
theh we
doe

the color
dependA upon

14 ncle tud than teealoing


6lak thon hotatfo0

Teeoloning
seoteol
ed
neusly
then the standad BST
etoom
b.e

the
neuly
make

color
G
teot change w be
cemplete tee
black ( bh od
Sccaled by ).
the +eleouing, cblor
atent n0t bLack 4

et have been bLaok)


’change color o tarert un de
Bodblak

ef qandatent a gad.
Change gTandþatent
New gTandþaert
R

color ed uncla
-then

G) change celor ot tarent


blaek

balonced tapeat
toee =3.
bladk
black
uncle
Ce & the et ch
case
the
chikd

cae
ceathe let-ch
lejt-ght the hight-child

COe
the ight
the ight

Cale Cp the, iht


chld the laft - chid

Rp

) ght otate
B

Let
otate P.

(B.

-0tate.

R
R R cae
B

8) let votte
Letor

R
)R
B

RL- Cse -

hì ght totate P,
R

RR
B

R
eg) <I0,20, 30,15x

B"g)<, (b, 14,19, 28, $37.


B

B 39 R
RR&
R

Recotouig
B.

lRR.
R
(13)

hecolauing.
13

Scet 28
(19) R w
fáj
Lnset 5
B

R 29
R
Jnecslouing
R

bh
14 n(00000, thd
(oo00 0t ) 39
h= 2Lo,
bh= h 2 ) bh 19

Q 9 , 8 , ,3, 5,2 7.
GD42gl,4, 5,9,3,6,7 .
eo,q0,5, 20,6,9.

(4
R
-
R

Recsloing Ru
4

3 41)
R R
B.

Recoloring

9,0, 4,3, 5,2

R,

LL

3.
K.
R

5
LL

R
R

R
R

eeslouno
N
Deletien

Tox doletfon epetaten,


celour ek
we

change
I4 delated node bLack, thery
be,
bLack height oh sub tree
Tedue ed t
R6 tre
treee
inbalanch be n ode wh take the
the deleted node d
þettfen
takéy the

hed, then make,

color black
child parent th en these
ay e esbilities
Caue I hed.
Actien ) Makse blaek

) Make s tarent
arent as hred
0tate aotnd o
tarent.
ight chd
parent new
Wi

hed
CaseI
R

n
Cae T
x's ng black ¢ bot
the
chlese W aoe ase black
AcHen-, ake o ed
i Set ss pasent au
Color
)

8.

Bne

R
B. (A

6lack 4 w's
chid i Ted 4 w's ight
hild black.
left child black.
ake we
ued
Make
90tate areund w,
) Sot ight o's paet
new

(0)P
B
x(A)

R.

Cae N s
W bLack w'e
ght cha a ued
(6Leqt cd an elthey be hdd
er black)
Acti- ) Set w's color a
cola
xs arent
ake 's paret
chilal as blad
Make
Sotatte and
Caues
(as mhiored age
caies)

cadei s celo black

arent theTe ve feur orble


Case.

Cas e I fued
black.
patert ed.
i Make,
a0tate

baret
et left child
batet as hew
B

(A
new
w(E)

black4 botth
Case T
Wate
the

Actian- ) Make w as yed


set os tþarent a
black 00t.

chéld blaok
Atien Make w's ight cd black,

aake 0tate asnd w


v) set chd Us asent
Dew w
B eo R

X
W A

Case V w black f w's


legt child
Aton- ) Set w's ceos a xs paent ceor.
MaRe x's
x's aTent a blaak .
) ake w's lelt ché Ld a blaek.
tuotate areund w's paent

R
R

(deletfon)
Delete"24 R
B

((4)
(9e
Case I
(oigat cae)
() case IE
(4), (iglt cae)
5
2

You might also like