Amortized Analysis of Spreading and Gathering
Explore the amortized analysis of the _spread and _gather methods within SELists, learning how these methods impact the efficiency of add and remove operations. Understand how potential method helps measure performance, and discover how varying block sizes balance between ArrayList and DLList efficiencies for managing linked list data.
We'll cover the following...
Next, we consider the cost of the _gather(u) and _spread(u) methods that may be executed by the add(i, x) and remove(i) methods. For the sake of completeness, here they are:
The implementation of the _gather() method is:
Amortization
The running time of each of these methods is dominated by the two nested loops. Both the inner and outer loops execute at most times, so the total running time of each of these methods is . However, the following lemma shows that these methods execute on at most one out of every calls to add(i, x) or remove(i).
Lemma: If an empty SEList is created and any sequence of calls to add(i, x) and remove(i) is performed, then the total time spent during all calls to_ _spread() and _gather() is .
Proof: We will use the potential method of amortized analysis. We say that a node u is fragile if u’s block does not contain elements (so that u is either the last node, or contains ...