Question: a . Recall the dynamic array : You start with an array of size 1 . When the array is full, you allocate a new

a. Recall the dynamic array : You start with an array of size 1. When the array is full, you allocate a new one with the size being doubled, then copy all the items to it. We have shown that the amortized cost for each add/push is 3.
Consider now that allocating memory for \(\boldsymbol{k}\) positions costs \(\boldsymbol{k}\)(instead of 0). This means allocating a new array of size 2 n and copying n items to it would now cost 3 n . Does the amortized cost for each add/push still hold? What would be the new value for the amortized cost? Justify your answer.
b. Consider a stack implemented on an "infinite array", with no need to grow and shrink, and with push and pop operations, each one costing 1. Now we need to add another operation multipush (\( k \)), that pushes kelements to the stack. Would the amortized cost per operation still be constant? Justify your answer.
a . Recall the dynamic array : You start with an

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!