TExcelTAD

Exercises

Fifteen problems covering the whole course: integer structures on the word-RAM, dynamic trees and connectivity, persistence and retroactivity, memory hierarchies, and succinct and probabilistic structures. Each has a short Answer and a full Solution; several solutions include a program you can edit and run. State every bound with its conditions (worst case, amortized, expected, model), as the lessons do.

Tip: Most problems here are about why a bound holds. Before calculating, ask which single step of the structure is expensive, and what pays for it: a halving of the universe, a potential, an amortization over Θ(w)\Theta(w) operations, or the block size BB.

# Exercise Practises
1 Two recursive calls van Emde Boas recurrences
2 Lookups in an x-fast trie binary search on prefixes
3 The wrong bucket size y-fast tries, indirection
4 Sketch four keys fusion nodes
5 Tours after LINK and CUT Euler-tour trees
6 Lowest common ancestors with ACCESS link-cut trees
7 How high can an edge climb? dynamic connectivity levels
8 Paths in a persistent tree path copying
9 A retroactive register retroactivity
10 Passes of an external sort DAM sorting bound
11 Searching a billion keys B-trees, vEB layout
12 Rank and select by hand rank/select
13 Merging Bloom filters Bloom filters
14 Cuckoo graph cycles cuckoo hashing
15 Backward search by hand FM-index

Exercise 1: Two recursive calls

A careless van Emde Boas implementation stores the minimum of each structure also inside its cluster (it does not keep it out of the recursion). Show that INSERT can then make two non-trivial recursive calls, and solve the resulting recurrence.

Answer

T(U)=2T(U)+O(1)T(U) = 2T(\sqrt{U}) + O(1), which is O(lg⁡U)O(\lg U): no better than a balanced BST.

Solution

Inserting xx into an empty cluster is no longer O(1)O(1): the cluster's own minimum must be stored inside its sub-clusters too, so the insertion recurses all the way down. When the cluster of xx is empty, INSERT must insert its index into the summary (a real call) and insert xx into the empty cluster (now also a real call). So T(U)=2T(U)+O(1)T(U) = 2T(\sqrt{U}) + O(1). With m=lg⁡Um = \lg U and S(m)=T(2m)S(m) = T(2^m): S(m)=2S(m/2)+O(1)=O(m)S(m) = 2S(m/2) + O(1) = O(m) by the master theorem, so T(U)=O(lg⁡U)T(U) = O(\lg U). Keeping the minimum out of the recursion is exactly what makes one of the two calls O(1)O(1) (Van Emde Boas Trees).

Exercise 2: Lookups in an x-fast trie

How many hash-table lookups does a SUCCESSOR query in an x-fast trie make in the worst case for w=64w = 64? How many prefix entries does a trie with n=106n = 10^6 random 64-bit keys store, approximately?

Answer

⌈lg⁡65⌉=7\lceil \lg 65 \rceil = 7 lookups. About n(w+1−lg⁡n)+2n≈106⋅47n (w + 1 - \lg n) + 2n \approx 10^6 \cdot 47 entries, roughly 47 million.

Solution

The binary search runs over the w+1=65w + 1 = 65 prefix lengths 0,…,640, \ldots, 64; each lookup halves the candidate range, so ⌈lg⁡65⌉=7\lceil \lg 65 \rceil = 7 lookups in the worst case. For the space: the top lg⁡n≈20\lg n \approx 20 levels of the trie are nearly complete, so they hold about 221≈2n2^{21} \approx 2n prefixes in total; below that, the paths of random keys no longer share prefixes, and each key contributes its own w−lg⁡n≈44w - \lg n \approx 44 entries plus the leaf. That is about n(w+1−lg⁡n)+2n≈47⋅106n(w + 1 - \lg n) + 2n \approx 47 \cdot 10^6 entries, a factor ww more than the keys themselves, which is what the y-fast trie removes.

Exercise 3: The wrong bucket size

