Hashing Structures Flashcards

1
Q

give the three components of a hash map

A

bucket array
hashing function
collision resolution strategy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

describe the hash map ADT

A

insert (k,v)

find(k)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

describe a collision

A

two keys k, k’ such that h(k) = h(k’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

describe the two parts of a hash function

A
  1. compute the hash code

2. map to range using compression map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is the division method

A

h(k) = k mod N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

describe the MAD method

A

h(k) = ((ak + b ) mod p) mod N

where p is prime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

describe separate chaining

A

collision resolved by inserting in the next free place

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

describe linear probing

A

scan through array for empty space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

describe quadratic probing

A

try A[(i+j^2) mod N]
i = h(k)
j = 0,1,2,3,…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

describe double hashing

A

try A[i + (j h’(k)]
i = h(h)
j = 0,1,2,3…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

describe rehashing

A

if a hash table becomes too full we must rehash to make it larger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is the load factor

A

how full the table is. This should be kept below 1.
k / n
k = number of items
n = capacity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

give the worst and average time complexity for inserting

A

O(n)

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

give the space complexity

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

give the worst and average time complexities for find

A

O(n)

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

give the worst and average time complexities for remove

A

O(n)

O(1)