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

DSA Assignment

A linked list is a linear data structure consisting of nodes where each node contains a data field and a reference (link) to the next node in the list. Linked lists allow for efficient insertion and removal of elements and can grow and shrink dynamically. They are commonly used when elements may be added or removed from the middle of the list frequently.

Uploaded by

Sourin Sur
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)
94 views

DSA Assignment

A linked list is a linear data structure consisting of nodes where each node contains a data field and a reference (link) to the next node in the list. Linked lists allow for efficient insertion and removal of elements and can grow and shrink dynamically. They are commonly used when elements may be added or removed from the middle of the list frequently.

Uploaded by

Sourin Sur
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/ 22

What io oat stouolhro?

A lata slzueare io a stoane Hal in usd t sbre


ane oraa nize adlala. J f a
csay ortopra dali
On a eompuler 6 h a
Kat i can be and
up odaled jficiertt aceesd@
A dala struetoe i t a a woed foa ogop
2nPhe dlal. It io aloo uoeo for þrecessia, *0V7iev

2) Wh do e9e need data toueiires ?

Sala &trueuse are Ro main baa ma 0mple


Seienco algo aitkmò as tKoy ouoble He þoogoa m
hanclle e data n an
oPPleiont e3a. Tt plays
a a
a al oole ln
ouhane/ng the þeator mance oF a
SojTasase 0 a
paogaan as tke mai funalion a
he socsave is o aud aretieve He wo@r
e

ata a fast ao boaibe.a ataueliie


brsvides
otficianoM. reusab:lky ad abst>aclion
Ho A
dolo struelavoa are
elhsfted)
Sata Struelure
A
inear data struchire
Nan linCor dea stouelnse
Statie deta amia dhia
Struatipe stouelaoe
Tree

A7 Stack ueue Lhnkod LiatF


iraz
nir

n*eeftor
nnoa
fre3 Strususe
ab
npa
sfoueli Nor
Linoa a l a Stsuolure
ae
alomeuto
Sala
a30a a u g hierarokial
ala elem@nlo alta oheod in

n a
neod 0reroker e man noS.
elemonli is 02

affaoded blb bore vious od


t
next aacent.
Cata elemanto
betoavea be oavezodna shale
Cauta omens
can

in a singe oun on
un oDnl

MomaTy io uizeo
uiized
uliized in
MmoH i nol
fn an ofieient co0ay

lincar dat Apblcaliona af nen -lisn


Applialiono a in
in dala staueludes as
dtouelu pO8 are mainly
abpkcaliox softesore eleveleb- Artrfioial Itelligence
m@hl.
an image baoe @sdihg.

Example: tae@s and


fvcambleo: arday, staek,
Queue, lnkead lt ste.
anbha

Crefine ADT9
An ADT io a mavkomalical model of a dala
stouelu se that sbecifieo the ioe of data slored,
Dhe epealiors suppoal On Rem, and tHe pes ef
aa mefrorg tle opezaiomo. An ADT speafieo t
a opealion doea, bud ut hots it dloes it. kn ADT
Can be inplemestood uoing one emay difforst dal
Stououses.
6) MenDon the Beopbes ie o ADT?
7@ Conalruelozs : ereale an inlarce that baskeuaa, olala
Ace eas Puneliona: Funeliowo cokie ot us t access
elemeuts of Ke oba pe. Enampla bke J81N).
Manipualion beocecdure: It sorulo lotus manipulate
0 modi he dah h e . Exanph bhke Insezt. Welele

DWhat aze the c0 et mple.monli onkollst


A Linked l t ca b e implemented uong sTouebare
and pointoas.
iYuet LinkeodList
in data
sfoue LinlcolLsinoxt;
3
The woed to ereale
above deelaralton io
aa nede ho k e d lit. The data fiold slovss
The elément a n lhe nert bolnler o stooe he

addrea h e nex ndee.


What ave le tbes o linkesd lest ?
Tybes leukes ot
Singlo anked l t
lonkod liet
Coub eiacular liukel o t

eireular lrkes liet


(oub
9) Hos the
he sing Linke l etn be 3ehrsasutea 9
a Het at het data
dala NULL

Head

Eack nede had colain


kas a value (data) and o pohdez
to tHe nboe next n tke liot
Eack ink'past con lado He aoldre sd of He next
hode

