day 7 2/2/98 ``1, 2, 3, 4, 5, 6, 7, 8, 9. There should be 9 of these, right?''
proof: keys must satisfy in order constraint and heap ordering constraint. $a smallest (heap order) element. This must be the root. Every smaller (by key order) element must be to the left of the root and larger (by key order) elements must be to the right. Now induct ont he left and right subtrees.
A random treap has priorities of each of its elements assigned randomly.
Search(k) is implemented in the same way as for other binary search trees.
Let:
Break the expected cost of a search is:
EC(m) = EC+(m)+EC-(m)
Consider searching for m+.5 . Then C+ will contain elements only from {1,...,m} . and C- will contain elements only from {m+1,...,n} . The probability that k in C+ is chosen will be [1/( m-k+1)] . åi = 1m[1/( m-i+1)] = Q(ln(m)) . Calculate the contribution from C- in the same way, then add them together to get EC(m) = Q(ln(n)) .
In order to delete, elements must be rotated to the leaves before removal. The expected number of rotations is less than 2. This can be seen by noting that rotations will follow the left most branch of the right child or the right most branch of the left child, then calculating the odds of a long left most or right most chain. Essentially, the tree is probabilistically ``fat'' in that almost all nodes are near to a leaf.