Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Structures and Algorithms Exam, Exams of Data Structures and Algorithms

This is the answer sheet of exams

Typology: Exams

2020/2021

Uploaded on 06/21/2021

Abc-ka-baap
Abc-ka-baap 🇮🇳

1 document

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
A
Buadh
fit
seakeh
(BFs)
is
an
algorilhm
Zhat
is
nd
gtaph
dala
or
searehing
Tuu
r
baunaing
suelure.
Th
lporm
o
BFS
io
tha
Braadth
fiut
nareh.
T
algo*ithm
leeionTly
uisil
amd
marks
all
tha
ky
odes
n a
qhaph
tn
an
acewrol bread
thnse
fanhisn
. This
olgerithm
seosi a
single
nade(initzal
O
souree
hocnt
in
a
aph
amd
Then vinild
all
le
nedos
adyaeenl
to
the seloctid
nods
.
BFS
aeceuus
Thea
nodas
md
y oma.
Once
the
algorithm
viAi
ond
marks
tha
slarleg
naca,
en
i
moes
tausasds
tha
neast
umeisitid nodas
and
analyses
iien.Onee
uisilad-,
al
nedes u makid .
Te
itna
tiomy
conlinu
nlill
all
th
nodss
o
the
qraph
haus heam
ucromhully
istid
anel
nark1d.
E
mpleL
sib
4
Yau
hae
a
ghapk
oA
mumbars
kaging
fromo-
Mark
0
os
viaiid
Tranwerse
ki
wn-wAitid
adtacrnt
nedes
whish
are
3and
1L
PTO
pf3
pf4
pf5
pf8
pfa
pff
pf12
pf14
pf15
pf16

Partial preview of the text

Download Data Structures and Algorithms Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

A Buadh fit seakeh

(BFs) is^ an algorilhm (^) Zhat (^) is nd gtaph dala^ or^ searehing Tuu (^) r baunaing suelure. Th

lporm o BFS^ io^ tha^ Braadth fiut nareh.

T algo*ithm

leeionTly uisil^ amd^ marks^ all^ tha^ ky

odes n a qhaph tn an

acewrol (^) bread thnse

fanhisn.^ This^ olgerithm seosi a single nade(initzal

O (^) souree (^) hocnt in (^) a aph amd^ Then vinild^ all (^) le (^) nedos adyaeenl to the seloctid nods. BFS aeceuus Thea

nodas md y oma.

Once the algorithm viAi

ond (^) marks (^) tha en i (^) moes slarleg^ naca, tausasds (^) tha (^) neast (^) umeisitid analyses (^) iien.Onee nodas^ and

uisilad-, al^ nedes u makid .

itna Te tiomy (^) conlinu (^) nlill (^) all

haus th^ nodss^ o^ the^ qraph

heam ucromhully istid^ anel (^) nark1d.

E mpleL

sib 4 Yau^ hae^ a (^) ghapk oA mumbars^ kaging fromo- Mark 0 os viaiid

Tranwerse ki wn-wAitid

adtacrnt nedes whish are

3and 1L

PTO

Spa0 lo has ban maukd as a nost nods ,

Root neds = O

Släp3-> Ois iid, markedl, and inslad inl e quu dala Auuli

O

QuuL:o23 + 3

Petete values (^) trom (^) quatie and (^) pint a (^) lt

Rasulto, 1,2,3, 5, 6

sta (^) Remainimg (^0) adjacant and (^) umnied nodes ara uisa marked, and (^) imtad (^) inlo (^) t quu Vist s^ amd 1 in (^) any aajuaneo ane mahk hana O as (^) vuiutid (^) andl (^) add lsm

Fer (^) count - (^2) o (^) N-1 (^) do C (^) << Cunl. (^) neat End hor

newVada. (^) met (^) cwrrent, nwt Curet. nit <nwWedoj

E-di Ed

Coede 8 (oy funlion)

Veid (^) inwrtAtN (^) (int data, i poitisn)

uet nsde^ nuwNsda, "cwrrent nt is i hadl= = NuLL)

hnt "Lit^ is^ empty. (^) \n);

elsei4 (poalion = =4)

insertAt Baginmingl dala); /" Funelion delid ta vinart

nod at baginming

als

/Gsates ne^ nede (^) and (^) assign data (^) o (^). naoeds= (^) (Auet nsda ") malloc (^) (sigpof neuwNoela (^) data = (^) data; (uernod)

PTO

TsaurAe to n-I nods

Cwront= head ;

eri-2 i=porilion-1; i++

Cued =Cwktet neot

*Links neu moda with noda ohend it and pruuwious lo

.

nuwNsda (^) nuaf =^ curun (^) ert Cunt> net = neuWoele

print NoDE^ TNSERTED (^) SveCESs (^) FU LLY. In (^) "):

And =, mar(4(o, o)=o, i=

max), , ) +i= 0+2=

=2,maz(4 (),.o)=2,is- S mas({), )+i =2-3=-

()=-1, (^) manl{ (^) l), o) = O, i^ =

