Description
Question 1: AVL Trees
AVL Trees are a type of self-balancing binary search tree (BST), similar in purpose to red-black trees.
The defining property of an AVL tree is:
For every node nn in the tree,
∣height(n.left)−height(n.right)∣≤1\left| \text{height}(n.\text{left}) – \text{height}(n.\text{right}) \right| \le 1
This means the heights of the left and right subtrees of any node differ by at most 1.
Let:
-
hh = height of the AVL tree
-
nn = number of nodes in the tree
The goal of this problem is to analyze the relationship between hh and nn.
(A)
Prove that:
n≥Fhn \ge F_h
where FhF_h is the hthh^{\text{th}} Fibonacci number, defined as:
F0=1,F1=1,F2=2,…F_0 = 1,\quad F_1 = 1,\quad F_2 = 2,\quad \ldots
Hint:
Use strong induction with two base cases:
-
First prove the statement for AVL trees of height 00 and 11.
-
Then assume the statement holds for all AVL trees of height ≤h\le h, and prove it for height h+1h + 1.
(B)
It is known that for all k≥30k \ge 30:
Fk≥1.5kF_k \ge 1.5^k
Using this fact and the result from part (A), show that:
h=Θ(logn)h = \Theta(\log n)
(C)
Consider inserting a node into an AVL tree.
-
The left image shows an AVL tree before insertion.
-
The right image shows the tree after performing a BST insertion, which violates the AVL property.
You are given an image illustrating this situation.
Task:
Describe a sequence of left and/or right rotations that restores the AVL property.
For each rotation:
-
Specify which node is the root of the rotation
-
Specify whether it is a left or right rotation
You may include diagrams or images if you wish (ensure they are uploaded with the notebook).
Question 2: Bloom Filters
A Bloom filter is a probabilistic data structure used to maintain a set SS of keys.
It supports:
-
Insertion of keys
-
Membership queries (“Is key kk in the set?”)
Bloom filters are useful when keys are complex objects (e.g., packets, images) that are expensive to compare.
Bloom Filter Structure
-
A Boolean array TT of size mm
-
ll independent hash functions h1,h2,…,hlh_1, h_2, \ldots, h_l
Initially:
T[i]=FALSEfor all iT[i] = \text{FALSE} \quad \text{for all } i
To insert a key kk:
-
Compute:
h1(k),h2(k),…,hl(k)h_1(k), h_2(k), \ldots, h_l(k)
-
Set:
T[h1(k)]=T[h2(k)]=⋯=T[hl(k)]=TRUET[h_1(k)] = T[h_2(k)] = \cdots = T[h_l(k)] = \text{TRUE}
Note: A Bloom filter is not a hash table, although both use hash functions.
(A)
To test whether a key kk belongs to the set, we check whether:
T[h1(k)],T[h2(k)],…,T[hl(k)]T[h_1(k)], T[h_2(k)], \ldots, T[h_l(k)]
are all TRUE.
Explain whether this method can result in:
-
A false positive
-
A false negative
(B)
Assume the hash functions are uniform, meaning:
P(hi(k)=j)=1m\mathbb{P}(h_i(k) = j) = \frac{1}{m}
for any key kk, hash function hih_i, and table cell jj.
If nn keys are inserted into the Bloom filter, compute the probability that a given cell T[j]T[j] remains FALSE.
(C)
Using the result from part (B), estimate the probability of a false positive, i.e., the probability that all ll cells:
T[i1],T[i2],…,T[il]T[i_1], T[i_2], \ldots, T[i_l]
are TRUE for a key that was never inserted.

