You are on page 1of 3

DATASTRUCTURES( 19CS3PCDST)

3rdSemester
PRACTISEPROGRAM LIST

Sl
.No Pr
ogr
am name

1 Givenast ackofint
eger
s,wri
teaprogram thatupdat
esthei
nputstacksucht
hatal
l
occurrencesofthesmall
estval
uesareatthebottom oft
hest
ack,whil
etheor
derof
theotherelementsremai
nsthesame.

Forexample:
I
nputstack(t
op-
bot
tom):566587
Output
:668755

2 Wri
teaPr ogr
am tostor
eandr et
ri
ev ethest
udenti
nfor
mat
ion(
USN,
Nameand
mobil
enumber)i
nLastI
nFir
stOutorder.

3 Mari
awantst
odel
etet
hei
tems,SugarandMi
l
kfr
om l
i
nkedl
i
st.
Simul
ateusi
ngC
Pr
ogram.

4 Abr acketi sconsideredt obeanyoneoft hefollowi ngchar acters:(,),{,},


[,or].
Twobr acketsareconsi deredt obeamat chedpai rifanopeni ngbr acket(i.e.
,(,[
,or
{)occur stotheleftofacl osingbr acket( i
.e.,)
,],or} )oft heexactsamet ype.There
arethr eet ypesofmat chedpai rsofbr acket s:[
],{},and( )
.
Amat chi ngpairofbracket si snotbal ancedi fthesetofbr acketsitencl osesar enot
mat ched.Forexampl e,{[(
])}isnotbal ancedbecauset hecont ent sinbet ween{and
}ar enotbal anced.Thepai rofsquar ebr acket sencl osesasi ngle,unbal anced
openi ngbr acket
,( ,andt hepai rofpar enthesesencl osesasi ngle,unbal anced
closingsquar ebracket ,
].
Byt hisl ogic,wesayasequenceofbr acketsisbal ancedi fthef ol
lowi ngcondi ti
ons
aremet :
Itcont ainsnounmat chedbr ackets.
Thesubsetofbr acket sencl osedwi t
hint heconf inesofamat chedpai rofbrackets
i
sal soamat chedpai rofbr ackets.
Given a st ri
ng ofbr acket s,det er
mi ne whet hert he sequence ofbr acketsi s
balanced.I fast r
ingisbal anced, returnYES.Ot herwi se,r
et urnNO.

5 Anishaisamusiclover.Sheusual
l
yput sal otofsongsi nhermobil
eandl i
stensto
them whenevershei sfree.Shereceiv
edahugef ol
derofnew songsf rom her
fri
end.Shehasanapponherphonet hatdivi
dest hosesongsint
odiff
erentplayl
ist
s
i
nhermobi l
ephonei .
eifthesongismot i
vationalthaniti
saddedtotheplayl
istA,if
thesongisr omanti
ctheni ti
saddedt ot hepl ayl
istB,i
fthesongissadt hento
playl
i
stC.Ifshepr essesabuttonintheapptopl ayt heplayl
istsinci
rcularmanner
thenthePlayl
istA,BandCar eplayedincir
cularf ashionuntilshestops.Shecan
alsochoosetopl aythesongswi t
hinaparti
cularpl ayli
sttobepl ay
edi nacircul
ar
manner.Simulatethisscenar
ioofplayi
ngthepl ayli
st sinci
rcularmannerandal so
thesongswithinapl ayl
i
sttobeplayedinacircularmanner .Alsoshowi tswor ki
ng
whenshedeletesasongf r
om play
li
stBanddelet est heplay
li
stC.

6 Harshai sbrowsingf oranart


icl
eondat astruct
uresthroughhi sbrowserinthe
i
nternet.Onthefirstwebpageheopenedtherewasal i
nkt oanotherwebpage.He
cli
ckedont hatlinkandt hebrowserdi
spl
ayedhi mthel i
nkedwebpage.Hehas
donesuchNcl ickswhi chhast
akenhimtonewwebpageev eryti
me.Nowhewant s
tofindoutwhichwebpagehewasl ooki
ngint
oaf t
erxcl
icksf r
om hisfir
stwebpage
wher ei
nx<=N.Hel phimtoknowthewebpagebysi mul
atingthisscenari
oinCusing
asinglyli
nkedli
st.

