1
COMP 250
Lecture 26
maps
- Nov. 8/9, 2017
maps Nov. 8/9, 2017 1 Map (Mathematics) codomain domain A map - - PowerPoint PPT Presentation
COMP 250 Lecture 26 maps Nov. 8/9, 2017 1 Map (Mathematics) codomain domain A map is a set of pairs { (x, f(x)) }. Each x in domain maps to exactly one f(x) in codomain, but it can happen that f(x1) = f(x2) for different
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1 2 3 4
null null
put( key, value ) get(key) remove(key)
16
head tail put( key, value ) get(key) remove(key)
17
18
19
1 2 3 4
null null
put( key, value ) get(key) remove(key)
20
put( key, value ) get(key) remove(key)
21
put( key, value ) get(key) remove(key)
22
4 9 12 22 3 6 8 14
23
24
3 6 8 14
Recall notation: black dots are not part of the map.
25
26
By default, “obj1 == obj2” means “obj1.hashcode() == obj2.hashcode()” 1-to-1 (not many-to-1)
27
28
29
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
30
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
31
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
32
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
33
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
34
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
35
𝑗=0 𝑡.𝑚𝑓𝑜𝑢ℎ−1
36
37
For a degree 𝑜 polynomial, Horner’s rule uses O(n) multiplications, not O(𝑜2).
38
hashcode()
We want to map the keys to a small range of positive integers. How ?
3 6