A dynamic array has a capacity (the number of elements it can currently hold) and a size (the number of elements it actually holds). Consider a dynamic array where we always want the capacity to be a Fibonacci number. Suppose that its current capacity is Fk. We will use the following strategy: • If, after inserting an element, the size reaches Fk-1, we will make an array with capacity Fk+1 and copy our current array there. • If, after deleting an element, the size reaches Fk-3, we will make an array with capacity Fk-1 and copy our current array there. If the array is initially empty and its capacity is 2 = F2, show for every sequence of operations, add and delete will happen in the amortized run-time is O(1), even with the array copying going on in the background. Explanation needed .. code is not required
A dynamic array has a capacity (the number of elements it can currently hold) and a size (the number of elements it actually holds). Consider a dynamic array where we always want the capacity to be a Fibonacci number. Suppose that its current capacity is Fk. We will use the following strategy:
• If, after inserting an element, the size reaches Fk-1, we will make an array with capacity Fk+1 and copy our current array there.
• If, after deleting an element, the size reaches Fk-3, we will make an array with capacity Fk-1 and copy our current array there.
If the array is initially empty and its capacity is 2 = F2, show for every sequence of operations, add and delete will happen in the amortized run-time is O(1), even with the array copying going on in the background.
Explanation needed .. code is not required
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 11 images