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.


An eight-bucket hash table stores five asset records in lists attached to buckets one, three, and five.


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


C=1+1=2.C = 1 + 1 = 2.


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 nn be the entry count and mm the bucket count:


α=nm.\alpha = \frac{n}{m}.


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.


α=68=0.750.\alpha = \frac{6}{8} = 0.750.


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 ________.


αnew=616=0.375.\alpha_{\text{new}} = \frac{6}{16} = 0.375.


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.

An inventory hash table assigns asset IDs 264 and 183 to bucket 4. That bucket stores key 264 with quantity 7, followed by key 183 with quantity 12. Which rule correctly retrieves the quantity associated with asset ID 183?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

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.

Match each term
A.

The number of addressable locations in the backing array.

B.

One stored record consisting of a key and its associated value.

C.

A location in the backing array that holds a list of stored records.

D.

Two distinct keys being assigned to the same array location.

Collision

Capacity

Bucket

Entry

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

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.

TableBucketsEntriesNonempty bucketsLoad factor
A1066
B1062
C10125

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice