Van Emde Boas Tree | Set 4 | Deletion
It is highly recommended to read the previous articles on Van Emde Boas Tree first.
Procedure for Delete:
Here we are assuming that the key is already present in the tree.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
- First we check if only one key is present, then assign the maximum and minimum of the tree to null value to delete the key.
- Base Case: If the universe size of the tree is two then, after the above condition of only one key is present is false, exactly two key is present in the tree (after the above condition turns out to false), So delete the query key by assigning maximum and minimum of the tree to another key present in the tree.
- Recursive Case:
- If the key is the minimum of the tree then find the next minimum of the tree and assign it as the minimum of the tree and delete query key.
- Now the query key is not present in the tree. We will have to change the rest of the structure in the tree to eliminate the key completely:
- If the minimum of the cluster of the query key is null then we will delete it from summary as well. Also, if the key is the maximum of the tree then we will find new maximum and assign it as the maximum of the tree.
- Otherwise, if the key is maximum of the tree then find the new maximum and assign it as the maximum of the tree.
Below is the series of images representing ‘delete key-0 query’ over the VEB Tree with 0, 1, 2 keys are present:
Step 1: As 0 is the minimum of the tree, it will satisfy the first condition of else part of the algorithm.
First, it finds the next maximum which is 1 and set is as minimum.
Step 2: Now it will delete key 1 from the cluster.
Step 3: Next condition, cluster has no key, is true, so it will clear the key from the summary as well.
1 2 2 0 1 4
Time Complexity: O(N).
Auxiliary Space: O(N).