solution ST2 Data structure 23-24
solution ST2 Data structure 23-24
(Model Solutions)
Session:...2023.2024.
Prepared By
(Faculty Name)
Reviewed By
Sliom Bection -A
Q.
Se4ch and binass Seat oh.
Seastch
Senstch iu a Simale
teleechimentaue triniase
elemert
Reaneling an
Seaeh oloes not Binay Seasich terhmique
Feaire he,Wlst
tist toto be
be Sorle reguires the list to
3) beSorte
Evey elemont the list is
Com pared wt he key cOnly the mid Jement
dement the lint is Cmpard
4 toit
alyoitmig
natuye iteretiye in q Key
element
Agrthm
n tertnique is Divide
s) githm is esy to m
Time Gmplex.
Time
(13 (9)
te
We
an mody
de Stasle dy Unstalble Seringalgomih m
(2)
that is the Smportance of taeded binasy
tee 9
Sn thslende binaly tre e
trayeua0 o nde% in the tree
tnek, S hetack ik 3ed hen
Jet o memoy nd me.
DBE Afc
(3)
s.
Cangtyet the BST the
Sb, s4, G,29, 54,
92, 65, 12 33
64
65
22
33
(4)
&echion -8
alain neohen lot nthh rae and it
Ans
Conley.
Inserdon dt .hiu a dinle Seig
abonihn Hhd'otr Sislar to te ny e
St
vitualy spkt jnto a deuted
Ra aay ie
and an (wsorded þart.
Begin! .
for d2 to N Do
key= A[N]
While 9>T1 AND kes <A[i-]oo
ACs1 =Ai-9
AA+] =key
End.
(3)
Examle
Soydel wnsorded Rart
First
Puss 1 23 |1os2
Sode mSrded
Rar Part
Secenel L12352
Ress 23 los
nordelRurt
Sor\ed Rars
Thi 2
Totel anriria =
N2 -Nh = 0N)
algonthm fr egesod amd
t ot he given element h,35,65,6 24,12,
E4, 64, 23
gort eee te dipide andl
Aht: , MergeSti. Mexje
abhach toot tla
te
Conguey
clemt. nb tuo equel
It diuider the gien iet
or the tuo haloes and hen
halbes, calsiheelsel
tb oted haloe.
meges Ah'
Ayorthm!
MERGE SoRT(as,besi Rrd)
1.
Hen midk-L (beg t end)l2
MERGE-SoRT (arr, beg, mil)
MERGE SefT (anr, hidt,ed)
MERaE (ars, bey,mid, end )
MERaE(ann, bes, mid, erd)
1. trd beg
Ptr 2 = mid+4
1:
. ELSE
merselisA[Ror3]-oorr[Rt2] oy eon
at ist
dr 2t t element
nigelirt [ lorlona]
I3.
762412 S4|67 23
24 |12s46?22
DVDE
ls 23
823
23 6?
(35|w|&s21/76
24
MERGE
23S4
24
3s 44S4|
65|6?/76
|I223
2324
Sorted lict
a.& wite a a cG fmehien por quick Sot w
loct elemo,t ae tivot ementi
Ansi duwide Sot iaIn hie sot, ofterr cleting
tha tioot elemet, tla arey
cntainc the element mlloe
One subaray
than ibo elemet, and tleo other sdbary
Condains the elemet reter than he tibot
element.
c Fymetion for quick Sort
boid Qictsont ( int ber c], int b, inu)
n loc;
(QL< ub)
(to)
nt ortilion (int hunber [], int l ,int ub)
x, , ten;
x= humber [u] : I)last element astivot
temþ hwnber[):
humberCi] = temp.
Ilocade i t ofte.
temb =mumber [ub] : first half
hunberfi+1].
muwnberfaL] -
mumber[its]= femp;
retn (i+1);
a.9)
If nez a bios ee ie 2,124<,4,EM,F
Rom the
from nolernocas
mode on He et side dd
BID
A'. i.e.
and modes on He roll piele
ubee.
CA,E, H, F
B,\,D CGE HF
01,D
((3)
(A
Read'F! Eeod'H'
B,),D
BiD
Recd'e'
Reada' B\,D
Read'g )
Read 'o
,D
(Final
Binasee
(M) (H)
Conshuet aa BTree od ade 5 ky neeiss
folleasn'g keys do am initially erbty bee.
b, 5,4,a, k, d, h, m,i, e, P, ,r, x, c, l,n,t,s.
Ans:
Crder m' 5 Ro a Bingde moa cam
Condain maximwn
aelere.
k
Split on
a b|
alb
albld
/
P
F
Sbifon
(7)
)
Secimy e
ane
() Dvisjow method
(2 Mid squa ethod
(3 method
0 Divisiew Meth’
CK)=Kmodm
wh Kis the Keyvaldmas the
Size the has tale
Example K27
m=lo
ce7)=27mod lo=f
2)Mid-Squae Methed
value
k36eD
)=
Feldng Method
k= K,k2, -,Km
S= Ktkat - t k y
o48
Keys Loat) 2.
72 72°o 7=2
338
38 38 7=3
37 37lo 7 2
S
I| 7 4K
- (24e)/o 7 4V
Kay 6G elldg at dex 3, New io
Kto) of7 =3X
=6+e 74 X
=(342)"7-Sv
et molese S, mew
= 4 X
( 4 )lo 7 SX
t2) o/"? X
= (443)"o7
44
Tee
Thee is balaeed Lalamed
(22)