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

solution ST2 Data structure 23-24

The document contains model solutions for an exam in Data Structures for the academic session 2023-2024 at Ajay Kumar Garg Engineering College. It includes various topics such as search algorithms, sorting techniques, binary trees, and hash tables, along with examples and algorithms. The document is structured with sections for questions and answers, prepared and reviewed by faculty members.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

solution ST2 Data structure 23-24

The document contains model solutions for an exam in Data Structures for the academic session 2023-2024 at Ajay Kumar Garg Engineering College. It includes various topics such as search algorithms, sorting techniques, binary trees, and hash tables, along with examples and algorithms. The document is structured with sections for questions and answers, prepared and reviewed by faculty members.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

AJAY KUMAR GARG ENGINEERING COLLEGE

Department of Information Technology

(Model Solutions)
Session:...2023.2024.

Exam Type(ST1/ ST2/ PUT/ UT) : ...Ik.

Subject Name: .DATA.STRUSIVRE.. Subject Code : Bcs-3o1


Year .....2AD. Semester : .38e..

Faculty Name Department


1.
Da.bnl.kumar II.....
2.
Ia.Modha. bgasal II...
3...IaKeti. ...I..
4.

Prepared By

(Faculty Name)

Reviewed By

(Faculty Name) (Signáture)

(Prof. Rahul Sharma)


HoD, IT
ST-2 Daty tructae BCs 3o|

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

Examine the mini mun Mumby


intotclange necded
sto Gnvert he
cray I., I1, 3,
6, 8, 12 4, 92, 94
minim vm.
(1)
4), 23, 41, 16, 19, !, 3,
6,8, 12,7,42, 77
(9

(13 (9)

te

So, min, no. of ierlang to build min haas : (8


Give EKAmple One
each 3table qn
Unsteble
teeNea
chmigyes.(ommon Soting

natue, Such ala Mege Sort,


imSosti Caunting ort
Sntotion Sort, nd BuAle Sort,
othese uch
( uck ot
Selectiom Sort e

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.

binay tee invove Teplacing nol)


tointesa with ufence to other
Ihey e nod e
too tep e thed eol binay toepu
( Double, Thaeade)
Fos Example:
LNR

DBE Afc

Lnk list Res pren ti gon

(3)
s.
Cangtyet the BST the
Sb, s4, G,29, 54,
92, 65, 12 33

64

65

Qs CGonstuct the BsT the


laing
S4

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.

at dla wobrelac hoilin n


amd laced
the soded pot.
lotan a s ize N n
Agorith
aeending eder

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

Sored Ret nsordelkt


A|25|29
ass
sored oae
1 5|o232]
Cndeity ! Bet case
Cmbarinons ter teycien, y
ase Seel So l
=l+1 +14-N-1)imer
Ttl Cmparnia
(N-)
Worst Cesel Al iteratien takes þluco meieihw

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.

JHILE /a2<=end ) : Coby Yemainig


Second lii
eleens
P2+t, 3++
17 foR
to oniginellisy
arli=
|9. STOP
mid nd

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)

Joc =.pariton (hunber,b ,ub); l lbcade Pivot


dich sor (huney,lb,l-1); || Sot firt holf
Quick sot (hwmbey, loet1ub);lsot seond hotl

(to)
nt ortilion (int hunber [], int l ,int ub)
x, , ten;
x= humber [u] : I)last element astivot

for (i =A ; j< ub ; jt+)


I|lacahom value
vale
I| Ssneller thon biet

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

Correhonds bivay ea ih nat ad der debr.


Lnordey : 3T9,A,c,G,E, H,F
Potodey! I,D,t,4,c, H, F,E, A.
A
'A'is n he Last oridien t
Heve ! mode
the fortodey Bo 'Ai e theot
o bmay tyee.:

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

ehe otterde ead made ne by ae


fram e t hn. We will follg

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

Heess obtaned by addn the patr


t the Key k.
K= l2345 K=i2 k-24 Kg-5
S=kË+kgt ka 12+34tS=S| C19)
Hast Table

o48
Keys Loat) 2.
72 72°o 7=2
338
38 38 7=3
37 37lo 7 2
S

48 4& f% 7=6 ¿|48

I| 7 4K

37 ealllig at aodex 2, Newdaz fr


37

- (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

Tota Nemte eesiy wthis þrohing=


Lo eato Key (20)
mde73
e
bolameed,
42
(4
73 44
73) mtatimt
32
tde42473
4nibalaied
laneed
us
tee Now
Leftntte
2
4 2
(7)
,32,44,82,
ssIe(73 42,4S, 73,
AVL
am nto lemts
dequneethe fllDung theShstien
aehot
element
a mod Dupict -
mece atet heiglts eunet Stes
-f
t-|H-Hel<1 Balamee
tee each bhay
tt-balaneng kmowm
as lso A
1962
82
(73

44

Tee
Thee is balaeed Lalamed

(22)

You might also like