Introduction to Algorithms, Third Edition



Download 4,84 Mb.
Pdf ko'rish
bet120/618
Sana07.04.2022
Hajmi4,84 Mb.
#534272
1   ...   116   117   118   119   120   121   122   123   ...   618
Bog'liq
Introduction-to-algorithms-3rd-edition

7.4.2
Expected running time
We have already seen the intuition behind why the expected running time of
R
ANDOMIZED
-Q
UICKSORT
is
O.n
lg
n/
: if, in each level of recursion, the split
induced by R
ANDOMIZED
-P
ARTITION
puts any constant fraction of the elements
on one side of the partition, then the recursion tree has depth
‚.
lg
n/
, and
O.n/
work is performed at each level. Even if we add a few new levels with the most un-
balanced split possible between these levels, the total time remains
O.n
lg
n/
. We
can analyze the expected running time of R
ANDOMIZED
-Q
UICKSORT
precisely
by first understanding how the partitioning procedure operates and then using this
understanding to derive an
O.n
lg
n/
bound on the expected running time. This
upper bound on the expected running time, combined with the
‚.n
lg
n/
best-case
bound we saw in Section 7.2, yields a
‚.n
lg
n/
expected running time. We assume
throughout that the values of the elements being sorted are distinct.
Running time and comparisons
The Q
UICKSORT
and R
ANDOMIZED
-Q
UICKSORT
procedures differ only in how
they select pivot elements; they are the same in all other respects. We can therefore
couch our analysis of R
ANDOMIZED
-Q
UICKSORT
by discussing the Q
UICKSORT
and P
ARTITION
procedures, but with the assumption that pivot elements are se-
lected randomly from the subarray passed to R
ANDOMIZED
-P
ARTITION
.
The running time of Q
UICKSORT
is dominated by the time spent in the P
ARTI
-
TION
procedure. Each time the P
ARTITION
procedure is called, it selects a pivot
element, and this element is never included in any future recursive calls to Q
UICK
-
SORT
and P
ARTITION
. Thus, there can be at most
n
calls to P
ARTITION
over the
entire execution of the quicksort algorithm. One call to P
ARTITION
takes
O.1/
time plus an amount of time that is proportional to the number of iterations of the

Download 4,84 Mb.

Do'stlaringiz bilan baham:
1   ...   116   117   118   119   120   121   122   123   ...   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