It is highly recommended to read the previous articles on Van Emde Boas Tree first.
Procedure for successor:
- Base case: If the size of the tree is 2 then if query-key is 0 and key – 1 is present in the tree then return 1, as it will be the successor. Otherwise return null.
- If the key is less than minimum then we can easily say that minimum will be the successor of the query-key.
- Recursive case:
- We first search for the successor in the cluster in which the key is present.
- If we find any successor in the cluster then generate its index and return it.
- Otherwise, search for the next cluster, with at least one key present, in summary, and return the index the minimum of that cluster.
See query for the successor of 0 the in below image:
Below image represents the successor of 1 query over VEB tree containing key 1 & 2:
Procedure for Predecessor:
- Base case: If the size of the tree is 2 then if query-key is 1 and key-0 is present in the tree then return 0, as it will be the predecessor. Otherwise return null.
- If the key is greater than the maximum then we can easily say that maximum will be the predecessor of the query-key.
- Recursive case:
- We first search for the predecessor in the cluster in which the key is present.
- If we find any predecessor in the cluster then generate its index and return it.
- Otherwise, search for the previous cluster, with at least one key present, in summary. If any cluster is present then return the index of the maximum of that cluster.
- If no cluster with that property is present then see if due to lazy propagation, the minimum of the tree(In which the cluster is present) is less than the key, if yes then return minimum otherwise return null.
Below image represents query predecessor of key-2:
3 4 6
- Proto Van Emde Boas Tree | Set 6 | Query : Successor and Predecessor
- Van Emde Boas Tree | Set 4 | Deletion
- Van Emde Boas Tree | Set 1 | Basics and Construction
- Proto Van Emde Boas Tree | Set 2 | Construction
- Proto Van Emde Boas Tree | Set 3 | Insertion and isMember Query
- 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)
- Inorder predecessor and successor for a given key in BST | Iterative Approach
- Pre-Order Successor of all nodes in Binary Search Tree
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
- Cartesian tree from inorder traversal | Segment Tree
- Two Dimensional Binary Indexed Tree or Fenwick Tree
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.
Improved By : Aakash_Panchal