module06

# module06 - Module 6: Dictionary Tricks CS 240 - Data...

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

Module 6: Dictionary Tricks CS 240 - Data Structures and Data Management Arne Storjohann Based on lecture notes by R. Dorrigiv and D. Roche School of Computer Science, University of Waterloo Fall 2010 Arne Storjohann (CS, UW) CS240 - Module 6 Fall 2010 1 / 17

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

View Full Document
Dictionary ADT A dictionary is a collection of items , each of which contains a key and some data and is called a key-value pair (KVP). Operations: search insert delete Arne Storjohann (CS, UW) CS240 - Module 6 Fall 2010 2 / 17
Implementations Unordered array or linked list search Θ( n ) insert Θ(1) delete Θ(1) (after a search) Ordered array search Θ(log n ) insert Θ( n ) delete Θ( n ) Balanced binary search trees search Θ(log n ) insert Θ(log n ) delete Θ(log n ) Arne Storjohann (CS, UW) CS240 - Module 6 Fall 2010 3 / 17

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

View Full Document
Interpolation Search Ordered array insert, delete : Θ( n ) search : Θ(log n ) binary search ( A [ ‘, r ] , k ): Check index b + r 2 c = + b 1 2 ( r - ) c Idea: Use the value of the key to guess its location Interpolation Search ( A [ ‘, r ] , k ): Check index + b k - A [ ] A [ r ] - A [ ] ( r - ) c Works well if keys are evenly distributed: O (log log n ) Bad worst case performance: O ( n ) Arne Storjohann (CS, UW) CS240 - Module 6 Fall 2010 4 / 17
Gallop Search Problem in Binary-Search: Sometimes we cannot see the end of the array (data streams, a huge ﬁle, etc.) Gallop-Search ( A , k ) A : An ordered array, k : a key 1. if k < A [0] then return “not found” 2. i 1 3. while A [ i ] exists and k > A [ i ] do 4. i 2 × i 5. if A [ i ] does not exist then return “not found” 6. return Binary-Search( A [ b i / 2 c , i ] , k ) O (log n ) comparisons ( n : location of k in A ) Arne Storjohann (CS, UW) CS240 - Module 6 Fall 2010 5 / 17

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

View Full Document
Self-Organizing Search Unordered linked list search : Θ( n ), insert : Θ(1), delete : Θ(1) (after a search) Linear search to ﬁnd an item in the list Is there a suitable ordering? No: if items are accessed equally likely
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/14/2012 for the course CS 246 taught by Professor Wormer during the Winter '08 term at Waterloo.

### Page1 / 27

module06 - Module 6: Dictionary Tricks CS 240 - Data...

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

View Full Document
Ask a homework question - tutors are online