Hash Maps Flashcards

1
Q

What is the ‘Set’ ADT and its operations?

A

A collection of data items that does not allow duplicates.

Operations: insert(x), remove(x), contains(x), isEmpty(), size(), addAll(x)/union(x), retainAll(x)/intersection(x), removeAll()

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

What is the ‘Ordered Set’ ADT, its additional operations, and its important operation runtimes?

A

A set with a ‘total order’ defined on the items. (All items pairs in a <, >, relation)

Operations: findMin(), findMax(x)

Runtime for balanced search trees Oln(n): insert(x), remove(x), contains().

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

What is the ‘Map ADT’ and describe its operations?

A

The map ADT is a collection of (key, value) pairs.

Keys are unique (sets), but values are not.

Operations: get(key), set(key, value)

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

What is a common way to store a map whose keys are integers?

A

In an array, so that the runtime for get(k), and put(k, v) are Theta(1).

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

What is a ‘Hash Table’ and what is its lookup runtime?

A

A data structure that implements an associative array or dictionary. It is an abstract data type that maps keys to values.

Look/ Get: Theta(1);

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

What are hashing ‘collisions’?

A

When more than one value is hashed by a particular hash function hashes to the same slot in the table.

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

What are the two goals of a good hash function?

A
  1. Uniform Distribution i.e. to spread the keys out as much as possible
  2. Ensure that all table cells can be used.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the four practices to be cognizant of when designing a hash table?

A
  1. Keep tableSize a prime number
  2. When combining hash values, make the factors prime numbers.
  3. Only use immutable objects as keys
  4. When two objects are equal, their hash code methods must return the same values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define the two methods to resolve collisions in hash tables.

A
  1. Separate Chaining: Keeps all items whose key hashes to the same value in a linkedList.
  2. Linear Probing: Placing the new key in another empty cell bases on a secondary function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the equation to calculate the ‘Load Factor’?

A

Load Factor (lambda) = The average length of a list = N/tableSize.

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