In a y-fast trie, what goes wrong if the buckets hold Θ(lg⁡w)\Theta(\lg w) keys instead of Θ(w)\Theta(w)? And with Θ(w2)\Theta(w^2)?

Answer

Θ(lg⁡w)\Theta(\lg w): the x-fast trie holds Θ(n/lg⁡w)\Theta(n / \lg w) representatives of O(w)O(w) space each, Θ(nw/lg⁡w)\Theta(nw/\lg w) space, and splits cost O(w)O(w) every Θ(lg⁡w)\Theta(\lg w) updates, O(w/lg⁡w)O(w/\lg w) amortized. Θ(w2)\Theta(w^2): everything still works, with O(lg⁡w)O(\lg w) bucket operations in a balanced BST; the space is O(n)O(n) either way.

Solution

The bucket size bb must satisfy two constraints: the x-fast trie's space O(nbw)O(\frac{n}{b} w) must be O(n)O(n), so b=Ω(w)b = \Omega(w); and a bucket operation, O(lg⁡b)O(\lg b) in a balanced BST, must be O(lg⁡w)O(\lg w), so bb is at most polynomial in ww. Updates must also amortize the O(w)O(w) cost of a split or merge over the Ω(b)\Omega(b) updates between two of them, again requiring b=Ω(w)b = \Omega(w). With b=Θ(lg⁡w)b = \Theta(\lg w) the first and third constraints fail. With b=Θ(w2)b = \Theta(w^2) they all hold, since lg⁡w2=2lg⁡w\lg w^2 = 2 \lg w. The usual choice b=Θ(w)b = \Theta(w) is the smallest that works.

Exercise 4: Sketch four keys

Four 8-bit keys are stored in a fusion node: x0=00010110x_0 = 00010110, x1=00011001x_1 = 00011001, x2=01010000x_2 = 01010000, x3=01010111x_3 = 01010111. Find the branching bits, the sketches, and the rank that sketch⁡(y)\operatorname{sketch}(y) gives for y=00011111y = 00011111. Is it correct?

Answer

Branching bits (from the right, bit 0 = least significant) {2,3,6}\{2, 3, 6\}; sketches 001001, 010010, 100100, 101101 (bits 6, 3, 2); sketch⁡(y)=011\operatorname{sketch}(y) = 011, ranked after x1x_1: rank 2, which is correct here (x0,x1<y<x2x_0, x_1 < y < x_2).

Solution

Adjacent keys first differ at: x0,x1x_0, x_1: bit 3; x1,x2x_1, x_2: bit 6; x2,x3x_2, x_3: bit 2. So the branching bits are 2, 3 and 6, and a sketch reads bits 6,3,26, 3, 2 of a key. The program checks the sketches, compares the sketch rank with the true rank for every 8-bit yy, and counts how often the sketch alone is wrong, which is why fusion trees need the desketch step.

python · try it yourself
keys = [0b00010110, 0b00011001, 0b01010000, 0b01010111]
bits = sorted({(a ^ b).bit_length() - 1 for a, b in zip(keys, keys[1:])})
def sketch(x):
    return sum(((x >> b) & 1) << i for i, b in enumerate(bits))
print("branching bits:", bits)
print("sketches:", [format(sketch(x), "03b") for x in keys])
y = 0b00011111
sk_rank = sum(sketch(x) <= sketch(y) for x in keys)
print(f"y = {y:08b}: sketch {sketch(y):03b}, sketch rank {sk_rank}, true rank {sum(x <= y for x in keys)}")
wrong = sum(sum(sketch(x) <= sketch(v) for x in keys) != sum(x <= v for x in keys) for v in range(256))
print(f"the sketch rank alone is wrong for {wrong} of the 256 possible queries")
branching bits: [2, 3, 6]
sketches: ['001', '010', '100', '101']
y = 00011111: sketch 011, sketch rank 2, true rank 2
the sketch rank alone is wrong for 138 of the 256 possible queries

Exercise 5: Tours after LINK and CUT

