Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

(

Pmoted malysis
in amoiized analysis
averoge the Hme rqwf o
, We
Porform a Saq uence of d ata shucture opeUT ations oves al
the Operahens perfoTmed
imo ied analysis helps to shew hat the qve ost
OF an
0peratiom is Sma ? we average ove a seq
of
uene
operations even though a
Single oerahorn wthin the
aquence mignt to expensive
moT zed analysís is diferent hdn
dverane-Caje analy sis
Amo yi 2 analssis quanantes ha averaqe fes foi mu n e df
each 0erasion in the wTSt Coße.
ft has three most Commm techniq neo

OAggregak analysis Pen fonm M

2The actouni ng method amov zRs analysis


we
get Pnsigh s intoa
3The petenha mehed. Po1culas ea Shchure
which heles fo opimiu
Aggregale anolysi's the e desiyn

Pn this method we shou


For all n
a
sequence of n operatens takeo wOrst-ase thme
T (n) in tota
o +h wsst
(ose,he aveyage (ost or _amatred (osF
eY Opetatíon is
T()
n
this amortizes (ost
upplieo to each Operation
even phen there ane several fype o oprati ons in the
Sequere
Stule Operotions
Fundamental operations 0 stade treke 0 C1) hme
Push CS,r) Pushe object r onto StuckS
Pop (s) Pops the top of Stack s retums th
Poppecl object.
Colling PP om empty Stack retums an ror
Catn opuratim tns oC) fime
in
.
Consd e the (ost of each to be
le's o erahons

of n Push &PoP openasn0


totd (Ost of a sequewhte
hme
for n
fe
isheeore n, and the achual
nunning
an).
is there foe
oporations
new opercdon
los take into COnsial@rad'on i s paijtve
Positte
C5.k)
Muipop S,
Stacle S,
objeciS
objects of Statk
of
the Etop ewe
I t emove the Stak
ntains

ensve
Stack if
he
pops
operasion w i not
thon objects nor
thon Mlipop operasion
> i f k is
not Aosit
in stack,
8
mako Ony Chono
code
Consider the bllowng pseudo
muUTT POP (S, E)
k>o
(s) and
not STACk-EMPTY
16 whle
2 POP S)
3 k-L

Exampl
14 Ater mvLTD PoPCS, 4)
06
39 Af
moLI P ,7)

(S
a Statk o 5 objecs.?
MULTDAP (S,) o
Tunn hme of
of p
ineo in the numbes
time is
achua Funnin
Oeradhern ochually ketuled absruct casts of
of +ha
in tems
hus MULTIPoP is onolyzecl
& PoP
1 toch ar PusH lo0p is the
of itratons of the whi
>he Num bel off +he Stack.
in CS df objects Poped
Oumbe
, ach teration 0f tho loge make me cal to POP
The tota cost o MOLTIAOe 1s mn (S,E) and actual
Tunnng Hme s o lintas function o thls cost
o r Sequerne of n AusH, PoP and mULTT POP opratirs
m an
folHally empty Stuck.

wOrst-cose MULTT POP is oCn size oh stuck is n.

Wost case time o any Stuck operatn is on

and hence a sequance o n Operathons CoSs otn)


Sinte oCn MULTI PoP operations cOsting O(n) eah

have

but +his s not nght


Usin 0991egake 0nalysis
BgHes upper bound anay sis (an be obteined b

Cmsideing he enhe sequene o opurations


Can be
thouah MULTEPP Operasion »pens) ve
any Sequence OF PUSH,PoP mOLTDPoP

0peratons OY an 0ihialy empty Stalk s a t mast on)

Un agg1cgade analy sis


th numbel of mee that PoP can be calles on a

oonenpityStalt ,inclyding calls oihn


MuLTE AOP is d mot

the nm be o- PAUSH 8erahions, id is a most n.

> For any value o n ,uny sequane o n PusH


Po
MULTI PoP
take a tots 04+ On) fime
h (vUTaqo Cost of an ogeraon is

On oCD
A CCOuning metho d

In the accouning methed

weaasig
we n difemng changeo to difeent peniaioms
opersaiems
Some
Operautims chargeol moe ess than tha
ac hually CoST
the amount chargad lor an operaiovm is
Omi2es cost

when
when Operaiep's amrtized cos exceeds acdua! et
we asign th dHerenre to spec h object in the
datu smuchure edi+

redit Can help Pay or dok aperatton hose

amod zed cost is Jsss thon


Hhon th detu cost

You might also like