0% found this document useful (0 votes)
5 views20 pages

Binary Search Trees M4

The document discusses binary search trees, including their properties, searching algorithms, and deletion cases. It also covers selection trees, forests, and disjoint sets, providing insights into their structures and operations. Additionally, it touches on tree traversal methods and the representation of distinct binary trees.

Uploaded by

db8770632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

Binary Search Trees M4

The document discusses binary search trees, including their properties, searching algorithms, and deletion cases. It also covers selection trees, forests, and disjoint sets, providing insights into their structures and operations. Additionally, it touches on tree traversal methods and the representation of distinct binary trees.

Uploaded by

db8770632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Mou-4 Dept & AI{ ML

RNSIT
Biuary Seaeh Trees
seareh tree s a
ABig blnany tree, It
then it
be

Setts the ollig prgpetes


0 Each noole hcy emetly aud tha
in the tre an
Cre dstnt
The lh the latt subtree ane Snalley
than the the root,
S The kags in the rigt subhee are
than in the Toot.

The d t oud augt subtree are aso


Search tree.
biay

(10)
Seayching a Binry Seach Tree
> Re Cursie
Seareh
searh Seoreh tree
elmnt Seaveh CtrePointey root, int kuy)
Yatcta ky
Toat
it (!root) veturn NULL;
te
i1 (ke3 rot data ky)
Yoot >dafa
ueturn 4(Toot ’data)
it (k<vot >dota kuy)
batum seaych Crot Lteie, k)
Tetum search (ret >ngtcila , k) )

Stanch a blnany seaych tree


e elemt 4 terSeaeh Ctreefointey tree, int k)
iohile Ctree)
Tetrn 4(tree data):
tree >tru ’ltekild
2

tree tre ’ ngtCi4)


into a
Dnseting
80>30
Jriet ss

3s>30

3S <H0

(35

dctonany paiy no a binany seaeh the


Void inset (treePonte taade, It k, lye thette
{
tre Pointer ptr, temp =modifd Search(ede, k):
(tenp I) (*hole))

i (pty z NULL)

exit (o) ;

pty ’ data.kuy - k
ptr data. item = theJtemj

it ( node) 19inyut chld fep


temp clla ptr j
ely
ese

ceaych Tree

troot

Case 1:- Delete O - eat hode deletion.


Rapuove the ink tom paent Seat hod
paut an Yeove tha nk
tree
Deli
Case 2: - Das
Raplae the wode with tts ody cid

Case 3: Delelk S) - Tiso clald4 hocde dlation


Raplae te hodels ith inorcr Succeyor q the
hodeli) in BsT
truvensad, nil ve w
sorted vaton 9 thu int hode. So, Retens te
p peuty BsT
In orcln travusal; 3S9 I2 13 ls 4 20

Jn ordy gucenoy S
SELECTLON TREES /CTourna nunt trees )
The data struture ed to selet a woinner
Joser ls a eeleten toutnament treu
Ng playes deay hode (u)
No
selecttn (run) n-)
Selectin Tree
winrtree
Loertre
n May Min Mo
oinnY winar losey tosey
Noce Lnade
Smalsy vale largay vale Saallyy vahue
Winner Iree
Min igr

In oich ech hode Comglela bineny


Supvens the Smaller 4
tres
ib
chldren. Thu oot wode deprets he
ths tree saluat
*9

G)

b>

01>b O6>
Aoser tree
gelectim tree nn Ashich eath hon leat node vefaiy
A tree
a pointeu the osey is called a loser

FOREST S
Da :-
:- Aforest is a set n2o disjoint
trees

ta:Tree tre torest


a orest fat a tree
- To trantonm
Binany
sing bhay te,
a

O Obtain tha biuory tree


the tres in th torest epreentatin ech t
nacle root
uigk cild
treeBiuony
A
hodey. root a felSughtChjld
d
tha through tgth tree biuary thune nk
Formal trautoT nuakien tollews;
J T,..., Ta a foreyt trees, than the
foreyt landted by
biy tre componding
to thy