A forest has the trees a−ba - b and c−d−ec - d - e (paths). Write an Euler tour of each (in the representation of the lesson, with vertex entries and directed edge entries), then the tour after LINK(b,c)(b, c), and the two tours after CUT(c,d)(c, d).

Answer

Tours a, a→b, b, b→aa,\ a{\to}b,\ b,\ b{\to}a and c, c→d, d, d→e, e, e→d, d→cc,\ c{\to}d,\ d,\ d{\to}e,\ e,\ e{\to}d,\ d{\to}c. After LINK(b,c)(b, c) (rerooted at bb and cc): b,b→a,a,a→b,b→c,c,c→d,d,d→e,e,e→d,d→c,c→bb, b{\to}a, a, a{\to}b, b{\to}c, c, c{\to}d, d, d{\to}e, e, e{\to}d, d{\to}c, c{\to}b. After CUT(c,d)(c, d): b,b→a,a,a→b,b→c,c,c→bb, b{\to}a, a, a{\to}b, b{\to}c, c, c{\to}b and d,d→e,e,e→dd, d{\to}e, e, e{\to}d.

Solution

LINK reroots aa's tour at bb (rotation: b,b→a,a,a→bb, b{\to}a, a, a{\to}b) and cc's tour at cc (already), then concatenates tour(bb), b→cb{\to}c, tour(cc), c→bc{\to}b. Every tour has 3k−23k - 2 entries for kk vertices: 3⋅5−2=133 \cdot 5 - 2 = 13 here. CUT(c,d)(c, d) locates c→dc{\to}d and d→cd{\to}c; the part strictly between them, d,d→e,e,e→dd, d{\to}e, e, e{\to}d, is dd's side, and the rest, concatenated, is b,b→a,a,a→b,b→c,c,c→bb, b{\to}a, a, a{\to}b, b{\to}c, c, c{\to}b, with 3⋅3−2=73 \cdot 3 - 2 = 7 entries. Each step is O(1)O(1) splits and concatenations of balanced BSTs, O(lg⁡n)O(\lg n) (Euler-Tour Trees).

Exercise 6: Lowest common ancestors with ACCESS

Show how to compute the lowest common ancestor of uu and vv in a rooted forest with a link-cut tree, using two ACCESS operations.

Answer

ACCESS(u)(u), then ACCESS(v)(v); the LCA is the last node at which ACCESS(v)(v) jumped onto the preferred path containing the root, i.e. the last node yy splayed in the loop before the final splay (if uu and vv are in the same tree).

Solution

