Open In App

proto van Emde Boas Trees | Set 1 (Background and Introduction)

Last Updated : 13 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Let us consider the below problem statement and think of different solutions for it. Given a set S of elements such that the elements are taken from universe {0, 1, …. u-1}, perform following operations efficiently.

  • insert(x) : Adds an item x to the set+ S.
  • isEmpty() : Returns true if S is empty, else false.
  • find(x) : Returns true if x is present in S, else false.
  • insert(x) : Inserts an item x to S.
  • delete(x) : Delete an item x from S.
  • max() : Returns maximum value from S.
  • min() : Returns minimum value from S.
  • successor(x) : Returns the smallest value in S which is greater than x.
  • predecessor(x) : Returns the largest value in S which is smaller than x.

  Different Solutions Below are different solutions for the above problem.

  • One solution to solve above problem is to use a self-balancing Binary Search Tree like Red-Black Tree, AVL Tree, etc. With this solution, we can perform all above operations in O(Log n) time.
  • Another solution is to use Binary Array (or Bitvector). We create an array of size u and mark presence and absence of an element as 1 or 0 respectively. This solution supports insert(), delete() and find() in O(1) time, but other operations may take O(u) time in worst case.
  • Van Emde Boas tree (or vEB tree) supports insert(), delete, find(), successor() and predecessor() operations in O(Log Log u) time, and max() and min() in O(1) time. Note : In BST solution, we have time complexity in terms of n, here we have time complexity in terms of u. So Van Emde Boas tree may not be suitable when u is much larger than n.

Background (Superimposing a Binary Tree Structure on Binary Array solution) The time complexities of max(), min(), successor() and predecessor() are high in case of Binary Array solution. The idea is to reduce time complexities of these operations by superimposing a binary tree structure over it. Background: proto van Emde Boas Trees

Explanation of above structure:

  1. Leaves of binary tree represent entries of binary array.
  2. An internal node has value 1 if any of its children has value 1, i.e., value of an internal node is bitwise OR of all values of its children.

With above structure, we have optimized max(), min(), successor() and predecessor() to time complexity O(Log u).

  1. min() : Start with root and traverse to a leaf using following rules. While traversing, always choose the leftmost child, i.e., see if left child is 1, go to left child, else go to right child. The leaf node we reach this way is minimum. minimum Since we travel across height of binary tree with u leaves, time complexity is reduced to O(Log u)
  2. max() : Similar to min(). Instead of left child, we prefer tight child.
  3. successor(x) : Start with leaf node indexed with x and travel towards the root until we reach a node z whose right child is 1 and not on the same path covered up until now. Stop at z and travel down to a leaf following the leftmost node with value 1.
  4. predecessor() : This operation is similar to successor. Here we replace left with right and right with left in successor().
  5. find() is still O(1) as we still have binary array as leaves. insert() and delete() are now O(Log u) as we need to update internal nodes. In case of insert, we mark the corresponding leaf as 1, we traverse up and keep updating ancestors to 1 if they were 0.

  proto van Emde Boas Tree We have seen that superimposing a binary tree over binary array reduces time complexity of max(), min(), successor() and predecessor() to O(Log u). Can we reduce this time complexity further to O(Log Log u)? The idea is to have varying degree at different levels. The root node (first level) covers whole universe. Every node of second level (next to root) covers u1/2 elements of universe. Every node of third level covers u1/4 elements and so on. With above recursive structure, we get time complexities of operations using below recursion.

T(u) = T(?u) + O(1)

Solution of this recurrence is,

T(u) = O(Log Log u)

Refer this for detailed steps to 
get the above result.

Recursive definition of proto van Emde Boas Tree: Let u = 22k be the size of universe for some k >= 0.

  1. If u = 2, then it is a bias size tree contains only a binary array of size 2.
  2. Otherwise split the universe into ?(u1/2) blocks of size ?(u1/2) each and add a summary structure to the top.

We perform all queries as using the approach described in background. In this post, we have introduced the idea that is to superimpose tree structure on Binary Array such that nodes of different levels of the tree have varying degrees. 

