BinarySearchTrees - Dictionaries 8:37 AM Ordered Dictionaries Binary Search Trees 6 < 2 Keys are assumed to come from a total order New operations

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

View Full Document Right Arrow Icon
Binary Search Trees 1 Binary Search Trees 6 9 2 4 1 8 < > = Binary Search Trees 2 Ordered Dictionaries Keys are assumed to come from a total order. New operations: ± closestBefore (k) ± closestAfter (k) Binary Search Trees 3 Binary Search (§8.3.3) Binary search performs operation find (k) on a dictionary implemented by means of an array-based sequence, sorted by key ± similar to the high-low game ± at each step, the number of candidate items is halved ± terminates after O(log n) steps Example: find (7) 1 3 4 5 7 8 9 11 14 16 18 19 1 3 4 5 7 8 9 11 14 16 18 19 1 3 4 5 7 8 9 11 14 16 18 19 1 3 4 5 7 8 9 11 14 16 18 19 0 0 0 0 m l h m l h m l h l = m = h Binary Search Trees 4 Lookup Table (§8.3.2) A lookup table is a dictionary implemented by means of a sorted sequence ± We store the items of the dictionary in an array-based sequence, sorted by key ± We use an external comparator for the keys Performance: ± find takes O (log n ) time, using binary search ± insertItem takes O ( n ) time since in the worst case we have to shift
Background image of page 1

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

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

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 2

BinarySearchTrees - Dictionaries 8:37 AM Ordered Dictionaries Binary Search Trees 6 < 2 Keys are assumed to come from a total order New operations

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