CP114 Lecture Notes - Lecture 12: Simple Algorithm, Bucket Sort, Quicksort

41 views10 pages
School
Course
Professor

Document Summary

Hashing is implemented by a hash function, a function that, given a key value, returns an integer value. We can then use this integer value to decide where in a storage array the data should be stored. Ideally each key value generates a unique index value, thus placing each piece of data in a separate and unique location in the data array. For a movie object the code would look like this def __hash__(self): Generates a hash value from a movie title and year. Postconditions: returns value - the total of the characters in the title string multiplied by the year (int > 0) value = 0 for c in self. title: value = value + ord(c) value *= self. year return value. The next step is to use these hash values to determine where in our data storage array the data should go.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents