09-scapegoat+splay

09-scapegoat+splay - Algorithms Lecture 9: Scapegoat and...

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 9: Scapegoat and Splay Trees Everything was balanced before the computers went off line. Try and adjust something, and you unbalance something else. Try and adjust that, you unbalance two more and before you know whats happened, the ship is out of control. Blake, Blakes 7 , Breakdown (March 6, 1978) A good scapegoat is nearly as welcome as a solution to the problem. Anonymous Lets play. El Mariachi [Antonio Banderas], Desperado (1992) CAPTAIN: TAKE OFF EVERY ZIG!! CAPTAIN: YOU KNOW WHAT YOU DOING. CAPTAIN: MOVE ZIG. CAPTAIN: FOR GREAT JUSTICE. Zero Wing (1992) 9 Scapegoat and Splay Trees 9.1 Definitions Ill assume that everyone is already familiar with the standard terminology for binary search treesnode, search key, edge, root, internal node, leaf, right child, left child, parent, descendant, sibling, ancestor, subtree, preorder, postorder, inorder, etc.as well as the standard algorithms for searching for a node, inserting a node, or deleting a node. Otherwise, consult your favorite data structures textbook. For this lecture, we will consider only full binary treeswhere every internal node has exactly two childrenwhere only the internal nodes actually store search keys. In practice, we can represent the leaves with null pointers. Recall that the depth of a node is its distance from the root, and its height is the distance to the farthest leaf in its subtree. The height (or depth) of the tree is just the height of the root. The size of a node is the number of nodes in its subtree. The size n of the whole tree is just the total number of nodes. A tree with height h has at most 2 h leaves, so the minimum height of an n-leaf binary tree is d lg n e . In the worst case, the time required for a search, insertion, or deletion to the height of the tree, so in general we would like keep the height as close to lg n as possible. The best we can possibly do is to have a perfectly balanced tree, in which each subtree has as close to half the leaves as possible, and both subtrees are perfectly balanced. The height of a perfectly balanced tree is d lg n e , so the worst-case search time is O ( log n ) . However, even if we started with a perfectly balanced tree, a malicious sequence of insertions and / or deletions could make the tree arbitrarily unbalanced, driving the search time up to ( n ) . To avoid this problem, we need to periodically modify the tree to maintain balance. There are several methods for doing this, and depending on the method we use, the search tree is given a different name. Examples include AVL trees, red-black trees, height-balanced trees, weight-balanced trees, bounded-balance trees, path-balanced trees, B-trees, treaps, randomized binary search trees, skip lists, 1 and jumplists. Some of these trees support searches, insertions, and deletions, in O ( log n ) worst-case time, others in O ( log n ) amortized time, still others in O ( log n ) expected time.time....
View Full Document

Page1 / 12

09-scapegoat+splay - Algorithms Lecture 9: Scapegoat and...

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