uo maz(f(), o)^ +i=^ 0+2=^2

()=2, (^) maz({), (^) o) (^) =2,e =^ - nws manl{l),)+i= 2-l =

PTO

(f 1o 1t2, 6, 13, 12,s)(10,6, 14,6,13, 12, 5) Swob (14> 8) (10,8,1t, 6,3, 12,so)->(* 10o, 8, 6, 13,2so) 5usa (1t> 6) (110, 6, 14,13, 12, So)>(10,9, 6, 3, 112,50) Soop 1+>I) (,10e,6,13, 14, 12, 5o)>(1O9 6, 13, 12 5) Sun (1t+> 12 (t1 P, 6, 13,12, 1t, 5o)>t,10, 6,13,12, 14, So) (So> Third Po

(t1,P,6, 13, 12, It5)>lt10, P,6, 13, 12, 1t,so)

(t (^) 0,6, 13, 12, (^1) s)>(8,10,6, 13,^ 12, 1 (10>)

so S uoap (iO>) (t8,10, 6, 13,^ 2,^ 1t^ 5o)> (^) e 6,10, 13, (^) 12,1 5) Swap l1o>) (t, (^) 61o, 13, (^12) It (^) so) (^) >(t®, 6, 10,3, 1215

(t8,, 1o, 13, 12, t, 5o) >(t8, s, to 12, 13, 1, 5o)

Suwo (B> 12. (t 8, 6,1 0, 12, E,1 50)(®,1, 10, 12,131n5o)

(t8,6, 10, 12,13,1450) (tP, 5,1o, 12 13, 14, so)

so )

FowrtlhaaA

(t 6,^ 10,12,13,15)(8,6,1o,^

12,13 (^) 1t So)

(t&, 10, 12, 13, 1t, So)(6,P, 1 12,13, 11> 5e) Swo 8> 6)

Ct6,8,10, 12,13, 1t 5)>(t» 6,8, 10, 12,13, 1,so)

(t,6, 8, 1,12,3, 1,5o)>(t,6,, 1o, 12, 13,1+,

(1o) 1)

(t6,®, 1o, 12, 13, 1, so)>(t 6,10, 12, I3, 1, 5o)

(I3>12)

(68, 1o, 12, 13,1t, 5o) (+, 4, P, 10, 12, 13, 150) (+>13) (t6,, 1 12, 13, 14,50)>(t,6,0,10, 1213, 4,50) (50) 1

No ta^ gun (^) Jaauencs is (^) altnady ssrad, but^ oun (^) algarilhe ders net^ knou (^) t it (^) s comltid (^) .Tus, zAs^ algetipm ad

One wnale pas wlout

ay (^) uaap lo (^) knsus it is (^) sorad.

Eth Pas«

(t6,8, (^) 10,/2, 13, (^) 1t, (^50) -(t,6,8,10,12, (^) 13,1t (^) 5o) (t6,P,10, 12 /3,+,5o)> (t,6,8, 1, 12,131t, 5) (t,,1D,12,13, )( 6,8, 10, 12, 3, 15)

|(t 6,8^ 1,^ 12,^ 13lts->^ (6,9,10,^ 12,13^15 3o)

6, 1o, 12,13, 1tso) (t,,1,12,15 58

(t6y 1o, 12, 3, 1t) 5o)?6,O, 1o,12 13, 1t 5o

(4t6,^ P^ 1o,^ 12,13,^ 1t^ 59)^ (4>6,P,^10 1213,^1 5)

TAusTAus, t^ amtad^ sa4junes^ ds»(4,^ 6, e, to,12,13/ 1^59

Alne, ha rusult of Pos-3 is » (t, P, 6, 10, 12 (3, 1*

So, tha alggrithmfor the Bubble sort>

PTO

ALt= 45 s^ tie nid

Nos, the^ ky es

B, Ku mid.

se, micd^ +1 ckcknq no

Lous = S High 1

Mid =^ Low^ tHgh-

5t

(^2 ) Mid 7 A7=90 wheh^ is^ mel

Neu Mid k

se, mid-I checkingmous

Lo 5 High = 7

Mid Lous +^ Hh 2 5tZ.

Mid = 6

Now, mid^ as^ ®6,^

uiek was^ agsd s^ fine.

Hene, 4 comparutens^ werL^ riaursd^ and^

f

in Zhe giem anhay.

PTO

C-proham_for (^) he (^) binghy (^) areh (^) alyorithmm =

inelude Ltdio.h> int main )

int i, Lous, hgh, mid, n, kay,

ankay (^) o pin (^) ( E^ nlar (^) the numken (^) of elumtnts (^) -> (^) 1n);

print( Enbe od^ inlagoy- n)

orli o, iznjit+)

scant (^) ["%d", k^ array (^) [); Printh (^) CE (^) n vaka^ le^ fid->n") eanf (d",kay) low = ; kh = n-I mid (^) - (lout (^) kigh)/ whike (^) (Lous (^) L= high

(anray L4ky lou= mid +4; a (^) okay Lid]= (^) =ky)

it4(% (^) dl (^) sound at (^) asray Aauilion (^) >/n,

ky, mid);

bruak

high = mid - 13

mid-lou +hgk)h.;

Case 1

right int rigkt)_

4 (att== NULLJ

beeak CaAr 2

ort(B; Ca 3

elafaudt:

n "^ nnalid^ choies^ )

break

Pren (^) do (^) yow want^ lo^ corlinue (^) prass (^1) J

ean %d*el;

skilele ==1)

ede1gpe isunt(»odilyAe ")

jntn

P-(roetgha mallee(sigrodrede))j

i (P!=NoLL)

P->ih =; P- sl = NULL

1 P

nesek=P hsP;

rolurnn

prin (^) not (^) snongh' (^) nanory

veid sort(nadaype "

nedslgpe t; nodiypa *S;

t L tile (t!=NULL)

ile (S!= NULL)

4(tinja) s-> ito)

tino

tSaho =S>mhoj

SAnso = e;

E Mi ehoiss ; 1

Een hu umban; 15

do yow^ want^ lo^ conlinu^ prs^ 1:

EJekese ; 1

Ela As mumhan 25

Elw chsise :

A2 Gumn^ element^ al>

(^3 3) 5, (^) 5o, +o, (^) 25, 3o, fo, (^) 7e, 20 and (^) 2P

So, ta^ contel on AVL Kuwe uill he adsn

Lach (^) lement ne (^) by ont^ amd (^) will be caukirq balamen faetor of zneh. hode bepore adeerg aelkr

o. I/ ths mods is imdsalanead tLAn ue will halarta that node ond hen add ls nnat elemant. Nou, ie

balane feclas. is g by

Balamen Jaetar = height o tejt us-Tre -kigktof nipkt sustru

&= (^) hr =1-1, o, (^) i}

I4 squslisns^ nal^ steis^ Aalia^ by^ a^ nsde^ tdanit

imbalaneud and uR lant to baloner it wwy rolalied.

NohBhtanes haclor. ny asplinsla ls 3 modes at a

Tderling plumaad 35

4-0- No huu node 3S is

imbalanerd o wt uill^ feyon

rotation

halsncd

O (

30

30

Now, fo Post^ - dsn taneing

follotu (^) Laht (^) Righe (^) Root AS (^) Past (^) ordn

ton abaut a AVL Thu form1d is

Pot (^) otdet 20,2, (^) 25, (^) 35, 3o, 50, Po, 7P, to.

Ans (^) To cnsrubt (^) ta (^) beinary eareh tee (^) lBsTD (^) for s^ zue paa order Tansse (Po), will first tid o ntrda

aeraltoT) pron tiepost ordn,. Tzen urild pr

e kko too rom u fot ordar ravsrsal an fo ihat aset ue will hunel our lt ses res arol ugkt nb re usung otda rauspal. wa wll repat h

POT-15, 10, 23, z5,^ 20,^ 35,t2 31, (^30) (L R (^) Ret)

TOT-1O 15, 20 23, 25 30, 35, 3, t2(L Rsot ) (Tmorelen rarsal^ o^ formad^ hunst^ arang^ ng^ lereg n asendiny &der)

F om POt Roatis 30

o, 1s,^ 2.0, 3s,34,* Fira we will coriuet tatsuhrr se POT- 1S, 1,23, 25, 2e,35,+2, 39, 30

Tor-9 15,23,2335, 3r,^

R

20

POT-5, L0, 13, 25, 20, 35, + 31, 30

oT 2(2,

(20)

Now, for rigkt sub ree

PoT-I5,10, 20_3S IOT (^) °, (^) 15, 20,13, 2S (^30)