GATE Computer ScienceHardGATE CS (PYQ pattern)

A dynamic array starts with capacity 2. When it is full and an element is appended, the capacity becomes ⌈1.5 × capacity⌉ and all current elements are copied. After 1000 appends, how many element copies have been made in total?

  1. A. 2047
  2. B. 2119
  3. C. 1065
  4. D. 1999

Correct answer: B. 2119

The capacities run 2, 3, 5, 8, 12, 18, 27, 41, 62, 93, 140, 210, 315, 473, 710, 1065; each full buffer copies its capacity, so copies = 2 + 3 + … + 710 = 2119. The final capacity 1065 is not the copy count.

More Algorithms questions

Exams that ask this topic