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?
- A. 2047
- B. 2119
- C. 1065
- 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
- Consider t(n): if n ≤ 2 return 1; else return t(n−1) + t(n−2) + t(n−3). How many calls to t (including the initial call) are made when…
- How many times is x++ executed? for (i = 2; i <= 100; i++) for (j = ii; j <= 100; j += i) x++;
- How many times is x++ executed? for (i = 1; i <= 1000; i = 2) for (j = i; j >= 1; j /= 3) x++; (integer division)
- Let f(n) = (log₂ n)^(log₂ n), g(n) = n^(log₂ log₂ n) and h(n) = (log₂ log₂ n)!. Which of the following is correct? I. f(n) = Θ(g(n)). II…
- Let f₁ = n^(1/log₂n), f₂ = (log₂ n)³, f₃ = (log₂ n)^(log₂ log₂ n), f₄ = 2^√(log₂ n), f₅ = n^0.001. Which lists them in increasing order of…
- In the median-of-medians selection algorithm the input is split into groups of g elements (g odd), giving the standard recurrence T(n) ≤…