lect0917

# lect0917 - Lecture 8 Balanced search trees 8.1 Overview In...

This preview shows pages 1–3. Sign up to view the full content.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 8 Balanced search trees 8.1 Overview In this lecture we discuss search trees as a method for storing data in a way that supports fast insert, lookup, and delete operations. (Data structures handling these operations are often called dictionary data structures.) The key issue with search trees is that you want them to be balanced so that lookups can be performed quickly, and yet you don’t want to require them to be perfect because that would be too expensive to maintain when a new element is inserted or deleted. In this lecture, we discuss B-trees and treaps , which are two methods that handle this tradeoff so that all desired operations can be performed in time O (log n ). Topics covered in this lecture: • Simple binary search trees: like an on-the-fly version of quicksort. • B-trees: a form of balanced search tree that uses flexibility in its node degrees to efficiently keep the tree balanced. • Treaps: like an on-the-fly version of randomized quicksort, that uses randomization to keep the tree balanced with high probability. • Tree-rotations: an important concept when talking about binary search trees, that is used inside many binary search tree data structures (including treaps). 8.2 Introduction For the next few lectures we will be looking at several important data-structures. A data-structure is a method for storing data so that operations you care about can be performed quickly. Data structures are typically used as part of some larger algorithm or system, and good data structures are often crucial when especially fast performance is needed. We will be focusing in particular on dictionary data structures, which support insert and lookup operations (and usually delete as well). Specificially, Definition 8.1 A dictionary data structure is a data structure supporting the following oper- ations: 41 8.3. SIMPLE BINARY SEARCH TREES 42 • insert(key, object) : insert the (key, object) pair. For instance, this could be a word and its definition, a name and phone number, etc. The key is what will be used to access the object. • lookup(key) : return the associated object. • delete(key) : remove the key and its object from the data structure. We may or may not care about this operation. For example, perhaps we are the phone company and we have a database of people and their phone numbers (plus addresses, billing information and so on). As new people come in, we’d like to be able to insert them into our database. Given a name, we’d like to be able to quickly find their associated information. One option is we could use a sorted array. Then, a lookup takes O (log n ) time using binary search. However, an insert may take Ω( n ) time in the worst case because we have to shift everything to the right in order to make room for the new key. Another option might be an unsorted list. In that case, inserting can be done in O (1) time, but a lookup may take time Ω( n ). In the last lecture we saw a data structure that consisted of an unsorted...
View Full Document

## This note was uploaded on 12/09/2009 for the course CS 2134 taught by Professor Hellerstein during the Spring '07 term at NYU Poly.

### Page1 / 7

lect0917 - Lecture 8 Balanced search trees 8.1 Overview In...

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

View Full Document
Ask a homework question - tutors are online