CSCA48H3 Lecture Notes - Lecture 18: Init, Hash Table, Hash Function

117 views4 pages

Document Summary

Csca48 - lecture 18 - hashing code + explanation. Hashing would provide an o(1), constant time search technique. Hash table: collection of items, where each position of the table is called a slot (numbered from 0 to m-1, where m is the size of the hash table) Hash function: maps item to slot -> h(item) = (item) % (m), where h(item) is the hash value (slot # ) of the item. Collision : two or more items technically belong in the same spot. Linear probing: look sequentially, slot by slot, until we find an open position. Rehashing: the process of looking for another slot after a collision -> rehash(pos) = (pos. + 1) % sizeoftable from week4_sll import * class hashtable(): """ a very basic hash table that stores integer numbers assuming that collision never happens!""" def __init__(self, n): """(hashtable, int) ->nonetype creates an empty list of length n""" self. _array = [none]*n self. _length = n.

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