Finding a Sub-Array (Rabin-Karp)

Concatenating Heaps

The concatenation of A and B looks like this:

C=[a1,a2,…,an,b1,b2,…,bm]

Since all elements of A are smaller than each element of B, and A and B are Min-Heaps, we know:

C[2⋅i]=B[2⋅(i−n)]≥B[i−n]=C[i]C[2⋅i+1]=B[2⋅(i−n)+1]≥B[i−n]=C[i]

Thus, C is also a Min-Heap.

Cuckoo hashing

1.) Inserting the keys 27, 2, and 32:


27:

0 1 2 3 4
T1 − − 27 − −
T2 − − − − −

2:

0 1 2 3 4
T1 − − 2 − −
T2 27 − − − −

32:

0 1 2 3 4
T1 − − 32 − −
T2 2/27 − − − −

->

0 1 2 3 4
T1 − − 2 − −
T2 27 32 − − −

2.) Infinite Sequence

With the Cuckoo hashing technique we can store at most two keys with the same h1 and h2 value. Since 2 and 27 already have the same values, any third number k with the same h1 and h2 values would lead to an infinite sequence.

k needs to fulfill the following two conditions:

k=5m+2(h1)⌊k5⌋=5p(h2)

I in II:

⌊m+25⌋=m=!5p

in II:

k=25p+2

With p=0 we have 2, for p=1 27, and we could choose e.g. p=2 and the third number 52
-> 52 would lead to an infinite sequence