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.
We will do the same procedure for the summary which will assign true according to the inserted 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.
- Proto Van Emde Boas Tree | Set 6 | Query : Successor and Predecessor
- Proto Van Emde Boas Tree | Set 2 | Construction
- Proto Van Emde Boas Tree | Set 5 | Queries: Minimum, Maximum
- Van Emde Boas Tree | Set 2 | Insertion, Find, Minimum and Maximum Queries
- Proto Van Emde Boas Trees | Set 4 | Deletion
- proto van Emde Boas Trees | Set 1 (Background and Introduction)
- Van Emde Boas Tree | Set 4 | Deletion
- Van Emde Boas Tree | Set 1 | Basics and Construction
- Van Emde Boas Tree - Set 3 | Successor and Predecessor
- LCA for n-ary Tree | Constant Query O(1)
- AVL Tree | Set 1 (Insertion)
- Segment Tree | Set 2 (Range Minimum Query)
- ScapeGoat Tree | Set 1 (Introduction and Insertion)
- Iterative Segment Tree (Range Minimum Query)
- Optimal sequence for AVL tree insertion (without any rotations)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.