CSE 163
Hashing�
Suh Young Choi�
🎶 Listening to: Tom Day
💬 Before Class: What’s your favorite cold food?
Announcements
Project Deliverables open now on Gradescope
Checkpoint 7 due tonight (last one of the quarter!)
Last resubmission window closes tomorrow
2
This Time
Previously…
3
Runtime Recap
Counting Steps:
Think of growth rates in terms of the input size (n)
4
Data Structures
5
How can the set/dictionary have run-times that don’t depend on the number of elements in the data structure?
Set of Ints
6
nums = set()
nums.add(11) # 11 % 10 == 1
nums.add(49) # 49 % 10 == 9
nums.add(24) # 24 % 10 == 4
nums.add(7) # 7 % 10 == 7
print(49 in nums) # True
print(5 in nums) # False
0 | | 0 | 0 | | 0 | 0 | | 0 | |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
11
7
49
24
Chained Hashing
7
Hash Functions
8
Hashing in Practice
9
class Example:
def __init__(self, a, b, c):
# Initialize _a, _b, _c
def __eq__(self, other):
return self._a == other._a \
and self._b = other._b
def __hash__(self):
return hash((self._a, self._b))
Group Work:
Best Practices
When you first working with this group:
Tips:
10
Before Next Time
Next Time
11