0% found this document useful (0 votes)
8 views13 pages

Design and Analysis of Algorithms 2

Uploaded by

sanvidarda545
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)
8 views13 pages

Design and Analysis of Algorithms 2

Uploaded by

sanvidarda545
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/ 13

Page No.

Date

Alaenitlia fpr Ins entioa4Dela h


Explain vwith sutable
potx Hgl&g2 tllatrek
e
by the START
the ukad tack STAek leo of pop
pop opexctton bn

the Lin:
fust lww' nte Steck
Stack betose Push opeathen Ghe A
2Tof meed te
XXX
YYY

Tof ALaOR
XXX
This
n2 LLAva
PoP faom SThk
SThtk bete pop opeuaho
To 3.Set
XXX 4Set

STeLKafpopepaken 5 5e
ToP 3ToP
XxX YYY
AL&

4The
aLOpregcntrtton.of
Dq vaiable AX STK wch
Stack calla tDr the l
the mnalwna hub
oelenny that can be hele by
inrthestackes
for the Checking so 2
OvERELDW the Case
opeHatton(T0P MA61K)ad UNDERFLbor hthe Cas
of pop opcation (TDP=D). In Coiahasfthe sked
Pepsesetation of Atacks Is free of these seqpèesrtaien.
aeguirehmets Fhexe ds na
te nked stack amd henelinttaton en the Capacity of
tCag bupporf.as many puch
opeattens Cinsertten of ndat) otheee stohage t
Cthe AvATL list an auppo st. This clispenses with
Imeed tE mantaân the MAKSTK Yartable a the
the checkavg of bVEKELO of the linked staak consequsty oo
cluang à
push opeato
ALeoRIHM PUSH_ LINKSTRCK (INFO, LINK, ToP, AvazLgl TeM)
This prOcedusa pushes amn ITEM inte a lin ked ttack

LLAvailable spae 2 z AvAIL NLgthen nite QvEKELOnl


RLRemoue fot node fxonm AvAL Ust
Set NEW i AYALL Ow AVALL =LINK LANL
3Set INFOCNEW: Iterm LCople Item nto neLa medo l
aSet LINK [NENI Tof [Nes nacle poins te the ontgnal
top nocle án the sfacle]
5 Set TOR = NEN CReset Top te pond te sthe ne) mede at
the top.of the oteck

ALGORITHMS PDP LINKSTACK (INED, LINk, ToP, AVAL, ITEM)


This protecux, cloletcg the top elemont otf a aked atack &.
asstgn te the vasoable ITEM.

Stack hos an fem te be semoved 2


If TOPs NULL then woáte &UNDERPLDW awd Fx
2st IEM= INEo LToe] Lcopies the top elenent of atel
inte ITeM
B.Set TEMP TOR pele
eld valua. ofthe
Lernunbek.Toethe
t p s t
t e k t lntin thetec
te thefack
and act

mtbecinte
ibatvexthe cencltnTots hNULL
8heConditionAvataNlLte check foslahe
6tax

Lcan take pla emy at ma endCallec fhefrstsc Sac

toxera fod andan arakaeein.descorilbsgaiscn

4he thst
cna.QuLL ll be. thc.fhstclaaut ut o

ihuaiacs ch as Loat
InfhsttiCk2Eo)st
o din ueuayiÇThe autamslbilawalHg
ito pass. ths.daftochon fn
QQuLEnch
SeLe at a hant fosa
Suaktpn
Dare

qLieue n Cenptax scenca


An imporfaut caanople of a
tmeshatiggstcm a In cokch proganz te
eccLKS in.a
aquLe skle wattngto ae caeatad
the dame pricrity forn
KEeRESENTA11ON Oe QueUes.
Rapseseatacd io the Computay in vaious ways
Queuss mag be os ox Lineax ascKELS Unles
ALSually byy mieng at Onariay
fmpled, each of e autugtll bemaintaiu
othessebtatacl ox
the location oh the frost elamat of thequaue
cotaiu ah the saox elamat of th
And ReAR, centainng sthe Locacton
condho koNrSNUL aill 2ndtacte that the quaue
qutue. The

shouss the way the asQL in Hg4 uoill be


