When an array becomes full, you can double its size or use one of the schemes described in Exercises 1 and 2. What are the advantages and disadvantages of each of these three schemes?
Exercise 1
Suppose that instead of doubling the size of an array-based stack when it becomes full, you just increase the size of the array by some positive constant k.
a. If you have an empty stack that uses an array whose initial size is k, and you perform n pushes, how many resize operations will be performed? Assume that n > k.
b. What is the average cost of the n push operations?
Exercise 2
Suppose that instead of doubling the size of an array-based stack when it becomes full, you increase the size of the array by the following sequence 3k, 5k, 7k, 9k, ... for some positive constant k.
a. If you have an empty stack that uses an array whose initial size is k, and you perform n pushes, how many resize operations will be performed? Assume that n > k.
b. What is the average cost of the n push operations?
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.