Algorithms For Dummies


Using Randomized Algorithms



Download 7,18 Mb.
Pdf ko'rish
bet542/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   538   539   540   541   542   543   544   545   ...   651
Bog'liq
Algorithms

  Using Randomized Algorithms 

     335


If on average it takes about three times the size of the input, Quickselect is provid-

ing good performance. However, you may wonder whether the proportion between 

inputs  and  computations  will  hold  when  the  input  size  grows.  As  seen  when 

studying  NP-complete  problems,  many  problems  explode  when  the  input  size 

grows. You can prove this theory by using another Monte Carlo simulation on top 

of the previous one and plotting the output, as shown in Figure 17-5.

input_size = [501, 1001, 5001, 10001, 20001, 50001]

computations = list()

for n in input_size:

    results = list()

    for run in range(1000):

        series = [randint(1, 25) for i in range(n)]

        median,count = quickselect(series, n//2)

        assert(median==np.median(series))

        results.append(count)

    computations.append(np.mean(results))

plt.plot(input_size, computations, '-o')

plt.xlabel("Input size")

plt.ylabel("Number of computations")

plt.show()

Completing the computations from this example may take up to ten minutes (some 

Monte Carlo simulations may be quite time consuming), but the result helps you 

visualize what it means to work with an algorithm that works with  linear time. 

As the input grows (represented in abscissa), the computations ( represented on 

the ordinal axis) grow proportionally, making the growth curve a perfect line.

FIGURE 17-4: 

Displaying the 

results of a 

Monte Carlo 

simulation on 

Quickselect.




336

 

   


  PART 5 


Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   538   539   540   541   542   543   544   545   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
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