10-treaps - Algorithms Lecture 10 Treaps and Skip Lists...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Algorithms Lecture 10: Treaps and Skip Lists [ Fa’10 ] I thought the following four [rules] would be enough, provided that I made a firm and constant resolution not to fail even once in the observance of them. The first was never to accept anything as true if I had not evident knowledge of its being so.... The second, to divide each problem I examined into as many parts as was feasible, and as was requisite for its better solution. The third, to direct my thoughts in an orderly way...establishing an order in thought even when the objects had no natural priority one to another. And the last, to make throughout such complete enumerations and such general surveys that I might be sure of leaving nothing out. — René Descartes, Discours de la Méthode (1637) What is luck? Luck is probability taken personally. It is the excitement of bad math. — Penn Jillette (2001), quoting Chip Denman (1998) 10 Randomized Binary Search Trees In this lecture, we consider two randomized alternatives to balanced binary search tree structures such as AVL trees, red-black trees, B-trees, or splay trees, which are arguably simpler than any of these deterministic structures. 10.1 Treaps 10.1.1 Definitions A treap is a binary tree in which every node has both a search key and a priority , where the inorder sequence of search keys is sorted and each node’s priority is smaller than the priorities of its children. 1 In other words, a treap is simultaneously a binary search tree for the search keys and a (min-)heap for the priorities. In our examples, we will use letters for the search keys and numbers for the priorities. I’ll assume from now on that all the keys and priorities are distinct. Under this assumption, we can easily prove by induction that the structure of a treap is completely determined by the search keys and priorities of its nodes. Since it’s a heap, the node v with highest priority must be the root. Since it’s also a binary search tree, any node u with key ( u ) < key ( v ) must be in the left subtree, and any node w with key ( w ) > key ( v ) must be in the right subtree. Finally, since the subtrees are treaps, by induction, their structures are completely determined. The base case is the trivial empty treap. Another way to describe the structure is that a treap is exactly the binary tree that results by inserting the nodes one at a time into an initially empty tree, in order of increasing priority, using the usual insertion algorithm. This is also easy to prove by induction. A third description interprets the keys and priorities as the coordinates of a set of points in the plane. The root corresponds to a T whose joint lies on the topmost point. The T splits the plane into three parts....
View Full Document

This note was uploaded on 10/14/2011 for the course ECON 101 taught by Professor Smith during the Spring '11 term at West Virginia University Institute of Technology.

Page1 / 12

10-treaps - Algorithms Lecture 10 Treaps and Skip Lists...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online