Question: 4. (This is Exercise 3-3 from the textbook.) We have seen how dynamic arrays enable arrays to grow while still achieving constant time amortized performance.
4. (This is Exercise 3-3 from the textbook.) We have seen how dynamic arrays enable arrays to grow while still achieving constant time amortized performance. This problem concerns extending dynamic arrays to let them both grow and shrink as items are added and removed over time. a) Consider an "underflow" strategy that cuts the array size in half whenever the number of items falls below half of the length of the array. Give an example sequence of insertions and deletions where this strategy gives a bad amortized cost. b) Then give a better underflow strategy than the one suggested in part a). Your strategy should be one that achieves constant amortized cost per deletion
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
