Hash Table Flashcards

1
Q

What is a Hash Table?

A

A hash table (commonly referred to as hash map) is a data structure that implements an associative array abstract data type, a structure that can map keys to values.

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

How do hash tables work?

A

A hash table uses a hash function on an element to compute an index, also called a hash code, into an array of buckets or slots, from which the desired value can be found. During lookup, the key is hashed and the resulting hash indicates where the corresponding value is stored.

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

What is hashing?

A

Hashing is the most common example of a space-time tradeoff. Instead of linearly searching an array every time to determine if an element is present, which takes O(n) time, we can traverse the array once and hash all the elements into a hash table.

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

Separate chaining

A

A linked list is used for each value, so that it stores all the collided items.

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

Open addressing

A

All entry records are stored in the bucket array itself. When a new entry has to be inserted, the buckets are examined, starting with the hashed-to slot and proceeding in some probe sequence, until an unoccupied slot is found.

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

Access

A

Access N/A Accessing not possible as the hash code is not known

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

Search
Insert
Remove

A

Search O(1)*
Insert O(1)*
Remove O(1)*

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