SearchTree

SearchTree - Search Trees. 1. Trees useful structure for...

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

View Full Document Right Arrow Icon
Search Trees. 1. Trees useful structure for hierarchical information, searching, etc. With large data, repeated linear search in link list too slow. With appropriate binary search trees, we can do searches, inserts, deletes, find successor, find pred etc in O(log n). Hashing is convenient if you just need to do inserts and lookups, but suppose you wanted to do: Lookup-by-prefix: type in first few letters of someone's name and have it output all names in the database that begin with those letters. Find-in-range[key1, key2]: output all keys between key1 and key2 A version of lookup(x) that returns the closest key to x when x is not in the database. Also consider operations like: Output the kth smallest element; assume all keys are distinct. Do a version of lookup(x) that tells us the rank of x (how many keys are smaller than x). 2. A recursive definition of the tree: tree either empty, or it has a root node r, with zero or more non-empty subtrees, whose roots are children of r. Drawn as r at the root, and edges from r to the roots of subtrees T1, T2, . ., Tk root k1 k2 .... kl Subtree1 Subtree2 Subtreel 3. No other structure: arbitrary distribution of depths, keys etc. 4. Example. A B M L T C F X Y G 5. A path in tree is the sequence of nodes, or edges. Path length is the number of edges. Paths are unique in a tree. Depth of a node is measured as path length from the root. Parent-child relationshio. Ancestor-descendant relationship. 6. The Directory structure example. the tree organizes the directory structure, making it intuitive to traverse.
Background image of page 1

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

View Full DocumentRight Arrow Icon
/usr alex bill charles research teaching junk paper books c1 c2 c2 7. Tree Traversals. 1. Listing of sub-directories ---- Pre-order traversal: print the node, then recursively traverse each subtree. 2. Compute dir sizes --- post-order traversal: compute sizes of all subtrees, then add them to get the size of the dir. 8. Binary Trees. Each node has 0, 1, or 2 children. Most common form of trees: heap; expression trees; branch-and-bound algorithms. 9. Binary SEARCH Trees. Important application of binary trees in searching and implementing a search ADT. For simplicity, we assume that objects are identified by
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 130a taught by Professor Suri during the Fall '11 term at UCSB.

Page1 / 8

SearchTree - Search Trees. 1. Trees useful structure for...

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

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