There is an algorithm called array doubling that is used to increase the size of an array to accommodate new data when an array fills up. In the algorithm, when an array fills up, a new array is created dynamically that is 2x the size of the original, the data is copied to the new array, and the old array is destroyed.
(a) write algorithm to implement an underflow strategy that cuts the array size in half whenever the array falls below half full.
(b) Specify the loop invariant in your algorithm.
(c) Explain how your algorithm maintains the loop invariant

Leave a Reply

Your email address will not be published. Required fields are marked *