Hash Tables

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Given an array with indices 0..9 to store integers from 0..500, the modulo (remainder) operator can be used to map 25 to index _________.

5

Suppose that the current capacity of a quadratic probing hash table is 101 (i.e., the length of the backing array is 101) and the number of entries is 52. It is time to "double" the capacity of the table. What should the new capacity be?

211

Given a hash table with 100 buckets and modulo hash function, in which bucket will HashInsert(table, item 334) insert item 334?

34

When deletions are done by marking an element as deleted rather than erasing it entirely, this is called _____________________.

Lazy Deletion

A hash table with 18 items and 31 buckets has a load factor of __________.

0.58

A perfect hash function maps items to buckets with no collisions. The runtime for insert, search, and remove is O(_____) with a perfect hash function.

1

Given a hash table with 50 buckets and modulo hash function, in which bucket will HashSearch(table, 201) search for the item?

1

In a hash table, insertion requires O(____) runtime.

1

In a hash table, removal requires O(____) runtime.

1

In a hash table, searching requires O(____) runtime.

1

In a hash table using open addressing (linear/quadratic probing), the load factor cannot exceed ________.

1/1.0

A modulo hash function is used to map to indices 0 to 9. The hash function should be: key % _____.

10

The hash function key % 10 will perform poorly if the expected keys are all multiples of _____, because all insertions will collide at bucket 0.

10

A modulo hash function for a 50 entry hash table is: key % _____.

50

Given a hash table T with 25 slots that stores 2000 elements, the load factor is __________.

80

Given an array with indices 0..9 to store integers from 0..500, the modulo (remainder) operator can be used to map 149 to index ___________.

9

key % 1000 maps to indices 0 through ____.

999

Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions? A) (97 × 97 × 97)/100^3 B) (99 × 98 × 97)/100^3 C) (97)/100^3 D) (97 × 97 × 97)/(3! × 100^3)

A

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true? (separate answers with commas) A) 9679, 1989, 4199 hash to the same value B) 1471, 6171 hash to the same value C) All elements hash to the same value D) Each element hashes to a different value

A,B

A hash table's ______________ is the number of items in the hash table divided by the number of buckets.

load factor/lambda

A hash table is a data structure that stores unordered items by mapping (or hashing) each item to a location in an ___________.

Array

For a hash table with which collision-resolving strategy is it possible to have a load factor > 1.

False

True/False: A hash function takes a message of fixed length and generates a code of variable length.

False

True/False: Duplicate keys are possible in a hash table.

False

True/False: In a hash table that resolves collisions using separate chaining, rehashing is needed to ensure that all operations perform correctly when the hash table's load factor is large.

False

True/False: In a hash table using chaining, the load factor cannot exceed 1.0.

False

True/False: In the average case, it is fastest to use a hash table when creating a data structure that will be often used to find the minimum element.

False

True/False: Suppose a hash table has 101 buckets. If the hash table was using open addressing (linear/quadratic probing), a load factor > 0.9 guarantees a collision during insertion.

False

True/False: Suppose we have two key-value pairs: ("hello", 3) and ("world", 390). Placing these two items in the hash table must NOT result in a collision.

False

True/False: The hashCode method (in last week's assignment) must return an integer between 0 and X (exclusive), for a hash table with capacity X.

False

A hash function computes a bucket index from an item's _____.

Key

On average, a good hash function will achieve O(1) inserts, searches, and removes, but in the worst-case may require O(_____).

N

A hash table with N buckets is commonly resized to the next prime number >= ___________.

N*2

Yes/No: Will the hash function and expected key likely work well if: Hash function: key % 1000 Key: 6-digit employee ID Hash table size: 20000

No

Yes/No: Will the hash function and expected key likely work well if: Hash function: key % 40 Key: 4-digit even numbers Hash table size: 40

No

Lazy deletion refers to a method of deleting elements from a hash table that uses ________________.

Open Addressing

A hash table with N buckets is commonly resized to the next _____________ number >= N*2.

Prime

For a hash table with which collision-resolving strategy can a load factor of λ = 0.7 guarantee that adding a new item is O(1)?

Separate Chaining/Chaining

For a hash table with which collision-resolving strategy is it possible to have a load factor of λ = 2.5?

Separate Chaining/Chaining

For a hash table with which collision-resolving strategy is it possible to have a load factor < 1.

True

True/False: A hash function may give the same hash value for distinct messages.

True

True/False: A hash function takes a message of arbitrary length and generates a fixed length code.

True

True/False: Duplicate values are possible in a hash table.

True

True/False: Suppose a hash table has 101 buckets. If the hash table was using chaining, the load factor could be <= 0.1, but an individual bucket could still contain 10 items.

True

True/False: Suppose a hash table has 101 buckets. If the hash table was using open addressing (linear/quadratic probing), a load factor < 0.25 guarantees that no more than 25 collisions will occur during insertion.

True

True/False: Suppose we have two key-value pairs: ("hello", 3) and ("hello", 49). These two items must have the same hash code.

True

True/False: When a hash table is initialized, all entries must be empty-since-start/empty-after-removal.

True

Yes/No: Will the hash function and expected key likely work well if: Hash function: key % 250 Key: 5-digit customer ID Hash table size: 250

Yes

With quadratic probing, if an item's mapped bucket is H, the formula for finding the item's index is (H + c1*i + cs*i^2) mod(_______)?

size/tablesize


Set pelajaran terkait

Biology Quiz Question for Test 2

View Set

consumer behavior- exam 3- quiz questions

View Set

Crisis 2 Exam 2 Book Questions BSN3

View Set

EXAM FX (Types of Property Policies)

View Set

Photosynthesis and Respiration Quiz

View Set