Chapter 11
Exercise 11.1-1
Available in the latest revision of the IM.
Exercise 11.1-2
Available in the latest revision of the IM.
Exercise 11.1-3
Available in the latest revision of the IM.
If any element among those with an equal key suffices to serve as a return value from Search, then there is no need to keep them all. Hence, we can avoid the usage of doubly linked lists, as in the IM, by working with (x,count) ordered pairs, where x is an object or pointer to an object. So, each slot is either nil (None in Python) or an ordered pair. Insertions increase, while deletions decrease those counters.
Exercise 11.1-4
Available in the latest revision of the IM.
Setting T[k]=nil is redundant (see the sequence of assignments for deletion in the IM).
Exercise 11.2-1
Available in the latest revision of the IM.
Exercise 11.2-2
We start with an empty table T[0:8]. Elements which appear to the left in the table have been added later.
0
∅
1
10, 19, 28
2
20
3
12
4
∅
5
5
6
33, 15
7
∅
8
17
Exercise 11.2-3
Available in the latest revision of the IM.
Exercise 11.2-4
Available in the latest revision of the IM.
Exercise 11.2-5
Available in the latest revision of the IM.
Exercise 11.2-6
Available in the latest revision of the IM.
Exercise 11.3-1
Available in the latest revision of the IM.
Exercise 11.3-2
Available in the latest revision of the IM.
The solution in the IM doesn't take into account the fact that the key is encoded as a radix-128 number. So, the correct way to calculate the hash value is to apply Horner's rule and compute it iteratively. Let's assume that the key k is represented as a sequence of characters ⟨s1,s2,…,sr⟩ in big-endian format.
Exercise 11.3-3
Available in the latest revision of the IM.
The solution in the IM is incomplete, since it doesn't answer the last question from this exercise. A cryptographic hash function must ensure that any permutation of characters generate a different hash value. Otherwise, someone could rearrange a document without breaking a message digest used in a digital signature. Imagine an adversary being able to rearrange the bank account number and/or amount of a digitally signed transaction.
Exercise 11.3-4
61 → 700 62 → 318 63 → 936 64 → 554 65 → 172
Exercise 11.3-5
Available in the latest revision of the IM.
Exercise 11.3-6
The size of our family of hash functions is ∣Zp∣=p, as we have p choices to select hb. We need to calculate the probability of a collision hb(k1)=hb(k2) for distinct keys k1 and k2. This probability is over the picks of hb. Observe that
which gives
We have the following equalities all taken modulo p
Following the hint from the book, according to Exercise 31.4-4 the above polynomial can have at most d−1 distinct zeros modulo p. In other words, at most d−1 choices of b can lead to a collision. Therefore, our family of hash functions is ϵ-universal for ϵ=(d−1)/p.
Exercise 11.4-1
Use VisuAlgo and select linear probing in the top menu bar. Choose the option in the left sidebar to create an empty hash table with m=11 slots and n=0 elements and press Go. Afterward, select the command to insert elements 10,22,31,4,15,28,17,88,59 and press Go.
For double hashing, the above website uses a different auxiliary hash function h2, so we cannot use it here. The hash table is filled as follows:
Exercise 11.4-2
Hash-Delete expects the key to be present in the hash table. Otherwise, there should be another check against nil for the returned index.
The Hash-Insert procedure from the book requires a slight change in 4 line as follows:
The Hash-Search doesn't need any change.
Exercise 11.4-3
Available in the latest revision of the IM.
Exercise 11.4-4
Instead of doing integral approximation (see page 300) we simply use the definition of the mth harmonic humber.
Exercise 11.4-5
This directly follows from Theorem 31.20, since ∣⟨h2(k)⟩∣=m/d.
Exercise 11.4-6
Enter solve 1/(1-x)=2/x ln(1/(1-x)) in WolframAlpha to get α≈0.71533 by clicking on the Approximate form button inside the Result pane.
Exercise 11.5-1
fa(0)(k) is an identity function, which is obviously injective. If we prove that fa=fa(1)(k) is injective (base case), then fa(r)(k)=fa∘fa(r−1)(k) for r>1 is also injective by induction on r. Note that the composition of two bijections is again a bijection (see solution for Exercise B.3-4).
We know that the swap function only rearranges the bits of an input independently of it's value, therefore x=y⟺swap(x)=swap(y).
Suppose, for the sake of contradiction, that there are two distinct inputs x and y such that fa(x)=fa(y). WLOG assume that x>y, otherwise, exchange them. Thus, we have
We have reached a contradiction, since a is odd and 2ω∤(x−y). Recall that both x and y are ω-bit words, hence x−y<2ω. Consequently, fa is injective.
Exercise 11.5-2
A random oracle is equivalent to an independent uniform hash function family. Let us take 5 distinct keys k1,k2,k3,k4,k5. Each will be independently and uniformly mapped by a random oracle to a slot in the range [0,m). There are m5 possible mappings, each with an equal probability of occurrence 1/m5. Thus, a random oracle is 5-independent according to the definition from the book on page 288.
Since a random oracle guarantees independence for any number of distinct inputs, it inherently satisfies 5-independence. 5-independence is a weaker condition than full independence; a fully independent function trivially satisfies k-independence for all k.
Exercise 11.5-3
At least r=3 rounds are required to trigger an avalanche effect potentially affecting any bit of the output to flip. In the illustration below, light red colored cells could be affected by flips in previous rounds. After 3 rounds, all cells are marked red, hence may be impacted by flipping a single bit of the input value k. Observe that flipping the most-significant bit of k only impacts the most-significant bit of ga(k) in the first round. Any other bit of k can only make the situation better. Hence, we consider a flip in bit position ω−1 as the worst-case scenario. Note that round 0 is an identity function, so it is essentially the key itself. Each round consists of two parts: the upper is ga(k) and the lower is fa(k) of the corresponding round.
Problem 11-1
Available in the latest revision of the IM.
Problem 11-2
Available in the latest revision of the IM.
Problem 11-3
Available in the latest revision of the IM.
Problem 11-4
a.
Arbitrarily pick two distinct keys x,y∈U. If H is 2-independent, then we can have m2 different pairs (h(x),h(y)) of hash values with equal probability of occurrence 1/m2. Collisions are denoted by pairs (i,i) for i=0,1,…,m−1. Therefore, the probability of a collision for two distinct keys is m/m2=1/m. Consequently, H is universal.
b.
First, we show that is H universal. Arbitrarily pick two distinct keys x,y∈U. They must differ in at least one component. WLOG let it happen at index 0≤i<n. For a collision to occur, with a randomly picked hash function ha∈H, we must have ha(x)=ha(y). Using the definition of ha we get
Observe that −(p−1)≤xi−yi≤p−1 and xi−yi=0 implies that xi−yi has a multiplicative inverse modulo p. Therefore,
Notice that ai is fully determined based on the choice of x, y and other components of a. Thus, the probability of a collision is 1/p, since for a randomly selected n-tuple a, there are p possible values at index i and only one leads to a collision. Furthermore, if ha(x)=ha(y) then all coefficients ak, associated with corresponding nonzero terms xk−yk, simultaneously satisfy (1) (just set i=k). This shows that H is universal.
Following the hint from the book, it is easy to see that x0=⟨0,0,…,0⟩ always hashes to zero. Therefore, the condition to have p2 unique pairs of hash values, with equal probability of occurrence, for any two distinct keys is not satisfied. Consequently, H is not 2-independent.
c.
Taking the hint from the book, let's see what happens to hab′(x) as ai and b range over Zp. The same reasoning will also apply to hab′(y). Let c=∑0≤j<ni=jajxj, since we keep all other parameters fixed. This constant c has no influence on the subsequent analysis.
We must show that hab′(x) can take any value from Zp and equal number of distinct pairs (ai,b) map to each such output. There are two cases to consider:
If xi=0 then each value of b produces a unique hash output, so it may range over Zp. For every b we can freely assign p possible values to ai. In other words, p distinct pairs map to each distinct hash value.
Otherwise, according to theorem 31.20, we know that ∣⟨xi⟩∣=p, since xi is relatively prime to p. In this case, the parameter b only shifts the full sequence of p values generated by xi. There are p such shifts. Thus, the output may range over Zp and again p distinct pairs (ai,b) map to each distinct hash value.
We can conclude that H′ is 2-independent.
d.
Since H is 2-independent, we can have p2 different pairs of hash values, with equal probability of occurrence 1/p2, for two distinct keys x,y∈U. The adversary may fool Bob, assuming that m=m′, if h′(m′)=h(m′)=t′, where h denotes the shared hash function between Alice and Bob. All the adversary can do is to find a hash function h′ such that h′(m)=h(m)=t, hoping that it will also collide on m′ with h. There are p pairs of possible hash values whose first component is t. The probability that h′ will also generate the same second component as h for m′ is 1/p. Therefore, no matter how much computing power the adversary has, her/his probability of success is at most 1/p.
As a side note, the previous analysis may also be carried out in an opposite direction. Namely, to ask what is the probability that Alice and Bob had selected a random hash function that hashes to the same value as h′ for m′. Among those that produce t for m only (1/p)th generate t′ for m′. So, we arrive at the same conclusion.
Last updated