B(T,,-T)
n 20

hey oot eguad to voot (r): hay keft subtre


egual toto B(T, T., --T) veh. Ti, Tis, ..
Tn: a the Subtre ot T. ud hay
Aubtree B(T,, --, Ta)
’Forgt Taavegale
OPre-order forest trovesa)
(() then etur

the not te tst tree q f.


(3) haven tha Aubtree Q the trst tree in
fores t preorelr
Traves th renainiog reey F in foret
preoreler.
Jhoder travusal torest.
emgty than refuso
( ravx the subtreey tka fost tree in
torgt inoer.
Vit the yoot the ftrst tre
trees n torest Inorcly
(5) Post ordsr traveyal9a torat
then retrn
( Trove tha subtree the trst tree 4 F
n toret postorshr
(2 Tyove the remaiig trees fin
toret portoclr
(4 Viit the root ta tst fee
.
traveu
Cn viyit oots each ree in te foegt
( within each leve, voo
2
REPRESENTATZON oP DJ SJOJNT SETS

Con Sicn lo eled unbued ttnough o to 9


patitin them inlo thyee disoiod 3es.
S,fo, b,1, s3 auel Ssf2, 3, s3

S S3

opuatin 6 thex ses aane


Disjeint set union
are ses then
their unien S Us; al elenent,x. Such hat is in
Si.

S, US
pei ba Suepretien

SUS
ct conteiing the elsent
1, Exauple

Unlorn aud Find Cpeatony


Pota Representaten o Set
:
Each 0ot has a poiotes to tha set home
y table is nanme' T- hold the set name.
Set
Name Pointer
S

elemet Set hame


ith rot j , I has poirte to enty k,t, Set
Duapesentote
2 3 4 6 1&9

2 -
Poret
Fiud elonant i by simgly folosg
aud 'cntinung unl e yeuch
value,

value meony uach


He 9oot,

acompyhy
uion.

int simp fid (int i)

eturn i;
Void Siplnim (int i, int i)
pand i):f3

hodas 'ntree i is Juy than he numben in treij


then make he
NoG? det be d tree itA n hook
ot TT be
Creaid ay a Tesudt q koeighted Uin, No node
in T Aaa dvel than LlagnJt!,
Tree obtained wing the keighting ule

-
initia
unienlo,1) uNonlo. )

Ui (o, 3) o, n-1)

Void
wigted Uin (int i, int j)

paunje tempj
pouutiJ tenp
Cunting Biay Trees
Dstinet Binerg Treey
n20, or biuary tre.
22 datinct rees

Clud

To obta'n te numbeu a distinet treu ot,


h nedlu, dolve fueumence equatiun.
hl

bi bn-i-!! aud bol )


To beg funchn or ta
the
B()
i0 humban biuarg tree
Sec urence Dalatun e get the

287) B(a) -]
Uti tat Bo) = bo l.h
fact

Can

to
B)

m
2

and () we see that bn


toeticient Q in Ba) y
(-)":2
Sinplfcain Coapat orr
ba a - D/,)

Tree travwsal aeguir a staek

heve selonre ABeDEF GHI


Qudndu Sequn e BCAEDGHFI 1 th Bame
bluang tree,
Cruytuet tree

first elamant in preoic segutnce la root < the tree

Beah A tn noroa eoene loe Can all


lwent
Cd elamint
tree
get be
stese above fallturcively
the ms Rh
DEPGHI
(B
iongla Constet Bincngy tree.
peonda peMutaticn I,), 3, -- 9

2)-a7t subtree

Cuyicda 23

tre
buatriy, multipieatom
koe noiah fo compute u pacuct 4n
Suppo.
Mutiees!
M, M* M,

orclr

(4 M) M, M, (m, +M,)

My
(M *(a M)) My
M, (Ms My) Mu)
M (M (n, yMu))
M))
bn be fo congul
tu podut n Matite. Ban by ba 26 buss.
tun
bn aud bo l

eni

You might also like