Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
c0D3M authored Mar 31, 2017
1 parent 6736999 commit 49960b8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Treaps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ Each node in this tree has a pair __(X,Y)__, Binary search tree property gets sa
and right subtree elelments > X.
Also for Y all nodes in left and right subtree are less than Y.Y values are called **priority**.
This data structure is often useful in balancing BST. If priorities are chosen randomly height of this binary search tree is **O(log N)**

As per Insert procedure , key point is anything you insert left subtree contain node < F and right subtree > F
- P(F) < P(J) we cannot insert here, since K(F) < K(J), goto left subtree.
- P(F) > P(C) , so we know this is the right place of F , call split ( C, F, F->L, F->R).
- K(F) > K(C) so we know that **F->L = C** but we still have to find F->R , which would be __first maximumum__ found in **right subtree**.
split(C->R, F, C->R, R)
- K(G) > K(F), **first maximum** found , this right subtree of **F->R = G**, now **C->R which was earlier G**, is changed, so find **first minimum** in **left subtree** i.e. G->L split(G->L, F, L, G->L)
- K(D)< K(F), we found first minimum and this will be added to **C->R = D** , once again **G->L** changed , so find first maximum in right subtree.


So recurively this process repeats until we reach empty nodes.

0 comments on commit 49960b8

Please sign in to comment.