After ACCESS(u)(u), the root-to-uu path is one preferred path. ACCESS(v)(v) walks up from vv through path-parent pointers. The walk ends on the root's preferred path, which is (the upper part of) the root-to-uu path, and it enters that path at the deepest node of the root-to-uu path that is also an ancestor of vv: the lowest common ancestor. In the loop of the lesson's access, that is the last value of y before y becomes NIL. Both ACCESS calls are O(lg⁡n)O(\lg n) amortized, so LCA queries are O(lg⁡n)O(\lg n) amortized, even while the forest changes by LINK and CUT. (If the last splayed node is not in uu's tree, uu and vv are in different trees.)

Exercise 7: How high can an edge climb?

In the Holm-de Lichtenberg-Thorup algorithm, prove that no edge ever needs a level above ⌊lg⁡n⌋\lfloor \lg n \rfloor.

Answer

By the size invariant, components of GiG_i have at most n/2in/2^i vertices. An edge of level ii lies in a component of GiG_i with at least 2 vertices, so 2≤n/2i2 \le n / 2^i, i.e. i≤lg⁡n−1i \le \lg n - 1.

Solution

The algorithm raises edges of a tree TT of FiF_i to level i+1i + 1 only when TT is the smaller half of a split tree, so ∣T∣≤n/2i+1\lvert T \rvert \le n / 2^{i+1}, and it raises non-tree edges only when both ends are in such a TT. This maintains the invariant that every component of GiG_i has at most n/2in / 2^i vertices. An edge at level ii has both endpoints in one component of GiG_i, which then has at least 2 vertices: 2≤n/2i2 \le n / 2^i, so i≤lg⁡n−1i \le \lg n - 1. Since levels only increase, each edge is raised at most lg⁡n\lg n times, which gives the O(lg⁡2n)O(\lg^2 n) amortized update bound (Fully Dynamic Connectivity).

Exercise 8: Paths in a persistent tree

A persistent (path-copying) unbalanced BST receives n=20000n = 20000 keys in random order, keeping every version. Estimate the total number of nodes created, and compare with the expected depth of a random BST.

Answer

Each insertion copies its search path: about the depth of the new node plus one. The expected depth of the kk-th inserted key is about 2ln⁡k2 \ln k, so the total is a little below 2nln⁡n≈2n⋅9.9≈3960002n \ln n \approx 2n \cdot 9.9 \approx 396000 nodes, about 360000.

Solution

The program counts exactly. The average copied path is close to 2ln⁡n−O(1)2 \ln n - O(1), matching the expected depth of a node in a random BST (The Expected Height of a Random BST analyses the same quantity).

python · try it yourself
import math, random

def insert(t, k, made):                      # t = (key, left, right) or None; returns a new root
    if t is None:
        made[0] += 1; return (k, None, None)
    made[0] += 1
    if k < t[0]: return (t[0], insert(t[1], k, made), t[2])
    return (t[0], t[1], insert(t[2], k, made))

rng = random.Random(8)
n = 20000
keys = rng.sample(range(10 ** 6), n)
t, made = None, [0]
for k in keys:
    t = insert(t, k, made)
print(f"{made[0]} nodes created, {made[0] / n:.1f} per insertion; 2 ln n = {2 * math.log(n):.1f}")
355721 nodes created, 17.8 per insertion; 2 ln n = 19.8

The measured 17.8 is a little below 2ln⁡n2 \ln n: the average depth of a node in a random BST is about 2ln⁡n−2.82 \ln n - 2.8, and each insertion copies the path plus the new leaf. All 20000 versions together use about 18 nodes per key, against n/2=10000n/2 = 10000 per key if every version were copied in full.

Exercise 9: A retroactive register

A register supports the update SET(c)(c) and the query GET. Design a fully retroactive version: insert or delete a SET at any time tt, and GET at any time tt. What does it cost?

Answer

Keep the SET operations in a balanced BST keyed by time. GET(t)(t) is the value of the SET with the largest time ≤t\le t: a predecessor query. All operations are O(lg⁡m)O(\lg m) worst case.

Solution

The state at time tt depends only on the last SET before tt, so a retroactive change affects only the interval until the next SET, and nothing has to be propagated: storing the operations sorted by time is enough. INSERT(t,SET(c))(t, \text{SET}(c)) and DELETE(t)(t) are BST insertions and deletions, GET(t)(t) a predecessor search, all O(lg⁡m)O(\lg m) (or O(lg⁡lg⁡U)O(\lg \lg U) with a van Emde Boas tree over integer times). The register is easy because SET overwrites the state; contrast it with the operations "y←y⋅x+ay \leftarrow y \cdot x + a" of the Ω(r)\Omega(r) lower bound in Retroactive Data Structures, where every operation depends on the whole history.

Exercise 10: Passes of an external sort

Sort N=236N = 2^{36} items (64-bit keys, 512 GiB) with M=230M = 2^{30} words of memory and blocks of B=216B = 2^{16} words. How many merge passes does multiway merge sort need, how many I/Os in total, and how does that compare with two-way merging?

Answer

N/M=64N/M = 64 runs, fan-in M/B−1=16383M/B - 1 = 16383: one merge pass. Total 2⋅NB(1+1)=4⋅220≈4.22 \cdot \frac{N}{B}(1 + 1) = 4 \cdot 2^{20} \approx 4.2 million I/Os. Two-way merging needs lg⁡64=6\lg 64 = 6 passes: 14⋅220≈14.714 \cdot 2^{20} \approx 14.7 million.

Solution
python · try it yourself
import math

N, M, B = 2 ** 36, 2 ** 30, 2 ** 16
runs = N // M
for k in [2, M // B - 1]:
    passes = math.ceil(math.log(runs, k) - 1e-9)
    ios = 2 * (N // B) * (1 + passes)
    print(f"fan-in {k:5}: {runs} runs, {passes} merge passes, {ios:>10} I/Os = {ios / (N // B):.0f} scans")
print(f"sort(N) = (N/B) log_(M/B)(N/B) = {(N / B) * math.log(N / B, M / B):.0f}")
fan-in     2: 64 runs, 6 merge passes,   14680064 I/Os = 14 scans
fan-in 16383: 64 runs, 1 merge passes,    4194304 I/Os = 4 scans
sort(N) = (N/B) log_(M/B)(N/B) = 1497966

With realistic parameters the logarithm in sort⁡(N)\operatorname{sort}(N) is between 1 and 2 (log⁡214220≈1.43\log_{2^{14}} 2^{20} \approx 1.43), so external sorting costs a small constant number of scans; the constant 4 includes reading and writing in both passes (Sorting in External Memory).

Exercise 11: Searching a billion keys

For N=230N = 2^{30} keys and blocks of B=26B = 2^{6} keys (a 512-byte line of 64-bit keys), estimate the blocks touched by a search with a cold cache for (a) binary search on a sorted array, (b) a B-tree with nodes of BB keys, (c) the van Emde Boas layout (use the lesson's bound and its measured constant).

Answer

(a) lg⁡(N/B)=24\lg(N/B) = 24; (b) log⁡BN=5\log_B N = 5; (c) at most 4log⁡BN=204 \log_B N = 20 by the worst-case analysis, about 1.21.2 to 1.5×5=61.5 \times 5 = 6 to 7.57.5 in practice.

Solution

(a) Binary search only saves the last lg⁡B=6\lg B = 6 steps of its lg⁡N=30\lg N = 30, which fall inside one block: 30−6=2430 - 6 = 24 blocks. (b) A B-tree has height ⌈log⁡BN⌉=5\lceil \log_{B} N \rceil = 5 and reads one block per level. (c) The vEB layout's pieces of at most BB nodes have height at least about 12lg⁡B=3\frac12 \lg B = 3, a path crosses about 30/3=1030 / 3 = 10 of them, and each piece spans at most 2 blocks: at most 20 blocks. The worst case assumes every piece straddles a boundary and that pieces are as small as allowed; the measurements in The van Emde Boas Layout came out at 1.2 to 1.5 times log⁡BN\log_B N, so about 6 to 8 blocks, for every BB at once.

Exercise 12: Rank and select by hand

For b=0110 1001 1101 0001b = 0110\,1001\,1101\,0001 (positions 0 to 15, left to right), compute rank⁡1(8)\operatorname{rank}_1(8), rank⁡0(8)\operatorname{rank}_0(8), select⁡1(5)\operatorname{select}_1(5) and select⁡0(3)\operatorname{select}_0(3). Then show how select⁡1\operatorname{select}_1 can be computed with O(lg⁡n)O(\lg n) rank queries.

Answer

rank⁡1(8)=4\operatorname{rank}_1(8) = 4, rank⁡0(8)=4\operatorname{rank}_0(8) = 4, select⁡1(5)=8\operatorname{select}_1(5) = 8, select⁡0(3)=5\operatorname{select}_0(3) = 5. Binary search for the smallest ii with rank⁡1(i+1)≥k\operatorname{rank}_1(i + 1) \ge k.

Solution

The ones are at positions 1, 2, 4, 7, 8, 9, 11, 15 and the zeros at 0, 3, 5, 6, 10, 12, 13, 14. Positions 0 to 7 contain the ones 1, 2, 4, 7: rank⁡1(8)=4\operatorname{rank}_1(8) = 4 and rank⁡0(8)=8−4=4\operatorname{rank}_0(8) = 8 - 4 = 4. The fifth one is at position 8, and the zeros at 0, 3, 5 make position 5 the third zero: select⁡1(5)=8\operatorname{select}_1(5) = 8 and select⁡0(3)=5\operatorname{select}_0(3) = 5. Since rank⁡1(i+1)\operatorname{rank}_1(i + 1) is non-decreasing in ii, the position of the kk-th one is the smallest ii with rank⁡1(i+1)≥k\operatorname{rank}_1(i + 1) \ge k, found by binary search with O(lg⁡n)O(\lg n) rank queries, each O(1)O(1) (Rank and Select on Bit Vectors).

python · try it yourself
b = [int(c) for c in "0110100111010001"]
rank1 = lambda i: sum(b[:i])
def select(bit, k):
    lo, hi = 0, len(b) - 1                    # smallest i with rank_bit(i + 1) >= k
    while lo < hi:
        mid = (lo + hi) // 2
        r = rank1(mid + 1) if bit else (mid + 1) - rank1(mid + 1)
        if r >= k: hi = mid
        else: lo = mid + 1
    return lo
print("rank1(8) =", rank1(8), " rank0(8) =", 8 - rank1(8), " select1(5) =", select(1, 5), " select0(3) =", select(0, 3))
rank1(8) = 4  rank0(8) = 4  select1(5) = 8  select0(3) = 5

Exercise 13: Merging Bloom filters

Two Bloom filters with the same mm, kk and hash functions represent sets AA and BB. Show that their bitwise OR is exactly the Bloom filter of A∪BA \cup B. Is their bitwise AND the filter of A∩BA \cap B?

Answer

OR: yes, exactly, since a bit is set in the filter of A∪BA \cup B iff some element of AA or of BB sets it. AND: no; it can have more bits set than the filter of A∩BA \cap B, so it is a valid filter for A∩BA \cap B (no false negatives) but with a higher false-positive rate.

Solution

Bit pp of the filter of a set SS is ⋁x∈S[p∈{h1(x),…,hk(x)}]\bigvee_{x \in S} [p \in \{h_1(x), \ldots, h_k(x)\}]. For S=A∪BS = A \cup B this disjunction splits into the one over AA OR the one over BB. For AND, a bit can be set in both filters by different elements (one in A∖BA \setminus B, one in B∖AB \setminus A), so the AND has every bit of the filter of A∩BA \cap B and possibly more. The program checks both facts.

python · try it yourself
import random

def bloom(S, m, k, seed=5):
    bits = [0] * m
    for x in S:
        r = random.Random(x * 1000003 + seed)  # k fixed positions per element
        for _ in range(k): bits[r.randrange(m)] = 1
    return bits

rng = random.Random(13)
A = set(rng.sample(range(10000), 300))
B = set(rng.sample(range(10000), 300))
m, k = 4000, 5
fa, fb = bloom(A, m, k), bloom(B, m, k)
OR = [x | y for x, y in zip(fa, fb)]
AND = [x & y for x, y in zip(fa, fb)]
print("OR == filter(A | B):", OR == bloom(A | B, m, k))
print(f"|A & B| = {len(A & B)}; bits set: AND {sum(AND)}, filter(A & B) {sum(bloom(A & B, m, k))}")
OR == filter(A | B): True
|A & B| = 7; bits set: AND 418, filter(A & B) 35

Exercise 14: Cuckoo graph cycles

Keys a,b,ca, b, c have hash values (h0,h1)=(0,0),(0,1),(1,0)(h_0, h_1) = (0, 0), (0, 1), (1, 0) in two tables of 2 slots each. Can they all be stored? Add a key dd with (1,1)(1, 1): can all four be stored? And a fifth key ee with (0,0)(0, 0)?

Answer

Three keys: yes. Four: yes (the component has 4 vertices and 4 edges, one cycle). Five: no (5 edges on 4 vertices, two cycles), so INSERT(e)(e) fails and forces a rehash.

Solution

The cuckoo graph has vertices T0[0],T0[1],T1[0],T1[1]T_0[0], T_0[1], T_1[0], T_1[1] and an edge per key. a,b,c,da, b, c, d form the 4-cycle T0[0]−T1[0]−T0[1]−T1[1]−T0[0]T_0[0] - T_1[0] - T_0[1] - T_1[1] - T_0[0]: 4 edges on 4 vertices, exactly one cycle, so each key gets its own slot (for instance a→T1[0]a \to T_1[0], c→T0[1]c \to T_0[1], d→T1[1]d \to T_1[1], b→T0[0]b \to T_0[0]). A fifth key adds a fifth edge to a component with 4 vertices: there are only 4 slots, so no placement exists, and an insertion would loop until MAX-LOOP and trigger a rehash with new hash functions (Cuckoo Hashing).

Exercise 15: Backward search by hand

The BWT of banana$\texttt{banana\$} is L=annb$aaL = \texttt{annb\$aa}, and C[$]=0C[\$] = 0, C[a]=1C[a] = 1, C[b]=4C[b] = 4, C[n]=5C[n] = 5. Run backward search for P=anaP = \texttt{ana} and give the number of occurrences.

Answer

Intervals: start [0,7)[0, 7); after "a": [1,4)[1, 4); after "n": [5,7)[5, 7); after "a": [2,4)[2, 4). Two occurrences.

Solution

rank⁡c(L,j)\operatorname{rank}_c(L, j) counts cc in L[0..j−1]L[0..j-1] with L=a,n,n,b,$,a,aL = a, n, n, b, \$, a, a.

  • c=ac = a: sp=1+rank⁡a(0)=1sp = 1 + \operatorname{rank}_a(0) = 1, ep=1+rank⁡a(7)=1+3=4ep = 1 + \operatorname{rank}_a(7) = 1 + 3 = 4. Rows 1 to 3 are the suffixes a$a\$, ana$ana\$, anana$anana\$.
  • c=nc = n: sp=5+rank⁡n(1)=5+0=5sp = 5 + \operatorname{rank}_n(1) = 5 + 0 = 5, ep=5+rank⁡n(4)=5+2=7ep = 5 + \operatorname{rank}_n(4) = 5 + 2 = 7. Rows 5, 6: na$na\$, nana$nana\$.
  • c=ac = a: sp=1+rank⁡a(5)=1+1=2sp = 1 + \operatorname{rank}_a(5) = 1 + 1 = 2, ep=1+rank⁡a(7)=4ep = 1 + \operatorname{rank}_a(7) = 4. Rows 2, 3: ana$ana\$ and anana$anana\$.

So "ana" occurs 4−2=24 - 2 = 2 times (at positions 1 and 3, overlapping), found with 2⋅3=62 \cdot 3 = 6 rank queries (The FM-Index).

Test yourself

A van Emde Boas tree that also stores each structure's minimum inside its clusters makes two non-trivial recursive calls per INSERT. What does its running time become?

  1. O(lg⁡lg⁡U)O(\lg \lg U)
  2. O(lg⁡U)O(\lg U), from T(U)=2T(U)+O(1)T(U) = 2T(\sqrt{U}) + O(1)
  3. O(U)O(\sqrt{U})
  4. O(1)O(1)

Two Bloom filters with the same mm, kk and hash functions represent AA and BB. What is their bitwise OR?

  1. Exactly the Bloom filter of A∪BA \cup B
  2. The Bloom filter of A∩BA \cap B
  3. A filter of A∪BA \cup B with false negatives
  4. Nothing meaningful

In the HDT dynamic connectivity algorithm, why can no edge reach a level above lg⁡n\lg n?

  1. Levels are reset after each deletion
  2. Components of GiG_i have at most n/2in / 2^i vertices, and an edge of level ii needs a component with at least 2 vertices
  3. Each edge is scanned only once
  4. The Euler-tour trees have height lg⁡n\lg n