Hashing Flashcards

1
Q

What is the general idea of a hash table?

A

To hash/map an unordered list of entries to a specific position in an array

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

How does a hash table improve the time of the insert, delete and lookup methods?

A

Gives them a O(1) worst case complexity. It will always be O(1) if there are no collisions

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

What is the main disadvantage of a hash table?

A

that some positions will be null so spaces will arise which makes the methods more complex

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

What is the table size abbreviated as?

A

TS which is the number of buckets

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

What is the hash function?

A

The operations done to the key to yield it’s respective index value

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

When does a collision arise

A

When the hash function gives the same index as another key

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

How can the problem of collisions be solved?

A

Have each array point to another data structure(embedded DS)

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

How do the embedded DS effect the total time complexity?

A

balanced tree: O(logN)

list: O(N)

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

What tradeoff exists when choosing a TS?

A

Amount of space and the number of collisions

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

What methods can a hash function implement to spread out keys?

A

multiply some or all values by a constant

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

What is the problem with multiplying keys by a constant?

A

array overflow

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

What is the problem with adding properties together to get the index?

A

permutations

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

How is hashing done?

A

by performing operation(s) on the key to get an index value

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

What is each element being hashed called?

A

A bucket. The index corresponding to it is the bucket index

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

When does the number of items not correspond with the number of buckets?

A

When collisions occur

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

What is the most important attribute when choosing a key?

A

uniqueness

17
Q

What is the most important attribute when choosing a hash function?

A

To get an even spread across the buckets/indeices a..b in other words no collisions

18
Q

What is the most important attribute when choosing a TS?

A

Preferably a table size just above the number of items i.e get the load function as close to one as possible

19
Q

What common operation is done on the bucket?

A

modulo

20
Q

If the TS is 50 then what is the modulo hash function?

A

H(key) = key % 50

21
Q

What does a perfect hash function accomplish?

A

avoids all collisions

22
Q

What is wrong with the modulus hash function h(k) = k % 1000, and a table size 20000?

A

Collisions are likely since the function only hashes to the first 1000 indices

23
Q

What does mid square hash function do?

A
  1. )key^2

2. )modulus of middle n digits by the table size

24
Q

What is the load factor

A

The number of entries/TS

25
Q

What is a trivial hash function and when is it appropriate?

A

When the actual keys are used as the index value. This is usually done when the data is small enough

26
Q

How can hash functions be implemented in java?

A

overriding the equals/hash code

27
Q

What does the common hash method known as extraction do?

A

separate the digits of the key

28
Q

What does the common hash method known as weighting do?

A

Multiplies extracted digits by a constant

29
Q

What does the common hash method known as folding do?

A

combines the extracted/weighted digits into one value