Introduction to Algorithms, Third Edition



Download 4,84 Mb.
Pdf ko'rish
bet306/618
Sana07.04.2022
Hajmi4,84 Mb.
#534272
1   ...   302   303   304   305   306   307   308   309   ...   618
Bog'liq
Introduction-to-algorithms-3rd-edition

17.1
Aggregate analysis
In
aggregate analysis
, we show that for all
n
, a sequence of
n
operations takes
worst-case
time
T .n/
in total. In the worst case, the average cost, or
amortized
cost
, per operation is therefore
T .n/=n
. Note that this amortized cost applies to
each operation, even when there are several types of operations in the sequence.
The other two methods we shall study in this chapter, the accounting method and
the potential method, may assign different amortized costs to different types of
operations.
Stack operations
In our first example of aggregate analysis, we analyze stacks that have been aug-
mented with a new operation. Section 10.1 presented the two fundamental stack
operations, each of which takes
O.1/
time:
P
USH
.S; x/
pushes object
x
onto stack
S
.
P
OP
.S /
pops the top of stack
S
and returns the popped object. Calling P
OP
on an
empty stack generates an error.
Since each of these operations runs in
O.1/
time, let us consider the cost of each
to be
1
. The total cost of a sequence of
n
P
USH
and P
OP
operations is therefore
n
,
and the actual running time for
n
operations is therefore
‚.n/
.
Now we add the stack operation M
ULTIPOP
.S; k/
, which removes the
k
top ob-
jects of stack
S
, popping the entire stack if the stack contains fewer than
k
objects.
Of course, we assume that
k
is positive; otherwise the M
ULTIPOP
operation leaves
the stack unchanged. In the following pseudocode, the operation S
TACK
-E
MPTY
returns
TRUE
if there are no objects currently on the stack, and
FALSE
otherwise.


17.1
Aggregate analysis
453
23
17
6
39
10
47
(a)
top
10
47
(b)
top
(c)

Download 4,84 Mb.

Do'stlaringiz bilan baham:
1   ...   302   303   304   305   306   307   308   309   ...   618




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish