module06

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
Gallop Search Problem in Binary-Search: Sometimes we cannot see the end of the array (data streams, a huge file, 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Self-Organizing Search Unordered linked list search : Θ( n ), insert : Θ(1), delete : Θ(1) (after a search) Linear search to find an item in the list Is there a suitable ordering? No: if items are accessed equally likely
Background image of page 6
Image of page 7
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 Right Arrow Icon
Ask a homework question - tutors are online