GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A dynamic array has capacity 1 initially. An append to a full array doubles the capacity (copying all n current elements); after a deletion, if the size is at most a quarter of the capacity (and the capacity exceeds 1), the capacity is halved (copying all n elements). The operation sequence is 9 appends followed by 10 repetitions of (delete, append). How many element copies are made in total?
- A. 8
- B. 23
- C. 15
- D. 175
Correct answer: C. 15
The 9 appends cost 1 + 2 + 4 + 8 = 15 copies (at sizes 1, 2, 4, 8). The size then oscillates between 9 and 8 with capacity 16, far above the quarter threshold, so there are no further copies. Shrinking at half capacity would cause a copy on almost every operation (175 here).
More Algorithms questions
- A 4-input comparator network applies, in order, the comparators (0,1), (2,3), (0,2), (1,3), (1,2), each putting the smaller value on the…
- How many comparators does Batcher's bitonic sorting network for 16 inputs use?
- Which is the tight solution of T(n) = 3T(n/4) + n^(log₄3)·log₂ n?
- Solve T(n) = 2T(√n) + log₂ n for large n. Which is the tight bound?
- Let T(n) = T(n − ⌊√n⌋) + 1 for n > 1 and T(1) = 0. Which is the tight bound?
- Let T(n) = T(n/2) + n(2 − cos n) (n in radians) with T(1) = 1. Which statement about T(n) is correct?