A dynamic array contains 36 live measurement records. Each allocated slot occupies 16 bytes, including unused slots. An engineer compares three possible reserved capacities without changing the number of live records. Ignore storage outside the record buffer.
For each capacity, calculate the unused slots, the percentage of allocated buffer storage that is unused, and the total allocated buffer storage in bytes. Enter exact integers or terminating decimals, without units or percentage signs.
Unlock full course notes by signing up
Counting copied event identifiers
A logging program starts with an empty dynamic array of capacity 3 and appends 70 event identifiers. Whenever the block is full, a resize replaces it with a block of twice the capacity and copies every existing identifier once. Count only copies of existing identifiers, excluding writes of newly appended identifiers. How many identifier copies occur in total? Give your answer in copies, to zero decimal places.
Movement costs in an editing buffer
An editing program stores nine command identifiers in a dynamic array of capacity 16, using zero-based indexing. It first inserts a new identifier at index 3, preserving order, and then removes the identifier at index 6 of the resulting sequence, again preserving order. Capacity does not change.
Count one element write for each assignment that moves an existing identifier or stores the newly inserted identifier. Ignore reads, size updates, and clearing unused slots. Find the insertion's element writes, the removal's element writes, and the final size in elements. Give all three answers as integers, to zero decimal places.
When shrinking cancels the benefit of growth
A dynamic array doubles its capacity immediately before appending to a full block. After each deletion, if its new size equals half its current capacity, it halves that capacity. Each resize copies every remaining element, and capacity never falls below 8.
Initially its capacity, the number of allocated slots, is CCC, where CCC is a power of two and C≥32C\geq32C≥32. Its size is C/2+1C/2+1C/2+1. A program repeatedly deletes the last element and then appends one element. Count existing-element copies only. Which statements about each delete-and-append pair are true? Select all that apply.
A reservation that exceeds the peak memory budget
A telemetry program has a dynamic array containing 75 records in a buffer of capacity 96 slots. Each slot occupies 24 bytes. The program requests enough reserved capacity for 210 records in total; reserving storage does not change the current size.
The growth policy selects the smallest capacity in the sequence 96,192,384,…96,192,384,\ldots96,192,384,… that meets the request. It then attempts to allocate that replacement buffer directly, without allocating the intermediate capacities.
During replacement, the entire existing buffer remains allocated until copying finishes. The combined buffer-storage budget is 10000 bytes. Ignore allocator metadata and all other storage, and assume allocation succeeds whenever this budget permits it.