Hash table Flashcards

1
Q

What does a hash table consist of?

A
  1. a hash function

2. An array of size N

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

What 2 properties does a hash function comprise of?

A
  1. A hash code that will map a key to some integer

2. A compression function that will restrict that integer to a value between 0 and N-1

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

What is the goal of the hash function?

A

allocate a space for the keys in a seemingly random way

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

Which hash code is not suitable for numeric values and strings?

A

Memory address

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

How does the integer cast hash code work briefly? And what is it suitable for?

A

Reinterpreting the bits of the key as integers

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

Which hash code is suitable for strings?

A

polynomial accumulation

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

How does component sum work?

A

We partition the bits of the key into components of fixed length
and we sum the components ignoring overflows

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

Name the 2 types of compression functions and their definitions

A

MAD: (ax+b) mod n

Division: y mod n

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

What is separate chaining and how does it work? Name on disadvantage of it

A

it is a collision handling method, it works by making each cell in an array point to a list of values mapped to that position.

  • it uses more storage space
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is open addressing?

A

It is a collision handling method that causes an entry to be mapped to a different cell

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

What is open addressing?

A

It is a collision handling method that causes an entry to be mapped to a different cell

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

What is linear probing? and name a disadvantage of it

A

Collision handling method where an entry is placed in the cell forward-next to the one it collided with

a longer sequence of probes are formed as collisions will continue to occur

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

Procedure for the remove function in linear probing

A
  1. search for the key in the table
  2. If found, replace value AVAILABLE
  3. return element or null if not found
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the big oh of searches, insertions and removals in a hash table? When does this worst case occur?

A

O(n)

occurs when all of the entries collide

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

Give the formula for the load factor and discuss how it affects the hash table

A

a = n/N

n is the number of entries and
N is the size of the table

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

What is the point of hashtables?

A

to get direct access to the elements stored

16
Q

What are the applications of hashtables?

A
  1. small database
  2. browser cache
  3. compilers
17
Q

Quadratic probing???????????

A