Chapter 13- hash tables

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

MD5 produces larger hash values for larger input data sizes.

false- MD5 always produces a 128-bit hash value.

For a decimal mid-square hash function, what is the bucket index for key = 110, N = 200, and R = 3?

10- 110 * 110 = 12100. Middle 3 digits = 210. Then 210 % 200 = 10. The mid-square hash function returns the remainder of the middle digits divided by hash table size

For R = 3, what are the middle bits for a key of 9? 9 * 9 = 81; 81 in binary is 1010001

100- The middle 3 bits are 100, which is 4 in decimal.

Which is not an advantage of storing password hash values, instead of actual passwords, in a database?

database storage space is saved-- Password hash values do not compress passwords, so storage space is not saved when storing hash values.

A hash value can be used to reconstruct the original data

false-- Although true for some hashing functions, MD5 and many others produce a hash value that cannot be used to reconstruct the original data.

Suppose a hash table has 101 buckets. If the hash table was using open addressing, a load factor < 0.25 guarantees that no more than 25 collisions will occur during insertion.

true- A load factor < 0.25 means fewer than 25% of the 101 buckets are in use. Therefore, at most 25 buckets are in use. An insertion only collides with non-empty buckets, so no more than 25 collisions will occur during insertion.

In a hash table using open addressing, the load factor cannot exceed 1.0.

true- With open addressing, one bucket holds at most one item. So a table with N buckets can have at most N items, making the maximum possible load factor N / N = 1.0.

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

1- 201 % 50 = 1. Search, insert, and remove operations all use the hash function to determine the bucket index

item 63

1- 63 % 11 = 8, but the bucket at index 8 already holds item 41. i is incremented to 1, and the bucket index is computed as (63 % 11 + 1 * (5 - 63 % 5)) % 11 = 10. Bucket 10 is occupied by item 55, so i is incremented to 2 and the bucket index is computed as (63 % 11 + 2 * (5 - 63 % 5)) % 11 = 1. Bucket 1 is empty, so Item 63 is inserted in this bucket.

A new hash table named playerNums with 10 buckets is created. A hash function maps an item's key to the bucket index.

A good hash function will distribute items into different buckets. Hash tables provide fast search, using as few as one comparison.

Each hash table array element is called a bucket.

A hash function computes a bucket index from the item's key.

A password hashing function produces a hash value for a password. The password hash function aims to produce a hash that cannot easily be converted back to the password.

Also, two different passwords should not produce the same hash value. Some password hashing functions concatenate extra random data to the password, then store the random data as well as the password hash value.

An implementation may choose to resize the hash table when one or more of the following values exceeds a certain threshold:

Load factor When using open-addressing, the number of collisions during an insertion When using chaining, the size of a bucket's linked-list

The approach for a hash table algorithm determining whether a cell is empty depends on the implementation. For example, if items are simply non-negative integers, empty can be represented as -1.

More commonly, items are each an object with multiple fields (name, age, etc.), in which case each hash table array element may be a pointer. Using pointers, empty can be represented as null.

Hash function: key % 40Key: 4-digit even numbersHash table size: 40

The remainder from dividing two even numbers is an even number. So, keys only map to even buckets. If keys have common factors or the expected keys are unknown, making N a prime number typically reduces collisions

When a hash table is initialized, all entries must be empty-after-removal

false- All entries must be initialized to empty-since-start.

Generating and storing random data alongside each password hash in a database, and using (password + random_data) to generate the hash value, can help increase security.

true-- If a different random value is generated for each password, an attacker will have a more difficult time trying to find an approach that will decrypt all passwords in the database.

A user could login with an incorrect password if a password hashing function produced the same hash value for two different passwords.

true-- If password verification involves comparing hash values, each password must have a distinct hash code. Otherwise, a user could potentially login with an incorrect password.

What is the result of applying the Caeser cipher with a left shift of 1 to the string "computer"?

"bnlotsdq" is the result of shifting "computer" left 1. 'c' is shifted to 'b', 'o' is shifted to 'n', and so on

A good hash function should uniformly distribute items into buckets. With chaining, a good hash function results in short bucket lists and thus fast inserts, searches, and removes. With linear probing, a good hash function will avoid hashing multiple items to consecutive buckets and thus minimize the average linear probing length to achieve fast inserts, searches, and removes. 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 function's performance depends on the hash table size and knowledge of the expected keys. Ex: The hash function key % 10 will perform poorly if the expected keys are all multiples of 10, because inserting 10, 20, 30, ..., 90, and 100 will all collide at bucket 0.

Using double hashing, a hash table search algorithm probes (or checks) each bucket using the probing sequence defined by the two hash functions. The search continues until either the matching item is found (returning the item), an empty-since-start bucket is found (returning null), or all buckets are probed without a match (returning null).

A hash table insert algorithm probes each bucket using the probing sequence, and inserts the item in the next empty bucket (the empty kind doesn't matter). A hash table removal algorithm first searches for the item's key. If the item is found, the item is removed, and the bucket is marked empty-after-removal.

The Caesar cipher shifts characters in the alphabet to encrypt a message. With a right shift of 4, the character 'N' is shifted to 'R'. The shift is applied to each character in the string, including spaces. The result is an encrypted message that hides the original message.

A left shift can also be used. Each message can be decrypted with the opposite shift.

A hash table resize operation increases the number of buckets, while preserving all existing items. A hash table with N buckets is commonly resized to the next prime number ≥ N * 2.

A new array is allocated, and all items from the old array are re-inserted into the new array, making the resize operation's time complexity O(N).

A hash table with linear probing handles a collision by starting at the key's mapped bucket, and then linearly searches subsequent buckets until an empty bucket is found.

During an insert, if a bucket is not empty, a collision occurs. Using linear probing, inserts will linearly probe buckets until an empty bucket is found. The item is inserted in the next empty bucket. Search starts at the hashed location and will compare each bucket until a match is found. If an empty bucket is found, search returns null, indicating a matching item was not found

Inserting a key uses the formula, starting with i = 0, to repeatedly search the hash table until an empty bucket is found.

Each time an empty bucket is not found, i is incremented by 1. Iterating through sequential i values to obtain the desired table index is called the probing sequence.

Hash function: key % 1000Key: Customer's 3-digit U.S. phone number area code, of which about 300 exist.Hash table size: 1000

Every key is ideally unique, but numerous customers may have the same area code. Also, less than a third of 1000 buckets will be used; the U.S. has only about 300 area codes

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

Ex: A hash table with 18 items and 31 buckets has a load factor of 18/31=0.58. The load factor may be used to decide when to resize the hash table.

A hash function can be used to produce a hash value for data in contexts other than inserting the data into a hash table. Such a function is commonly used for the purpose of verifying data integrity.

Ex: A hashing algorithm called MD5 produces a 128-bit hash value for any input data. The hash value cannot be used to reconstruct the original data, but can be used to help verify that data isn't corrupt and hasn't been altered.

The extracted middle bits depend on the maximum key.

Ex: A key with a value of 4000 requires 12 bits. A 12-bit number squared requires up to 24 bits. For R = 10, the middle 10 bits of the 24-bit squared key are bits 7 to 16.

n a hash table, an item's key is the value used to map to an index.

For all items that might possibly be stored in the hash table, every key is ideally unique, so that the hash table's algorithms can search for a specific item by that key.

Various techniques are used to handle collisions during insertions, such as chaining or open addressing.

Open addressing is a collision resolution technique where collisions are resolved by looking for an empty bucket elsewhere in the table (so 75 might be stored in bucket 6).

The remove algorithm uses the sought item's key to determine the initial bucket, probing buckets to find a matching item. If the matching item is found, the item is removed, and the bucket is marked empty-after-removal.

Remove algorithm probes each bucket until either the matching item or an empty-since-start bucket is found. If the matching item is found, the bucket is marked empty-after-removal.

A cryptographic hash function is a hash function designed specifically for cryptography.

Such a function is commonly used for encrypting and decrypting data.

Suppose the hash table below is resized. The hash function used both before and after resizing is: hash(key) = key % N, where N is the table size. How many elements are in the hash table after resizing?

The 4 existing elements are preserved during the resize

Cryptography is a field of study focused on transmitting data securely. Secure data transmission commonly starts with encryption: alteration of data to hide the original meaning.

The counterpart to encryption is decryption: reconstruction of original data from encrypted data.

A hash table with chaining will inevitably have large linked-lists after inserting many items.

The largest bucket length can be used as resizing criteria. Ex: The hash table is resized when a bucket length is >= 4

The search algorithm uses the probing sequence until the key being searched for is found or an empty-since-start bucket is found.

The removal algorithm searches for the key to remove and, if found, marks the bucket as empty-after-removal.

A hash table is fast if the hash function minimizes collisions. A perfect hash function maps items to buckets with no collisions. A perfect hash function can be created if the number of items and all possible item keys are known beforehand.

The runtime for insert, search, and remove is O(1) with a perfect hash function.

If computer B in the above example computed a hash value identical to the downloaded hash value, then the downloaded message would be guaranteed to be uncorrupted.

Two identical MD5 hash values imply a high likelihood that the data is uncorrupted, but not a guarantee. Different hash values, on the other hand, guarantee that the data is corrupted.

Suppose the hash table below is resized. The hash function used both before and after resizing is: hash(key) = key % N, where N is the table size.

What is the most likely allocated size for the resized hash table?- Resizing will use the next prime number >= 14, which is 17.

A password hashing function is a cryptographic hashing function that produces a hash value for a password. Databases for online services commonly store a user's password hash as opposed to the actual password.

When the user attempts a login, the supplied password is hashed, and the hash is compared against the database's hash value. Because the passwords are not stored, if a database with password hashes is breached, attackers may still have a difficult time determining a user's password.

Encryption and decryption are synonymous.

false-- Although the encryption and decryption processes can be similar, the two terms exist to distinguish between the process of altering the data into a 'hidden' form (encryption) and reconstructing back into a 'readable' form (decryption).

The Caeser cipher is an encryption algorithm that works well to secure data for modern digital communications.

false-- The Caeser cipher is very easy to decrypt, even by hand. Modern encryption algorithms are far more advanced and secure than the Caeser cipher.

Hash function: key % 1000Key: 6-digit employee IDHash table size: 20000

hash function and expected key not work well-- Numerous collisions are likely. The hash function only maps keys into the first 1000 buckets. A good hash function should uniformly distribute hashed keys across all buckets.

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

key- The key is usually a part of the item, such as a student object that has a name, age, and student ID number, with the ID number serving as the key.

How many direct access table buckets are needed for items with keys ranging from 100 to 200 (inclusive)?

201- 200 + 1 = 201. Buckets indices will be 0 to 200. The hash table size with direct hashing equals the largest key plus 1. Note that only buckets 100 to 200 will be used; buckets 0 to 99 will be unused.

For a 1000-entry direct access table, type the bucket number for the inserted item, or type: None. HashInsert(hashIndex, item 734)

734-- A direct hash function uses the item's key as the hash table bucket.

The insertion algorithm can only insert into empty-since-start buckets.

false- The insertion algorithm can insert into empty-since-start and empty-after-removal buckets. Whichever bucket is encountered first in the probing sequence will be used for the insertion.

In a hash table using chaining, the load factor cannot exceed 1.0.

false- The load factor is the number of items divided by the number of buckets. Multiple items can be placed in one bucket when using chaining. So the hash table could have more items than buckets, making the load factor > 1.0.

For a 1000-entry direct access table, type the bucket number for the inserted item, or type: None. HashInsert(hashIndex, item 1034)

none- 999 is the largest possible key value. An N-entry direct access table supports keys ranging from 0 to N-1

For a 1000-entry direct access table, type the bucket number for the inserted item, or type: None. HashInsert(hashIndex, item -45)

none- A negative number is not a valid array index. An N-entry direct access table supports keys ranging from 0 to N-1

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- In the worst case scenario, the 10 items are the only items in the table and are all added to the same bucket. The load factor, 10 / 101 = 0.099, is ≤ 0.1.

Double hashing would never resolve collisions if the second hash function always returned 0.

true- The index formula becomes (h1(key)+i∗0)mod(tablesize) when the second hashing function returns 0. Regardless of the value of i, the formula would always yield the same index.

When resizing to a larger size, the load factor is guaranteed to decrease

true- The load factor is computed as X / Y, where X is the number of items and Y the number of buckets. Resizing will not change X. When Y increases, the fraction X / Y decreases. Therefore, the load factor always decreases when resizing to a larger size.

The removal algorithm searches for the bucket containing the key to remove. If found, the bucket is marked as empty-after-removal.

true- The search algorithm is used by the remove algorithm to find the correct bucket. If found, the removal algorithm must mark the bucket as empty-after-removal.

Cryptography is used heavily in internet communications.

true-- Virtually all logins into internet accounts use encryption to securely transmit a username and password to a web server.

item 55

10- 55 % 11 = 0, but the bucket at index 0 already holds item 77. i is incremented to 1, and the bucket index is computed as (55 % 11 + 1 * (5 - 55 % 5)) % 11 = 5. Bucket 5 is occupied by item 16, so i is incremented to 2, and the bucket index is computed as (55 % 11 + 2 * (5 - 55 % 5)) % 11 = 10. Bucket 10 is empty, so Item 55 is inserted in this bucket.

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

10- key % 10 will yield a remainder of 0, 1, ..., or 9. Ex: 19 % 10 = 9, 20 % 10 = 0, and 21 % 10 = 1. A common mistake is to use key % 9, whose remainders can only be 0 to 8.

A class has 100 students. Student ID numbers range from 10000 to 99999. Using the ID number as key, how many buckets will a direct access table require?

100,000-- 99999 + 1 = 100000. The table size depends only on the largest key. As such, a direct access table is very inefficient for this application, since only 100 buckets would be used out of 100,000 total.

How many buckets will be checked for HashSearch(numsTable, 45)?

13.1.4: Hash table search efficiency.- Bucket 5 is checked first (45 % 10 = 5), and the matching item is found. Hash search may search only O(1) buckets.

A hash table's items will be positive integers, and -1 will represent empty. A 5-bucket hash table is: -1, -1, 72, 93, -1. How many items are in the table?

2- 72 and 93 are the stored items. The three -1's are empty buckets

For a decimal mid-square hash function, what is the bucket index for key = 112, N = 1000, and R = 3?

254- 112 * 112 = 12544. Middle 3 digits = 254. Then 254 % 1000 = 254. For a 1000 entry hash table, R must be greater than or equal to ⌈log101000⌉=3 to index all buckets. 3 digits can index all 1000 buckets at indices 0 to 999.

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

34- 334 % 100 = 34. The insert operation uses the hash function to determine the bucket index.

item 16

5- (16 % 11 + 0 * (5 - 16 % 5)) % 11 = 5. The bucket at index 5 is empty prior to the insertion of 16, so item 16 is stored at index 5.

If item keys range from 0 to 49, how many keys may map to the same bucket?

5- 5 keys will map into each bucket. Ex: 1, 11, 21, 31, and 41 will each map to bucket 1. A modulo hash function will map numkeys/num buckets keys to each bucket

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

50- key % 50 yields values from 0 to 49, which is 50 values (counting the 0).

If a linear search were applied to the array, how many array elements would be checked to find item 45?

6- Linear search will check elements 0, 1, 2, 3, 4, and 5, where item 45 will be found. On average, linear search requires O(N), compared to O(1) for hash tables.

For a decimal mid-square hash function, what are the middle digits for key = 40, N = 100, and R = 2?

60- 40 * 40 = 1600. Middle 2 digits = 60. The bucket index is 60 % 100 = 60.

For a binary mid-square hash function, how many bits are needed for an 80 entry hash table?

7- . The value of the middle 7 bits may range from 0 to 127, so the hash function returns the remainder of the middle bits divided by hash table size. r = log2(80) = 6.32 = 7

Suppose the hash table below is resized. The hash function used both before and after resizing is: hash(key) = key % N, where N is the table size. At what index does 99 reside in the resized table?

99 is rehashed using the new table size, and is inserted at index 99 % 17 = 14.

key % 1000 maps to indices 0 to ____

999- key % 1000 maps to 1000 indices numbered 0 to 999. (Common mistakes are to assume indices 0 to 1000, or 1 to 1000).

A direct hash function uses the item's key as the bucket index. Ex: If the key is 937, the index is 937.

A hash table with a direct hash function is called a direct access table. Given a key, a direct access table search algorithm returns the item at index key if the bucket is not empty, and returns null (indicating item not found) if empty.

The mid-square hash function is typically implemented using binary (base 2), and not decimal, because a binary implementation is faster. A decimal implementation requires converting the square of the key to a string, extracting a substring for the middle digits, and converting that substring to an integer. A binary implementation only requires a few shift and bitwise AND operations.

A binary mid-square hash function extracts the middle R bits, and returns the remainder of the middle bits divided by hash table size N, where R is greater than or equal to ⌈log2N⌉. Ex: For a hash table size of 200, R = 8, then 8 bits are needed for indices 0 to 199.

A hash table is a data structure that stores unordered items by mapping (or hashing) each item to a location in an array (or vector). Ex: 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 (25 % 10 = 5), and 149 to index 9 (149 % 10 = 9).

A hash table's main advantage is that searching (or inserting / removing) an item may require only O(1), in contrast to O(N) for searching a list or to O(log N) for binary search.

A common hash function uses the modulo operator %, which computes the integer remainder when dividing two numbers. Ex: For a 20 element hash table, a hash function of key % 20 will map keys to bucket indices 0 to 19

A hash table's operations of insert, remove, and search each use the hash function to determine an item's bucket. Ex: Inserting 113 first determines the bucket to be 113 % 10 = 3.

A direct access table has the advantage of no collisions: Each key is unique (by definition of a key), and each gets a unique bucket, so no collisions can occur. However, a direct access table has two main limitations

All keys must be non-negative integers, but for some applications keys may be negative. The hash table's size equals the largest key value plus 1, which may be very large.

Actually, linear probing distinguishes two types of empty buckets. An empty-since-start bucket has been empty since the hash table was created.

An empty-after-removal bucket had an item removed that caused the bucket to now be empty. The distinction will be important during searches, since searching only stops for empty-since-start, not for empty-after-removal.

Hash function: key % 250Key: 5-digit customer IDHash table size: 250

Assuming the IDs are well distributed, the hash function distributes keys into all hash table buckets.

Various techniques are used to handle collisions during insertions, such as chaining or open addressing.

Chaining is a collision resolution technique where each bucket has a list of items (so bucket 5's list would become 55, 75).

A collision occurs when an item being inserted into a hash table maps to the same bucket as an existing item in the hash table.

Ex: For a hash function of key % 10, 55 would be inserted in bucket 55 % 10 = 5; later inserting 75 would yield a collision because 75 % 10 is also 5.

Note that if the algorithm encounters an empty-after-removal bucket, the algorithm keeps probing, because the sought item may have been placed in a subsequent bucket before this bucket's item was removed.

Ex: Removing item 42 above would start at bucket 2. Because bucket 2 is empty-after-removal, the algorithm would proceed to bucket 3, where item 42 would be found and removed.

A mid-square hash squares the key, extracts R digits from the result's middle, and returns the remainder of the middle digits divided by hash table size N.

For a hash table with 100 entries and a key of 453, the decimal (base 10) mid-square hash function computes 453 * 453 = 205209, and returns the middle two digits 52. For N buckets, R must be greater than or equal to ⌈log10N⌉ to index all buckets. The process of squaring and extracting middle digits reduces the likelihood of keys mapping to just a few buckets.

A multiplicative string hash repeatedly multiplies the hash value and adds the ASCII (or Unicode) value of each character in the string. A multiplicative hash function for strings starts with a large initial value.

For each character, the hash function multiplies the current hash value by a multiplier (often prime) and adds the character's value. Finally, the function returns the remainder of the sum divided by the hash table size N.

Normally, each item being stored is an object with several fields, such as a person object having a name, age, and ID number, with the ID number used as the key.

For simplicity, this section represents an item just by the item's key. Ex: Item 64 represents a person object with a key of 64, which is the person's ID. HashInsert(hashTable, item 64) inserts item 64 in bucket 4, representing item 64 in the hash table just by the key 64.

A modulo hash uses the remainder from division of the key by hash table size N.

HashRemainder(int key) { return key % N }

The search algorithm uses the sought item's key to determine the initial bucket, and then linearly probes each bucket until a matching item is found. If search reaches the last bucket without finding a matching item or empty-since-start bucket, the search continues at bucket 0

If an empty-after-removal bucket is encountered, the algorithm continues to probe the next bucket. If an empty-since-start bucket is encountered, the search algorithm returns null.

In linear probing, a hash table search algorithm uses the sought item's key to determine the initial bucket. The algorithm probes each bucket until either the matching item is found (returning the item), an empty-since-start bucket is found (returning null), or all buckets are probed without a match (returning null).

If an empty-after-removal bucket is found, the search algorithm continues to probe the next bucket

A hash table with quadratic probing handles a collision by starting at the key's mapped bucket, and then quadratically searches subsequent buckets until an empty bucket is found.

If an item's mapped bucket is H, the formula (H+c1∗i+c2∗i2)mod(tablesize) is used to determine the item's index in the hash table. c1 and c2 are programmer-defined constants for quadratic probing.

Insert algorithm uses the item's key to determine the initial bucket. Insert linearly probes (or checks) each bucket until an empty bucket is found. Item is inserted into the next empty bucket.

If probing reaches the last bucket without finding an empty bucket, the probing continues at bucket 0. Insert linearly probes each bucket until an empty bucket is found.

Using linear probing, a hash table remove algorithm uses the sought item's key to determine the initial bucket. The algorithm probes each bucket until either a matching item is found, an empty-since-start bucket is found, or all buckets have been probed.

If the item is found, the item is removed, and the bucket is marked empty-after-removal

Using linear probing, a hash table insert algorithm uses the item's key to determine the initial bucket, linearly probes (or checks) each bucket, and inserts the item in the next empty bucket (the empty kind doesn't matter).

If the probing reaches the last bucket, the probing continues at bucket 0. The insert algorithm returns true if the item was inserted, and returns false if all buckets are occupied.

When inserting 55, no collision occurs with the first computed index of 5. Inserting 66 also does not cause a collision.

Inserting 25 causes a collision with the first computed index of 5. i is incremented to 1 and a new index of 7 is computed. Bucket 7 is empty and 25 is inserted.

Double hashing is an open-addressing collision resolution technique that uses 2 different hash functions to compute bucket indices. Using hash functions h1 and h2, a key's index in the table is computed with the formula (h1(key)+i∗h2(key))mod(tablesize).

Inserting a key uses the formula, starting with i = 0, to repeatedly search hash table buckets until an empty bucket is found. Each time an empty bucket is not found, i is incremented by 1. Iterating through sequential i values to obtain the desired table index is called the probing sequence

Hash function: key % 1000Key: Selling price of a house.Hash table size: 1000

Most house prices are rounded to the nearest 1000, as in $249,000. Thus, nearly all prices will map to bucket 0

For a well-designed hash table, searching requires _____ on average

O(1)- Hash tables support fast search, insert, and remove

A hash table with chaining uses a list for each bucket. The insert operation first uses the item's key to determine the mapped bucket, and then inserts the item in that bucket's list. A bucket may store multiple items with different keys that map to the same bucket. If collisions occur, items are inserted in the bucket's list.

Search first uses the item's key to determine the mapped bucket, and then searches the items in that bucket's list.

Chaining handles hash table collisions by using a list for each bucket, where each list may store multiple items that map to the same bucket. The insert operation first uses the item's key to determine the bucket, and then inserts the item in that bucket's list.

Searching also first determines the bucket, and then searches the bucket's list. Likewise for removes.

A 100 element hash table has 100 _____

buckets- Each hash table array element is called a bucket.

A company will store all employees in a hash table. Each employee item consists of a name, department, and employee ID number. Which is the most appropriate key?

employee ID- Keys should be unique; assumedly the company would assign a unique ID number to each employee.

Given hash function of key % 10, determine the bucket status after the following operations have been executed.HashInsert(valsTable, item 64)HashInsert(valsTable, item 20)HashInsert(valsTable, item 51)HashRemove(valsTable, 51). bucket 1?

empty-after-removal-- Item 51 was inserted in bucket 1, and then later removed.

Given hash function of key % 10, determine the bucket status after the following operations have been executed. HashInsert(valsTable, item 64)HashInsert(valsTable, item 20)HashInsert(valsTable, item 51)HashRemove(valsTable, 51). bucket 2?

empty-since-start--- Items 64, 20, and 51 do not map to index 2, so bucket 2 is still empty and has been since the hash table was created.

The search algorithm stops only when encountering a bucket containing the key being searched for.

false- Encountering a bucket with the key being searched for is not the only case that stops the search algorithm. Probing N buckets or encountering an empty-since-start bucket will also stop the search.

A hash table implementation must use only one criteria for resizing

false- Multiple criteria can be used together. Ex: Resizing could occur when either the load factor exceeds 0.5 or the number of items in a bucket exceeds 11

When the removal algorithm finds the bucket containing the key to be removed, the bucket is marked as empty-since-start

false- Removal must mark the bucket as empty-after-remova

Suppose a hash table has 101 buckets. If the hash table was using open addressing, a load factor > 0.9 guarantees a collision during insertion

false- Unless the load factor is 1.0, empty buckets exist in the table. So if 0.9 < load factor < 1.0, a key's hash may lead to an empty bucket, allowing insertion without collision.

A hash table has buckets 0 to 9 and uses a hash function of key % 10. If the table is initially empty and the following inserts are applied in the order shown, the insert of which item results in a collision?HashInsert(hashTable, item 55)HashInsert(hashTable, item 90)HashInsert(hashTable, item 95)

item 90- Item 55 mapped to 55 % 10 = 5, and item 90 to 90 % 10 = 0, so no collision occurs.

Given hash function of key % 10, determine the bucket status after the following operations have been executed.HashInsert(valsTable, item 64)HashInsert(valsTable, item 20)HashInsert(valsTable, item 51)HashRemove(valsTable, 51). bucket 4?

occupied--- Item 64 was inserted in bucket 4, and currently occupies the bucket.

If a message is encrypted with a left shift of X, what shift is needed to decrypt?

right shift of x--- The inverse shift decrypts the message. So if a message is encrypted with a left shift of X, a right shift of X will decrypt.

Given:hash1(key) = key % 11hash2(key) = 5 - key % 5and a hash table with a size of 11. Determine the index for each item after the following operations have been executed.HashInsert(valsTable, item 16)HashInsert(valsTable, item 77)HashInsert(valsTable, item 55)HashInsert(valsTable, item 41)HashInsert(valsTable, item 63)

see below


Kaugnay na mga set ng pag-aaral

Section 7: Changing, Replacing, and Renewing your Drivers license

View Set

Management Chapter 11 Organizational Control and Change.

View Set

Mastering Biology - 23.3-23.4 Review

View Set