Hash Map Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the 3 requirements for a good hash function?

A
  • Consistent
  • Efficient to compute and not ignore siginficant numbers
  • Should uniformly distribute
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why should array size M be prime?

A

If not, not all bits of key will play role and will therefore lose a chance to disperse evvenly and avoid collisions

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

How do we hash integers, floating-pont numbers, strings?

A

Use modular hashing
* Integers: Calculation with modular hashing to get index
* Floats: Binary representation of key
* Strings: Treat as large integers
* Compound keys: Mix together in a similar way to strings

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

How do we convert hashCode() into an array index?

A

Combine with modular hashing by converting 32-bit to 31-bit then compute remainder

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

What is separate Chaining?

A

Build a linked list or symbol table for each bucket that contains a collision. Should be kept short.

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

How do we implement symbol tables into hash table?

A

Build for each array index a symbol table of keys that hash to that index
Therefore maintain an array of ST objects that implements operations. This is done by computing Hash Function to get index of object that contain key, then using get() and put() to delegate the operation to that table.

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

What is the average length of the list?

A

N/M

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

What is the probability that a list has more than t x a keys?

A

(a e/y)^t e ^(-a)

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

What is linear probing?

A

Store N key-value pairs in hash table of size M > N, relying on empty entries for collision

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

What are the 3 cases for linear probing?

A
  • Key equal to search key
  • Search reaches null
  • Key not equal, try next with iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is probing?

A

Operation of determining whether a given table entry holds an item whose key is equal to the search

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

How do we delete a key-value pair from a linear probing table?

A
  • Check if key exists
  • Find index by hashing
  • Find index where key matches given key, set both the key and value at index to null
  • Rehash the subsequent key-value pairs re-inserting key-value pairs into hash table using put
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the load factor, a?

A

Percentage of table entries that are occupied. Can never be 1

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