Tguxcs5 QUeUEH Nelemes
otaacd fn menaxatng daleted -fron)
Bg5alao ndicals the a elamotrw wil be
the. sau u olanant ll be addad to tha
Hhe Quaue and
Obsexve that wheyaxey an elemet hs daleked froog.
the alua of RON A Dnercaato by5 tisc .
he quue,
be Sonplemendcd ky the asgne
TRoNT=FRONI+1.
pLLE,he
Sillasas hene am elemast s added -teo tke.
value of KEBR is nReased by 1;. this can be Tmpleltac bsy
sthe aignmsat ReAK KeARtI
Thismtama -thataftex NInextons4 the Beng eleaat offh
QUEDE CA] or in othey words i euetlly
This
the que will odcupLy the last pat of thacaLsTs
cUs euen though the quue ftself nagg nat Centan y
elenes
Page No
Date

at the tine the quzue claL BCEpy the lart fat ofst
aray, ie when REAR:N. One way ste do ths sto s ,

changing FRONT ad REAR acLOingl


IIEMa abave. Ths procecue may ke we eapenaive
Ihe produe we adopt ts te asuN that he cuay QUEUE
à circulax tht, that QUEUE L1] comes

the qaue by Qasiging JTEm te QuEuE (]Speciallys

then aag
QuEUE Ckese]4 21ÊM;
QUCUE
REAR: 4
AAABA8CCcDoo
2 3

FAONTE 2 QueDE
ReAR4 B88ccc Doo
2
4 56
N

TRONI 2
(6)
QvEVE
ccC
DODEeFPF
FRONTE 3
REAR6
22 CejoooEEEEeE
3567es N
RRAHEREPREKEAiTON CEAGutUE
QUeVE a
LySimilay f FRONT = N, and an elamant
te Nt1

Suppese that eu quuue cCorelalsg y ene alamaxct , Ire


suppse that FRDNT= REARNU
QMduupgese thot the eleasd u daletod Thon kue dsg
REAK= NULL
FRONT ENVLL
to ndicade thec the guLLe Saet

LINkeD KePRESENIAZLON OF QUEUES


Eplain h sitable Aloothen Tscshod Deletroanflfee
inked quauee a quaue implanaudad aaabnae et
9A he mnodat
With twb pon yaszables TRoNT & ReAK po)chng to
ohich is n the TRONT amd REAK f fe quaue The LNED
fele af the tist hod the elamas of the quaLe cs the
LINK frelds held pohdtos te fhe hergh bartag elemac the
quaue.
B68

FRONT

4In the Caue of sertton nto.a inked quaLueq necla


bortbwed frono the ANALL st aud aug the Hean to be
aprceNcing sthe quaue. The RAR polix pctalad
to.poirt totae lart nee iust addod to tha tist Tn the
FRONI daletd and the fesct TaoNt peludes b updals
a polnt to t e motmocla tn thest

Trued ELE te Quue Q


B8B ccc

AAA

TRON FRONT 2EAR

4The aay apssoabon fa quuesutfens fn the


desau back af Lnikcd CyuaL Capacsy This in tnn calks
OVERELO Cosclition
nsecton s ada inte the qusut
LyAlso, dus. te the Enhenat
data stuke n thich.clata dasadvantage. of the axay
oevernant cxpenLhvets
aitenante ofthe qyuau.Cale foc ts cculay Toselenestt
L4In Cenhast the nkad
may be. Bhsead Inte he. quaLe
NoDE =InfocmattDatLEnk.
AVALmemen vaxiable
Pege No
Date

KDEQVES
4A deauk fs a Uneag st fnwohich elehibnitecon be
adead or Temoved at eitheg enc b notin theicolle
The feNYm QlegLa s o Contrdction of the hamy clouble-endodl

stastatced dugua asnd an sutput


y* INeT-RESTRICTED DEQuE Which alleus ?udextrans at enly
Sne end af the tist but alleusdalaten& at bath ends.of tha

Ly DugpU[- RESTRLCIED DERuE which allouK daletions at eny


pue emd sf theist but allows Tisettioug ot both ence of t

LSETE 4 DEQUE
AAA 868
2 3 45

DEQVE
WWw XX

2 3 4 56
Cb)

TeaoRLTY QUEUE
LA pioity qyuaue a collection of elembite duch thact
each elimt has been assghac a priort auc sh-ht
the oxde a which elemonk asua oleleted aund processedl
Comes frtm the folauing
Pags la
Date

GDAn elesnaut ot bighex priaritky froctsd bat


