Grokking Algorithms


empty slot in the hash table



Download 6,4 Mb.
Pdf ko'rish
bet112/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   108   109   110   111   112   113   114   115   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

empty slot in the hash table
Answer: 
Not consistent
5.4
f(x) = len(x)
Uses the length of the string as the index
 Answer: 
Consistent
Suppose you have these four hash functions that work with strings:
A. Return “1” for all input.
B. Use the length of the string as the index.
C. Use th
e irst character of the string as the index. So, all strings 
starting with 
a
are hashed together, and so on.
D. Map every letter to a prime number: a = 2, b = 3, c = 5, d = 7,
e = 11, and so on. For a string, the hash function is the sum of 
all the characters modulo the size of the hash. For example, if 
your hash size is 10, and the string is “bag”, the index is 3 + 2 + 
17 % 10 = 22 % 10 = 2.
For each of the following examples, which hash functions would 
provide a good distribution? Assume a hash table size of 10 slots.
5.5
A phonebook where the keys are names and values are phone 
numbers. The names are as follows: Esther, Ben, Bob, and Dan.
Answer: 
Hash functions C and D would give a good distribution.
answers to exercises


228
5.6
A mapping from battery size to power. The sizes are A, AA, AAA, 
and AAAA.
Answer: 
Hash functions B and D would give a good distribution.
5.7
A mapping from book titles to authors. The titles are 
Maus

Fun 
Home
, and 
Watchmen
.
Answer:
Hash functions B, C, and D would give a good 
distribution.
CHAPTER 6
Run the breadt
h-irst search algorithm on each of these graphs
to ind the solution.
6.1
Find the length of the shortest path from start to finish.
Answer:
The shortest path has a length of 2.

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   108   109   110   111   112   113   114   115   ...   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