0% found this document useful (0 votes)
20 views

binary search tree

Binary tree

Uploaded by

ashvanthraj26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

binary search tree

Binary tree

Uploaded by

ashvanthraj26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Seauch tro Ppoated anueuty

Binay whon
2
maul
Bina Seach roe is a binaau
Eree in which fon venol x in t h

tree, fhe Valuey of all th cous in its

Cccbtre ue SmalleY than tha ke


Value în X, Qrd th Values of all tha key
in its right Sub ree 0ue Joge h@h tha
volue in X
odmec

20
Node deelaation
Struct Trouodu

Element Type Elemant


Seauch Trou Let
Seauch re viaht j
LOpection oetovmed in Bnauy Seauch

tret aue
Make empty
2 T n s e t i o n

3 Delution

4 Pind
5 Find min
6. Pind max

Make empty Is wed


S ued fov
for
Opocutiorn
mate empty
ini Halization
Seauh TPree Make empty CseaLch TreT

f (T!NOLL)

Make Empty CT- 4t)


Make Empty (T-> Rgh
Froe CT))

Tetum NOL

Find
This opeation oiu fird ky x in

tho bina Seah troa fkoy is OUun


than pointe tD that hode is etuned.

F th toy is not found it oil


bun NUL
oebup
T is NOLL, then Just
It
ke Stored a t TS eua to
tha
a n retum T. otheuoise make a u i v
Call on a Subtre of T, eithey duft sive
ight dupending on t h Value Stoostored inT.
( Axeme
Pind-Iq

kug value

Purahi
ram
on
Position Pind (Element Type x, SeaaCh lrat)
raT)
If CT== JoLL
9 otun NOLC)
if CxeT-> Element)
Tetun Fird Cx, T->Lutt)D
ese
if Cx>T>Elemant)
retum Pind Cx T Pght);
ele
retun T;+ tey founo
3
Pid Min
This routine Tetun th Position of
Smalleyt elumant in the tro
To Potom a Find min, Staut at
tha reot ad go Jat a dong ay thure
is a dlt child
Th stoPping point 's thuior
Smallyt Oumint
9

Position Fird Min Cseauch res T

if CT= =NULL) o
Toturn NOLC
else
if CT-> Jtt == NULL)

return T
ese
Totum ind Min CT7t);

Find Max

This TOuutine e t u n the Position of


daugyt elument in thi tre
tree
To Pactorm a Find Max, Stout ot thu

root and go ight s a


adorg uthere is
ght child
The Stopping Point is the dasgest lamant
position Pind Max C seauh TroT)

fCT = NUL)
Tetun NOLL
eLe
If (Trght== NULL)
otun T
oe
retun Ptnd Max (7-> Right)
Inseuti on '
To Inse x intoEree T, PooCeed
th Find furction

-> Ifx tstound do nothy tng Othe


-wise inseut at the daut Spot on the
Path traversed
8, lo, 3, 2 8, 6 S, 13,1 n
inset 8 insait lO insout 3 inseut 2

inseut 8
inseut 6no oneq
inseut 5

13
tnset 13 nsaut I

odolbG 18

13

Seauch lree

SeCuch Tre T)
n set Element Type I,

if CT= =NOLL)
Trowode)):
= maulloc size ot (strowt

if CT== uOLL)
Space D b
Fatal EnoY o u t of

olse

T SElement =X
T- t = NUL;
1 - Pight -
NOLL
3
ele
if CxT Element)
TRight Inseut XT-> RighE); 9 0
if CxeT> Element
T-Left = Inseut Cx,T > Let);
return TT
Delution
node o ith no children
Case 1 Tf th node is a Au,rt can be

duluted immediakely
e
aft
dalubing

JOo T
Caxe 9 nodo wth one chtld -

f chtld,the hode can


t h rode has Oh
be dulubedato Its Puent adjuts a poinkad
t bgpauM-ha hode

To dulute

Frtte
duut
4
d
ngmolsTA)
CUse 3 hode CwHh toochildren
To dulte 2 Jnom93

Pincd rode coith S maller Value în

tha Sub trot


ght
OT
Pnd nocle with bTgge Vadue o
th duft Subtrea

Roplace
the hode in place of duuted
hodu

aftu
dulutig
2 (2

SeauchTee Dolute (elementlype x, Seauch ree T)

Position Tempell
if CT== NULL)
Exor CElement not found")
else
CxeT ElemenE)
T-Lot =Delute (x,T->lett)
ele
iF CxT Elemant)

TPight =Delete (x, T>RghE)


ose
if (T->ltt 38 TRignt)
Tmpceu-Find Min CT->Rghlt);
T Elemunt ImpceU > ¬lemant
T->Rt Deluke (T Element,T-Rght):
else
bor
Tmpcel T
f (1- Left
== NULL)
T T Right
else
if CT- Right ==
NOL)
T T Left

frea CTmp Celu);

Tetun T

Jnomo3

amo

ni bo9-
umo3
nuwmo3

You might also like