Hash tables Flashcards

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

Define Hash table

A

A data structure that implements an associative array (dictionary)

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

How is data stored in an associative array?

A

As a collection of key-value pairs

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

What is hashing?

A

The position of the data within the array is determined by applying a hashing algorithm to the key

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

What is the hashing algorithm called?

A

A hash function

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

Pros of hash tables

A

Enable efficient searching

Maintaining data in a hash table is very efficient

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

Why must you use an array to implement hash tables?

A

So you can access each position of the array directly by specifying the index of the position

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

What are the positions within an array called?

A

Buckets

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

What’s a bucket?

A

A single piece of data or complex data object stored alongside a key

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

Load factor =

A

N (number of occupied buckets) / K (Number of buckets)

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

What is the optimal load factor?

A

0.75

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

What are the main requirements of a hash function?

A

Always produces the same hash value for the same key

Provides a uniform distribution of hash values- every value has an equal chance of being generated

Minimises clustering- keys don’t produce the same hash value

Be fast to compute

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

Define a collision

A

When 2 or more different keys produce the same hash value

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