Chapter 5 (Hashing) Flashcards

1
Q

Table size should be a ____ ____

A

Prime number

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

In perfect hashing, what is the worst case access time?

A

O(1)

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

What is a drawback of the chaining method?

A

Allocating new nodes

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

What is the formula for the expected number of probes in a linear probing strategy?

A

1/(1-lambda)

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

What is the worst case running time for a find in hopscotch hashing?

A

O(1)

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

T/F Java hash tables require the “equals” and “hashCode” methods to be defined on the hashed objects

A

T

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

How many hash tables does cuckoo hashing use?

A

2

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

How does separate chaining handle collisions?

A

Each index contains a list. Each item that collides is contained in this list

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

What is primary clustering?

A

A large list of values clustered around the same cell

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

What is the primary drawback of linear probing?

A

Primary clustering

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

What is it called when two keys map to the same location?

A

Collision

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

What is lambda?

A

The ratio of the number of elements to the table size

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

What is the job of the hash function?

A

Mapping

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

What is the average running time for inserts, deletes, and finds for hashing?

A

O(1)

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

T/F Hashing supports operations like findMin and findMax

A

F

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

What is the worst case access time in cuckoo hashing?

A

O(1)

17
Q

What is rehashing?

A

When a table is 50% full, create a new table twice the size of the old one and rehash everything to the new table

18
Q

How can duplicates be handled with separate chaining?

A

Having a counter on each element

19
Q

What does Horner’s rule give us?

A

A simple way to compute a polynomial using multiplication and addition

20
Q

In perfect hashing, what is the space required?

A

O(n)

21
Q

What is the strategy of quadratic probing?

A

First look 1 away, then 4, 9, 16, 25, etc.

22
Q

If we want to hash 100 elements into a table size of 100, what would lambda be?

A

1.0

23
Q

T/F Open addressing requires a large table

A

T

24
Q

How can you keep the likelihood of a cycle in cuckoo hashing very small?

A

Keep the load < 0.5

25
Q

In double hashing, what is done to resolve a collision?

A

A second hash function

26
Q

What is the scheme of perfect hashing?

A

Each secondary table can be constructed several times until it is collision free

27
Q

What problem does quadratic probing introduce?

A

Secondary clustering

28
Q

What is a downside of double hashing?

A

Likely to be slower than quadratic probing

29
Q

T/F The hashing function should be a simple algorithm that distributes the keys evenly among the cells

A

T

30
Q

What are three common collision resolution strategies?

A

Linear probing Quadratic probing Double hashing

31
Q

What is done if sliding in hopscotch hashing is unsuccessful?

A

Rehash

32
Q

How does open addressing resolve collisions?

A

By storing a colliding element in an alternate cell

33
Q

In universal hashing, what is the probability of a collision if a hash function is chosen at random?

A

1/M

34
Q

T/F Each secondary table can be constructed several times until it is collision free

A

T

35
Q

In linear probing, cells are tried ____ until an empty cell is found

A

Sequentially

36
Q

With a lambda of 1.0, what should the average list be?

A

1 node

37
Q

What does quadratic probing help prevent?

A

Primary clustering

38
Q

In open addressing, how is the alternate cell chosen?

A

By another function called the collision resolution strategy

39
Q

For ints, how does a hash function convert keys to indices?

A

key % tableSize