Example: Managing an Equipment-Room Inventory
Example: An equipment room uses a hash table, a structure that uses each record's key to select an indexed bucket. Asset IDs are keys, and quantities are stored values. This table has eight buckets, numbered 0 through 7. Each bucket holds a list, searched from left to right. A collision is handled here by keeping both records in that bucket's list.
The diagram shows the initial five records. Bucket assignments for new keys are supplied below; you do not need to construct a hash function.
a) Search for an absent asset
Asset ID 777 is assigned to bucket 3. Determine whether it is stored and count the comparisons with stored keys. Do not count the calculation of the bucket index.
Start at bucket 3. The first stored key you compare is ________. Since 777 and 635 are different, continue to the next record.
The next stored key is ________, which also differs from 777. The list then ends. No record matches the requested key, so the lookup reports that asset ID 777 is absent.
The number of key comparisons is
The final search cost is 2 key comparisons. Records in other buckets are not searched because the table's bucket assignment directs this key to bucket 3.
b) Insert a record and check capacity
Insert a new record for asset ID 846 with quantity 18. Its assigned bucket is 1, and it is appended after the existing record. Calculate the resulting load factor to three decimal places. The inventory system resizes only when the load factor exceeds 0.750; decide whether this insertion triggers resizing.
The load factor is the number of stored entries divided by the number of buckets. Let n be the entry count and m the bucket count:
The new asset ID is distinct, so insertion increases the entry count from five to ________. The bucket count remains ________ because appending a record to a bucket's list does not create a new bucket.
The resulting load factor is 0.750. Resizing requires the load factor to exceed 0.750, so equality does not trigger it. This insertion therefore does not trigger resizing.
Only three buckets are nonempty, but using three as the numerator would calculate the fraction of occupied buckets rather than the load factor.
c) Rebuild with more buckets
For a later capacity upgrade, the same six records are moved into a new table with 16 buckets. Calculate the new load factor to three decimal places. Explain why copying each list to its old bucket index is not a generally valid rebuilding procedure.
The upgrade changes capacity but adds no records. The numerator remains six, and the new bucket count is ________.
The new load factor is 0.375. Doubling the bucket count while holding the entry count fixed halves the load factor.
To rebuild correctly, determine each record's destination using the bucket-assignment rule for the new table size, then place the record there. A changed bucket count can change a key's destination, so its old index is not sufficient evidence of its new location. Some records may keep their old indices, but that must follow from the new assignments rather than being assumed.
A library catalogue uses a hash table whose array locations each hold a list of stored key-value records. Match each structural term to its description in this implementation.
The number of addressable locations in the backing array.
One stored record consisting of a key and its associated value.
A location in the backing array that holds a list of stored records.
Two distinct keys being assigned to the same array location.
Collision
Capacity
Bucket
Entry
Three inventory hash tables store distinct asset records in bucket lists, so a bucket may contain several records. Complete the load-factor column using the supplied counts. Enter exact decimals without units.
| Table | Buckets | Entries | Nonempty buckets | Load factor |
| A | 10 | 6 | 6 | |
| B | 10 | 6 | 2 | |
| C | 10 | 12 | 5 |