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?
- A. 33
- B. 64
- C. 63
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A stack-based checker is run on four strings. Which one is balanced?
- A circular queue in an array of size 6 uses front (index of the first item) and rear (index of the next free slot), both starting at 0…
- A 2-D array A[10][20] (indices from 0) of 4-byte integers is stored in COLUMN-major order starting at address 1000. What is the address of…
- Only the lower triangle (including the diagonal) of a 10 × 10 matrix is stored, row by row, in a 1-D array starting at address 2000, with…
- What is printed? (Python) python a = [3, 8, 1, 9, 4] a.insert(2, 7) a.pop() a.remove(9) print(a, len(a))
- A circular queue of size N = 5 keeps one slot empty. What is printed (dequeued values, 'F' for each rejected enqueue, final count)? c…