Proto Van Emde Boas Tree | Set 3 | Insertion and isMember Query
Please see previous articles on Proto Van Emde Boas Tree to understand these properly.
Procedure for Insert:
- Base Case: If the size of Proto-VEB is 2 then assign true to the bit array( Here we in code we assign Proto-VEB(1) due to recursive structure and so now it is not nullptr and it act as true ) at the position of key.
- Until we reach at the base case, we will recursively call insert on cluster containing key and also now we use the key as the position of the key in that cluster instead of the query key.
Example: Let’s insert 2 into Proto-VEB (u=4): From the procedure of insert we will start recursion as size of Proto-VEB is greater than 2 so we recursively call insert() on cluster number 2/which is 1 and it’s position 2%which is 0 so recursive call will be insert(cluster, 0).
And cluster is size 2 Proto-VEB, we reached at the base case so it will assign true at( in code Proto-VEB(1) as true ) cluster 0th place.
Likewise, we will do the same procedure over summary.
See the image below for more clarity:
Follow the instructions written near the boxes from top to bottom.
isMember procedure: This procedure returns boolean value according to whether the key is present in Proto-VEB or not. It is quite trivial to understand see the image above to get the idea about it.
- Base Case: If the Proto-VEB size is 2 then check if bit array value at the key position is true or not and return value accordingly. (In code we check whether pointer at the key position is nullptr or not.)
- Recursion: we do recursive call over cluster containing key until we reach the base case.
Implementation of above algorithm:
Insert Algorithm Complexity Recurrence:
T(u) = 2T() + O(1)
This algorithm runs in O(log2(u)) worst-case time.
isMember Algorithm Complexity Recurrence:
T(u) = T() + O(1)
This algorithm runs in O(log2(log2(u))) worst-case time.