ny elemDnt ot lousen prioity
43)Two elemo with the sane prerty ana pece
acerhng te the boclat tn cohich the wen cddacd to
the qpiuee
iatemi progtams of high paionityasa precesssd for
Cnd progam th the Sane priaxity forna aataide
hat is babad Lstand Eplal 0 the Repsuuatteo
LINKED LISt
LA Snked istor ene-a istq bae collecton of
ldata elermbi Colac mecas whexe the inenL ordax
given by meama bf pole That aeach nacle d
ts hb.past:the frst pad contalns the infoxnahog
of the elanaud,ad he geconc psck Callacd the
lor nectpolnkxleld Contas the adeses of the ozt bnkellt
n therst da
Zng aqschematto ehagtar otp.a inkad ist it
G.nodasEach nsca j pictoed with two patt The lat
pot supaAseNds the lngormcien pact bf the
may Centalng am entre Secerd of
data
nacasshich
pax sapxERela the jterns. The sgli
natpoitx feldof he hadua aae
he st This folsus
theaual paashse of clrauil ng
node appeas in the given felel.
node contis adpeial valua Thepotr o the lat
callacd the ull pointDs,
Page No.
Dats

Name
DR
infoxation pat of thicd nael
START

Hg unked ust wtth Gnocdas

KePRESENTAT1ON OF LINKeO LI61S IN MerOR

yCet lzT bea in kad st Then L1ST wtil be malntkalnocl n.


anane nlass thelse speiftedar impied as foous

eall them hese INED On LINK- ÁNdh that INEO LK] anl
LINKCKJ Cortaia saapechvely, the infemaken paxk the
nextpointe fteld ofanocla of LIST
As noed above LIST Qlao reqrs a wasdablaa nanma áuch as
stAAhch contalrs the lncation ef the kaegiarng ef the List,
Cd ahatpoivia sentinelcenoled by NuLokich ndicaka
the enl of tha list. Sinse the subscatpts of the cas IhEO.
unles othunwrce sfatid.

HenDeR LINKEO 1LISTS.

cotlrs a spetal nece , callac theheoclax nacko c the


begiangofthe st
Qsancbe heaclar list aa heacon List wherxe the
last nocle Conta) x the slpante.
Dats

(6t circalat hendon s t a henca wohese the Los


polvcts back to the heocar nAdo.
START
HEADER NODE

(a) Grypunled heaelr t


STAAT

HBADER
NoDE

40bsenve that tha list poiex STAKTalayspolsta fa


the henduy necle. Aceondtngly LzNK.CSTe]NULL bndlata
that a gieundad henclex s emply Gwd LINK LstAErle

LyA Hhougk Oux datt


data ma bebe mahuctanc ky buaclax Ast n
Ordina inkec bt.

Ogcbecayanode, not he henrlex neeuhen Aued w


heodty asts Thus hst hocle fna
Hhe node folloulwg the heacde st s
sceton Df the hence pcdea awc -fhe
StARTa asth erdlna
oTdinainkec ists
Pege No.
Date

Alaoxtmll ohich uses a_pointor vartable PTK to


hesea chrculay headen Last, s eseatial tse Aame
a Algorfthn 5ls uolch taveses an orelinaty linked
Lst,exopzt thact now the alqor ithm C1) begt sth
PR =LINk Csmer] (not PIR STARI) auc (2) enea when 1
PTRSIRRI Met PTRa NVLE)

LYrculay headex Lists axe facquaty cased sng feocl


af ordinaxy inakeelist becase ma peations
ch ea to state and toplement sng header
Asts. Ths coMes fron the fallong twoprnpei
ef Chraulax headar nti
(0The mull poiade ús notLsed, ancd hence all pöta
pontos Ceutain halid adolxesses

2)Evey Corinany) mocde has a predacessoxg de The


fst ndde may hot Baqyixe a spcial oac.
2(Travexshsg a Chcalax tteadey List)
Alaocthn 5:ll 3(Travoahg
Le LasT be at creular heelex list a memery, This
algortthm aveses LISt, applytng an operatlon PkoCESS
H each Mode. of L1ST.

1 Set PIR = LINK CSIHRT].Tritaliges the poietox Pr


2 Repent bteps 3.amcl t wile PTR START:
ZApply Pko cEs5 te INfO CeTRI
A Set PR LINK [PIR]. EPTR mow poi tt to the neat noe

5.Ext
IEnd of stsp 2Lop
Thona Snkedl Jsts
hh somektag appeas fa the itonatuka

(DA Sinked ict wh0e Cost ode peint back to the fost
de inhtod. ofcondaan ng the uld poilay callad
aCrcalay

beginning of the Aist auelaspesndtoailo ooo at


nda of the t tontalaehenattc oiogtaksg
Lof these bsts

You might also like