Treaps - an introduction

So what are treaps?

Technically speaking, we can define Treaps at a surface level as :-

Example of a Treap

Why are we even bothered about such a data structure, what is the intuition and motivation behind Treaps?

Now, the question is which will be in majority, skewed BSTs or more balanced BSTs?

Now, where are the Treaps, this is not what we started with?Here's the answer to this :

What if the situation is online instead of offline?

This means if we get values to be inserted in the BST on the go, instead of all at begining, we cannot do random permute in such a scenario.

Here we will use the heap property we introduced earlier, so lets say we have a max heap.

Such a thing has a high property that we maintain an almost balanced BST all the time, but remember its just a chance game, although the probability here is very high.

If you are curious how about high is the probabilty? 


Note : There are other data structures such as Red Black Trees and AVL Trees for maintaining balanced BST. They do not use randomness and they guarantee that tree is a Balanced Binary Search Tree. They are more complex than Treaps.