Data Structures & AlgorithmsHardProduct-company MCQ pattern

A dynamic array starts with capacity 1 and doubles its capacity (copying all current elements) whenever an insert finds it full. How many element copies happen in total while inserting 33 elements?

  1. A. 33
  2. B. 64
  3. C. 63
  4. D. 32

Correct answer: C. 63

Resizes happen when inserting the 2nd, 3rd, 5th, 9th, 17th and 33rd elements, copying 1 + 2 + 4 + 8 + 16 + 32 = 63 elements, under 2n: O(1) amortised per insert. 32 counts only the last resize.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic