GATE Computer ScienceHardGATE CS (PYQ pattern)

A dynamic array starts with capacity 4. When an append finds it full, it allocates capacity c + c / 2 (integer division), copies every existing element and then appends. After 100 appends, how many element copies have been made in total, and what is the capacity?

  1. A. 124 copies, capacity 128
  2. B. 182 copies, capacity 141
  3. C. 278 copies, capacity 211
  4. D. 278 copies, capacity 141

Correct answer: D. 278 copies, capacity 141

Capacities go 4, 6, 9, 13, 19, 28, 42, 63, 94, 141. A resize happens each time the size reaches the current capacity below 100, copying that many elements: 4 + 6 + 9 + 13 + 19 + 28 + 42 + 63 + 94 = 278, ending at capacity 141. Doubling instead would give 124 copies and capacity 128.

More Programming and Data Structures (GATE) questions

Exams that ask this topic