next bast o tle ast node


0nlam
ink or
node.
NULL value skiok slanifies tho kdtHe

Hea pohter askiok þohts aRe ist uoede in he


liot
doubllinked liot be eprsso.Jed?
10)Ho he ea

NULL dalo e breviou dala i dafa NULL


Tarl
Hed

O Eae hoele has eonlain 3 oldo, as value(dato


a2
ad'poiles past (þoovious and link o7 next)
OEach brovious bointe conlains the adldre4s of
#he preiouo nole in the lit.
O Faeh next
next þoter eonlaino He odsress f He
nex usde in he list
Paovfouo pomfer a o He fiast ode and neat
pohte ef the laot hede tHe laked lost eonlan
NULL valueo colieA signties the end o tho nee
Head boinfes cokeh bon
bolo He fiast noode n Ke lst.
Tail poAtes oAiah paiTo afp,he the at
He aot hosh nthe ot
)What aze e benej ito ADT
ADT o a b l e , dsbust and i based on pohelpos
o Objeot 0rionted Progaa mmirg (o0P) and
Soft csase Enginea er
( n ADT can be reused aseve.aal blaced and
itrecu ces eodina ofoato.
Ercabsulalo nsures that data annotbe orrup

Woka vaaiouo abesalhon cannet be


intogaahol
Tanpere eak btHe opbliealilen padsgpan
obuatdata stuotmre.
(A D T hsued a

W h e n slng lnkeel s t
eam be vepaeseted a

cizulaz Denkood let2


he na next þoiter oftke lastnode oftHe
When adoloross o
H e memoa
io
Lrkes Conlbns
Sig likeal lst fnateaoo
ethat shoh
he iost nede
Hepe
NULL

elatanex datamotdak met hext

eaa
ocparesoted
be.ebresonted
list
Then
Then Re sad Lsnkeol and oe ean calleodi
liot
linkea
eir nlar
keod l s t
S/g eiroulaar
3 When doubla linked lt asn be
be vepresentedns
oircular kes ott Ta:l
Head
dala next brov lalahe
bv elala ext

tle fist noole of He doubly


T poev boinler a Lost rooe
note
the ost
of he
aokrsso
linkes t eonlaiho momo
t e lost nosle
Otbolnler e
o a t lit and Phe fntroe
of The Ct eonlaiho m@m0 a/ress otHe
of tle
tha lis. Thsr the oloub nkod liot
eau
be
linkeo liot.
prosenteo co eireulas doub

19 Whad axe e advantegso o liukeslistt


I8ea lion Qu deleläbn in Oinkeo Dists are ve
eJFreient.
eonolant lime.
Linkecl iot exban dloein
be2

For inmpe menlalion ef slacks au queu@ andfor


ebae senla.lion of tae6s aud gaabho.
'inkedLislys ase woeo for d namie memoy
okcok mOano feclie memo
allo ealioc9kcok uli lixalior-
honee, ho mem0o eseo lege..

I5 Ltatout the demaails of lkod liot-


is more in nked ioto hen@e, cone
. L o e of pomers
equised more memor.
and
and ae 9.uiges Oh)
.SeoreKng an olemout io cestl
DEme eomplexi.
0,
.Random aceebd io nol þosibe due to dna nie
memoy allocalon

(G
.Teaversinai mora me
e0nsu mia ad oovezyse
tra veash o nst bossible in sina linkod lista.
Dests.
6) What ove
advantoges Qd dio@van lag@o aaara
implemenlalion aover lenkea iot 2
Linked iat
Acd van Tapes Ravdom Hee@xd Fast Fat Is0 Lon/elolion
Seasek Tim@) te
Less m@m00n ecle n a n i a size
per elenOn EPiciet memoy
Bettar cabhe Loali alloenlion/ili zalio
isadvantagesSloco inceslior/eletion Slbw searek lime
im. Mora memoy neecde d
Fixoo Sze pe ode ao addito nal
In@fiai ent mem0ay Sloarage aequaeo or
alloealion/uli lizatio oteas.
)What io a oiaeular rkeo Diet2
T h e link Prela a He last o e eonlains tke m@moay
The
addre aHe fhst nosk,
Sueh a laked lot iw ealles
eireula lenkea bot

e need af head poinler


18) What j
hat l.bcel lit9
19) List 3 Orampkoa tuoOs

and quoue.
Inple menlalion of saok quoue.

Tmpkm@hTallon of gaaphp: Adjoceny t zepros


cskiok woes a
tion o aoephs io He mbat bobular
vesloes.
Dinked list to store ajoos.
We uoe a lbod Lt
ena mio mem0y allocalion
offaee bleoks.
alack ?
2) efina
A Staek is an oaderoa/ osllealion ofitins inlo slhieh
nes lemo may
man be inoered and Prom cokiak ilems
mabe dekteo aon A , oalleo He slak

29) Whait aze e operaliors of He staak?


void push(staukts, it elomet); /*I.ert an aknaat hia
inpop (staok *s); /Romove adetban He topstagk
olemanl
voad er0a faok*a) oate neA9 sãok 7 a

tisompfak ); olook i staok iu emy7


ic peek(staek"s); /T4 retuns tte. top
ilm from
he ataek but doss het bemove

3ze (afaok*3); / Tt velama tha maumber of Tms on


the staek
23) Waite le algorithm t bush or add ebwnt

HLGORITHM:
PUSH (STACK, TOP, SI ZE, ITEM

staok io he asoo cok N elomento. Top in e


poktes e tp o the slkmet of#e arro
ITEM be naestod.

TOP N len [eheok OvesPo


PRINT STAOK jo Full or Oveajloco
Exi
9
End if)
TOP TOP+ 1 Inere mert e TOP
S TACKTOP] TEM I nsea7 He ITEM]

knkes l t
4) Hoco he operaliona peform on

hm-plemenlalon o staek ?
7 3faek Czeahon_uabo Lked lif
void ereate (staek **p)
t a p - NULL; /top ponto to ANULL heaZio
n p staok »/
3
an olein t tb the staok by iushha ked
void h staok*p, ht elemat)
staene;
OLS-staol") mallee (dkest(stacA)) ;
ithes= =NULL)
potfA \h Staok io full),
Oit)D;
3
hesvalue = elemsnt
ne9next =*ap
tep nes
3
_ (
C . C
( |1
ET O
C
25) What ade he apklicalio o stack 9
iset abb lioations
Pape- vlsi d hisloan in a Web baosea
lndo seque nee atext ed Toa
Maokine
Chah aaf mehod callo in the Java Viataal Mathine
Vali due amL
Tnaioeet appi ealiona
Aurlaoy data structnve for algoait hm
Compo net o oker data staudnde
26) w e Phe algoith m to pop a eleme Prom a

staok 9
ALGORI THM:
POP(TACK, TOP, ITEM)
io the a J r a n coh
N elem Onts, TOP i H
STACK
poter H e p othe ekmet o t e asa

ITEM be nsetod.

iTOP 0 #en [oAeak wdeadlos


PRINT STACk io Enpty or Undertbs
E xt Cend
it
TTEM =8TACK LTOP
TOP T0P-1
Re
q,u@ue 9
etne OmetsAa
27
io an
abstract clata strualu ,
ueJuene
ne
open
l.like staoks, a queue io
Similas Staoks.
Similas

msert
at both o , One end io alsay4d woed
asm0e daia
daaoueue ad oer io usoa
dlea ueue
2) What ade he operalkon a queue
voidd noueue (ueue *q, telemet
n he queue */
* Insestf an elomet
int deauoueausue ) Romove an ekmeut foom
he 9ueue
gueue *erenle)) Create a nezo queue */
h ombgeue *q); / eheok i queue ls mpi
t dize (queu@ *a);
/Rotam te no. of elomeT
ueue

29 Wote a agoitom t mseat a elomet ho te


yueLe 2
ALG0RITHM

ENOUEUE (YVEVE, REAR, FRONT, TTEM)


OUEVE he azam colth N ekmeuto, FRONT »e
bohter that conlhno He loealion of tHe olement to be
delofed od REAR 0lano he lbcalton othe hoeato
olomt.ITEM io the t be hoe fod.
REAR = N-1 #en eleok Oedou
PRINT" QueUE is full or Oveaflos"

13
1FRONT =NULL tHenCeek hoat onl on
FRONT -1
REAR

eloe
ReAR REAR +1 |Inczement REAR

uEDE LREAR) =ITEM Cob ITEM ts ReAR poallo

Rotuan

30 What aze he pes ot uoue


yuoua

ueMe can be o Pou beo


Shble Queue
Cereulas ueue
Paioar ibj Jueue
e - quoue (pubh
£rded Pueue
3) Cetime double eded quoLe 9
nserlion and dolblion
T io a queue in cokok
Cakeo place at He botk ando.
by linked lt ?
Hocs the queue o hnplemeatod
stouet q,node
hval
8touet qode noxt;
3,
sTouc QuONe

stauot gode foont, *qaear


Eapede stauat queue JUevE;
an elem et
33) Wote doun te algoaltm o delete
from a queue)
I FRONT = 1 0R FRONT> REAR
Wate UNDERFL0W

SET VAL =VEVE FRONT


SET FRONT =
fRONT +1

END OF IA
EXIT

34) What are Re appkealions oOuene 9


c t apblaions
Waltaiats
Acaeso shasea a0sourees (Ex- pahtea)
Multiprogrammi
Indiacet applicalio
AuiloT d stouotae for algoaithma
Componet etker dala &truelavep.
A
35 What are He enauene & dequeue obeaolAo?

Qnqueue):It addo a noA n the rA


athe quene
dequene): I vemoves He rem frort item
r o m he quQue

(5
36) At 12nguisk betcoeen stack and 9ueue

S tack Duue
Elemento aze hseat Elemonth ore insealecd os
ad demovea af e same 7Omovedfrom dijjerat ed
dJferet
are wsed
Here, just On bote io Ts0"polntea
wwed.Ibohto He tob t poht frot ad ende
o h e staak.
Staok follocsa Last In fast ueues folloeso fist In
Ot (LIFo) coaer flat Out (FIFO 0rder
Staeks are visua.lireo as ueues, abe visualizeda
verZical eolleelios. hoaizonZal celle elioe.
Man operaliosot staak Man aperalions o queue
Dre puok and pbop. a7e OnqueuO and deaueue.

3) Conveat He Idi Srossion (A+8)-( +D/


b poatfix and refix oxproasion
Indix Expralon :Are)*(et D)/p
Idi poxt fi
Opealor 8tak Poot ixeab
Cuaret Smbol

A A
A
AB
t
ABt
ABt
ABt
AB+C

(19
+ + D

D D
&,
2

O+ + D
Co

++1I+ +
c
(O

u
2

+
D

2
p e elor Staak
Curreut Swbol Poei Prp
AB
+ AB

A Be
+
ABD
D + AB-0 D

+/ AB-CD

+/C AB-D
P /C AB-eDP
/C AB-CDDP
+/C A8-eDPR
+/ AB eD -PR

+/ AB -CD-PR

4) Ezplan he usane of tack on recu ssive


algoaltkm plemoulatis
Hanoi Tocoer posblem io a oxampla ef a veLurshe
pro blem solved
buoi staok.
Thio i a booblem cohio hawe 3 diok oJ
didd eret size ond 3 ood A, b 20 . 3 dtoko aae
paesnt inb ood A. So, us tesget is To move the
3 diok nlo god C.
20
A here i som Q0nd'ors
lime
One One disk can be mOve a a

upber most dsk


conoisto oakin the
Cach
E aoh hove

sfaek top o austhor alaok. oa


from One of the on

an Smp zod.
be placed on top smaller han it
No disk ean

he definio
of
Faom
A a@eurslve funelion, a9e

A8 olion
that i f afun
kno o

all irselF agsin:k agan


þexlieulaar
Vo peafoam a
calles
task the funolion
ao Reenrshe funclion
AC
t r heb pasblhn,
m o v e the
first disk
to per
fnelion. knel
A 9e ealle a

aokele
To perfoTm the
A opeaalto he Funolion

oallee it self ve curshek


6 lims.
A

A
2) Give he applicalio of prior i queue
9uoue2

t o s t both algoa
h o afost
Tt i uoed TRe C:kstbo'a sshn
Tt io woe n brhn's algoaithm.
GTt woeo heap s0t Soat.

It is woe h o Ombresson Téokngues uke

Hutman eoVo

You might also like