Please refer all previous articles on Proto Van Emde Boas Tree first.
Successor Query Procedure:
- Base case: For Proto-VEB of size 2 the only possibility is that key is 0 and if the next key is present then it is its successor or there is no successor. So the same procedure is applied.
- First, we will look in the present cluster (means the cluster in which the query key is present) if there is any key greater than query key is present then we will be the successor so we return it.
- If above is not the case then we will recursively call successor procedure over summary to find next true value in summary. If there is no next true value in summary then we will return -1 as a sign that no larger key is present.
- In the above operation if we find any next true value then we will find the minimum key present in that cluster which will be the successor of the query key.
See the image below for basic understanding of the operation of Successor query:
Procedure for Predecessor is same as successor with some minor changes you should try to understand it from the above description for successor query. See the image below for basic understanding:
Below is the implementation:
Recurrence Relation for Successor and Predecessor Queries:
T(u) = T(u) = 2T()) + O(log2())
Time Complexity : O(log2(u)*log2(log2(u)))
- Van Emde Boas Tree - Set 3 | Successor and Predecessor
- Proto Van Emde Boas Tree | Set 3 | Insertion and isMember Query
- Proto Van Emde Boas Tree | Set 2 | Construction
- Proto Van Emde Boas Tree | Set 5 | Queries: Minimum, Maximum
- 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 2 | Insertion, Find, Minimum and Maximum Queries
- Inorder predecessor and successor for a given key in BST | Iterative Approach
- Pre-Order Successor of all nodes in Binary Search Tree
- LCA for n-ary Tree | Constant Query O(1)
- Segment Tree | Set 2 (Range Minimum Query)
- Iterative Segment Tree (Range Minimum Query)
- Segment Tree | Set 2 (Range Maximum Query with Node Update)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.