We will soon be discussing following in coming sets. 

1) Detailed representation. 

2) How to optimize max() and min() to work in O(1)? 

3) Implementation of the above operations. 

Sources: http://www-di.inf.puc-rio.br/~laber/vanEmdeBoas.pdf http://web.stanford.edu/class/cs166/lectures/14/Small14.pdf 


Similar Reads

Problem Solving for Minimum Spanning Trees (Kruskal’s and Prim’s)
Minimum spanning Tree (MST) is an important topic for GATE. Therefore, we will discuss how to solve different types of questions based on MST. Before understanding this article, you should understand basics of MST and their algorithms (Kruskal’s algorithm and Prim’s algorithm). Type 1. Conceptual questions based on MST - There are some important pr
5 min read
Practice questions on B and B+ Trees
In this article, we will discuss different types of problems based on B and B+ trees. Before understanding this article, you should understand basics of B and B+ trees (see: Introduction, Insert, Delete). These are the types of questions asked in GATE based on B and B+ trees. Type 1. Based on order and number of keys in B and B+ tree - These are th
5 min read
Combinatorics on ordered trees
An ordered tree is an oriented tree in which the children of a node are somehow ordered. It is a rooted tree in which an ordering is specified for the children of each vertex. This is called a "plane tree" because the ordering of the children is equivalent to an embedding of the tree in the plane, with the root at the top and the children of each v
13 min read
Expression Trees Using Classes in C++ with Implementation
Prerequisite: Expression Tree The expression tree is a binary tree in which each internal node corresponds to the operator and each leaf node corresponds to the operand so for example expression tree for 3 + ((5+9)*2) would be: In expression trees, leaf nodes are operands and non-leaf nodes are operators. That means an expression tree is a binary t
4 min read
Introduction to ANN | Set 4 (Network Architectures)
Prerequisites: Introduction to ANN | Set-1, Set-2, Set-3 An Artificial Neural Network (ANN) is an information processing paradigm that is inspired by the brain. ANNs, like people, learn by examples. An ANN is configured for a specific application, such as pattern recognition or data classification, through a learning process. Learning largely invol
5 min read
Introduction of NewSQL | Set 2
Prerequisite - Introduction to NoSQL, Difference between SQL and NoSQL The term NewSQL is not exactly as wide as NoSQL. NewSQL systems all begin with the relational data model and the SQL query language and they all attempt to cover portion of similar types of scalability, flexibility or lack-of-focus that has driven the NoSQL development. Many off
2 min read
Introduction to Internet of Things (IoT) - Set 1
IoT stands for Internet of Things. It refers to the interconnectedness of physical devices, such as appliances and vehicles, that are embedded with software, sensors, and connectivity which enables these objects to connect and exchange data. This technology allows for the collection and sharing of data from a vast network of devices, creating oppor
9 min read
Image Splicing | Set 1 (Introduction)
Image Forgery can be largely divided into two sub categories: (1) Copy Move Forgery (2) Image Splicing Copy Move Forgery Copy Move forgery is a process of making a composite picture by cutting some object from image and adding it to the same image. Image Splicing Image Splicing is a process of making a composite picture by cutting some object from
1 min read
Introduction to Xamarin | A Software for Mobile App Development and App Creation
The entire world is now surrounded by billions and trillions of mobile Tech which is inevitable. The major share of the development of mobile apps is taken by the Google's Android, Apple's iOS, and Microsoft's Windows. Every new learner or newbie in Mobile Development Domain finds himself in the dilemma of choosing the platform to start with. They
9 min read
Introduction of 4th and 5th Normal Form in DBMS
Two of the highest levels of database normalization are the fourth normal form (4NF) and the fifth normal form (5NF). Multivalued dependencies are handled by 4NF, whereas join dependencies are handled by 5NF. If two or more independent relations are kept in a single relation or we can say multivalue dependency occurs when the presence of one or mor
5 min read
Article Tags :
Practice Tags :