7 Considertwosi ngl
yl i
nkedli
sttostor
etwopoly
nomials.Per
for
mtheaddi
ti
onof
thesetwopolynomi al
sasshowni nt
heexampl
ebelow:
Polynomial1:2x^3+8x^4+5x^
6 and
Polynomial2:3x^4+4x^6
thenoutputshouldbe2x^ 3+11x^
4+9x^
6

8 Createadatast ruct
uret
woStackst hatrepresent
st wost acks.I
mpl ementat
ionof
twoStacksshoulduseonl
yonear ray
, i
.e.
,bothstacksshoulduset hesamear r
ayfor
stor
ingelements.Foll
owi
ngfuncti
onsmustbesuppor tedbyt woStacks.
push1(i
ntx)–>pushesxt ofi
rstst
ack
push2(i
ntx)–>pushesxt osecondst ack
pop1()–>popsanel ementf
rom thef i
rstst
ackandr eturnthepoppedel ement
pop2()–>popsanel ementf
rom thesecondst ackandr eturnthepoppedelement

9 Youhav et hr eestacksofcy li
nderswher eeachcy l
inderhast hesamedi amet er,but
theymayv ar yinheight .Youcanchanget hehei ghtofast ackbyr emov ingand
discardingi tst opmostcy li
nderanynumberoft i
mes.
Findt hemaxi mum possi bleheightoft hest ackssucht hatal loft hest acksar e
exact l
yt hesamehei ght .Thismeansy oumustr emov ezer oormor ecy l
indersf rom
thet opofz eroormor eoft hethreestacksunt i
lthey 'real lthesamehei ght ,then
printthehei ght.Ther emov alsmustbeper formedi nsuchawayast omaxi mi zet he
height.
InputFor mat :
Thef i
rstlinecont ainst hreespace- separatedi ntegersn1, n2andn3descr ibingt he
respect i
v enumberofcy li
nder si
nst acks1, 2and3.Thesubsequentl i
nesdescr i
be
ther espect iveheightsofeachcy l
inderinast ackf r
om t opt obot t
om:
● Thesecondl ine cont ai
nsn1 space- separ at edi ntegersdescr i
bingt he
cylinderheight sinst ack1.Thef i
rstelementi st het opoft hest ack.
● Thet hirdl
inecont ains n2space- separ atedint eger sdescr i
bingt hecy li
nder
height sinstack2.Thef i
rstelementi st hetopoft hest ack.
● The f ourt
hl ine cont ai
ns n3 space- separ ated i ntegers descr ibing t he
cylinderheight sinst ack3.Thef ir
stel ementi st het opoft hest ack.

10 Supposether
eisacircl
e.Ther
ear e pet
rolpumpsont
hatci
rcl
e.Petr
olpumpsare
numbered 0 t o N-
1( bothinclusi
ve).You havet
wo pieces ofinf
ormat
ion
corr
espondi
ngtoeachofthepetr
olpump:
(1)t
heamountofpet rolt
hatpar t
icularpet
r olpumpwi l
lgive,and
(2)t
hedist ancefrom t hatpet r
ol pumpt othenextpet rolpump.
I
niti
all
y,youhav eat ankofi nfi
ni t
ecapaci t
ycar ry
ingnopet rol
.Youcanstartthet
our
atanyoft hepet r
olpumps.Cal culatethefirstpointfrom wher et
hetruckwill
beable
tocomplet ethecircle.Consi dert hatthetruckwi llst
opateachoft hepetrolpumps.
Thetruckwi llmoveoneki lomet erforeachl i
tr
eofpet rol
.
I
nputFormat
Thefir
stlinewi l
lcont ainthev alueofN.
ThenextN l i
neswi llcont ainapai rofintegerseach,i .
e.theamountofpet rolt
hat
petr
olpumpwi l
lgiveandt hedi stancebetweent hatpetrolpumpandt henextpetr
ol
pump.

11 You'r
egiv
enthepoi nt
ertotheheadnode(f
ir
stnode)ofasi ngl
ylinkedl i
st,wher
e
thedatai
nthenodesmustbei nascendi
ngorder(Sortt
helistf
ir
st).Delet
easf ew
nodesaspossiblesothatt
heli
stdoesnotcontai
nanyv al
uemor et hanonce.The
giv
enheadpointermaybenulli
ndi
cat
ingt
hattheli
stisempty.

You might also like