Grokking Algorithms



Download 6,4 Mb.
Pdf ko'rish
bet40/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   36   37   38   39   40   41   42   43   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

Chapter 4
 
 
I
 
 
Quicksort
EXERCISES
How long would each of these operations take in Big O notation?
4.5
Printing the value of each element in an array. 
4.6 
Doubling the value of each element in an array.
4.7
Doubling the value of just th
e irst element in an array. 
4.8
Creating a multiplication table with all the elements in the array. So 
if your array is [2, 3, 7, 8, 10], you irst multiply every element by 2, 
then multiply every element by 3, then by 7, and so on. 
Recap
• D&C works by breaking a problem down into smaller and smaller 
pieces. If you’re using D&C on a list, the base case is probably an 
empty array or an array with one element.
• If you’re implementing quicksort, choose a random element as the 
pivot. he average runtime of quicksort is O(
n
log 
n
)!
• he constant in Big O notation can matter sometimes. hat’s why 
quicksort is faster than merge sort.
• he constant almost never matters for simple search versus binary 
search, because O(log 
n
) is so much faster than O(
n
) when your list 
gets big.


73
In this chapter
• 
You learn about hash tables, one of the most
useful basic data structures. Hash tables have many 
uses; this chapter covers the common use cases.
• 
You learn about the internals of hash tables:
implementation, collisions, and hash functions. 
This will help you understand how to analyze a 
hash table’s performance.
 
hash tables
5
Suppose you work at a grocery store. When a customer 
buys produce, you have to look up the price in a book. If 
the book is unalphabetized, it can take you a long time to 
look through every single line for 
apple
. You’d be doing 
simple search from chapter 1, where you have to look at 
every line. Do you remember how long that would take? 
O(
n
) time. If the book is alphabetized, you could run 
binary search t
o ind the price of an apple. hat would 
only take O(log
n
) time.


74

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   36   37   38   39   40   41   42   43   ...   120




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