A test registry maps string keys to integer counts of available spaces. Apply the seven operations in the figure to an initially empty map, separately under each policy:
The key text inside each operation is the string supplied to the map. Under both policies, putting an equal existing key replaces its value; removing an absent key changes nothing.
For each policy, report the final number of entries and the sum of the stored space counts. Count a stored value once per entry, even when several entries have equal values. Give all four answers as integers, to zero decimal places.
Unlock full course notes by signing up
Zero seats or a missing key
A map of available seats initially contains K2 → 0 and M7 → 18. Keys use exact string equality, and stored values are nonnegative integers.
For this interface, get returns the stored value or the special marker absent. put stores the supplied value and returns the previous value, or absent for a new key. remove returns the removed value, or absent if the key was missing. containsKey returns true or false.
Complete the result column by applying the operations from top to bottom. Enter exact integers or the words true, false, or absent. Each row asks for the operation's returned result.
What the contract guarantees
Two software libraries implement the basic mutable Map ADT for the same key and value types, using the same key equality rule. Their documentation adds no ordering or running-time guarantees. Which statements are guaranteed by the Map ADT? Select all that apply.
Accumulating parcels by destination
A warehouse records batches of parcels sent to three destinations. An initially empty map, totals, associates each destination with its accumulated number of parcels.
For each batch, the program performs these operations in order:
Here, getOrDefault returns the stored value when the key exists and otherwise returns the supplied default without changing the map. put inserts an association or replaces its existing value.
Following employee-to-role-to-rate lookups
A repair company calculates labour charges using three maps. Employee identifiers are exact string keys, and every lookup needed below succeeds.
For each employee, the program looks up the employee's role, uses that role as a key in the rate map, and multiplies the resulting rate by the employee's recorded hours. The total labour charge is the sum across all four employees. Ignore taxes and additional fees.
Find both quantities below in USD, to two decimal places: