Question Bank

Amortized Analysis Quick Quiz

Difficulty: Easy

Short drills on amortized cost for dynamic arrays, hash table rehashing, and the aggregate method. Good for solidifying the gap between worst-case and average-case-per-operation.

Question Bank
/

Amortized Analysis Quick Quiz

Amortized Analysis Quick Quiz

Short drills on amortized cost for dynamic arrays, hash table rehashing, and the aggregate method. Good for solidifying the gap between worst-case and average-case-per-operation.

Question Bank
Easy
JavaScript
4 questions
amortized-analysis
big-o
quiz
fundamentals

813 views

14

Trace the pushes below. How many element copies happen in total across all 8 pushes when the underlying array doubles starting from capacity 1?

Examples

Example 1:

Input: finalSize = 8 (the underlying array doubles from capacity 1)
Output: 7
Explanation: Resizes happen at sizes 1, 2, 4, copying 1 + 2 + 4 = 7 elements in total.

Example 2:

Input: finalSize = 16
Output: 15
Explanation: Resizes happen at sizes 1, 2, 4, 8, copying 1 + 2 + 4 + 8 = 15 elements, still bounded by 2 * finalSize.