Subsections


3.3 SEList: A Space-Efficient Linked List

One of the drawbacks of linked lists (besides the time it takes to access elements that are deep within the list) is their space usage. Each node in a DLList requires an additional two references to the next and previous nodes in the list. Two of the fields in a Node are dedicated to maintaining the list, and only one of the fields is for storing data!

An SEList (space-efficient list) reduces this wasted space using a simple idea: Rather than store individual elements in a DLList, we store a block (array) containing several items. More precisely, an SEList is parameterized by a block size $ \ensuremath{\ensuremath{\mathit{b}}}$. Each individual node in an SEList stores a block that can hold up to $ \ensuremath{\ensuremath{\mathit{b}}+1}$ elements.

For reasons that will become clear later, it will be helpful if we can do Deque operations on each block. The data structure that we choose for this is a BDeque (bounded deque), derived from the ArrayDeque structure described in Section 2.4. The BDeque differs from the ArrayDeque in one small way: When a new BDeque is created, the size of the backing array $ \ensuremath{\ensuremath{\mathit{a}}}$ is fixed at $ \ensuremath{\ensuremath{\mathit{b}}+1}$ and never grows or shrinks. The important property of a BDeque is that it allows for the addition or removal of elements at either the front or back in constant time. This will be useful as elements are shifted from one block to another.

An SEList is just a doubly-linked list of blocks. In addition to $ \ensuremath{\ensuremath{\mathit{next}}}$ and $ \ensuremath{\ensuremath{\mathit{prev}}}$ pointers, each node $ \ensuremath{\ensuremath{\mathit{u}}}$ in an SEList contains a BDeque, $ \ensuremath{\ensuremath{\mathit{u}}.\ensuremath{\mathit{d}}}$.

3.3.1 Space Requirements

An SEList places very tight restrictions on the number of elements in a block: Unless a block is the last block, then that block contains at least $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ and at most $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ elements. This means that, if an SEList contains $ \ensuremath{\ensuremath{\mathit{n}}}$ elements, then it has at most

$\displaystyle \ensuremath{\ensuremath{\ensuremath{\mathit{n}}}}/(\ensuremath{\e...
...h{\ensuremath{\mathit{n}}}}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})
$

blocks. The BDeque for each block contains an array of length $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ but, for every block except the last, at most a constant amount of space is wasted in this array. The remaining memory used by a block is also constant. This means that the wasted space in an SEList is only $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+\ensuremath{\ensuremath{\ensuremath{\mathit{n}}}}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$. By choosing a value of $ \ensuremath{\ensuremath{\mathit{b}}}$ within a constant factor of $ \sqrt{\ensuremath{\ensuremath{\ensuremath{\mathit{n}}}}}$, we can make the space-overhead of an SEList approach the $ \sqrt{\ensuremath{\ensuremath{\ensuremath{\mathit{n}}}}}$ lower bound given in Section 2.6.2.

3.3.2 Finding Elements

The first challenge we face with an SEList is finding the list item with a given index $ \ensuremath{\ensuremath{\mathit{i}}}$. Note that the location of an element consists of two parts:

  1. The node $ \ensuremath{\ensuremath{\mathit{u}}}$ that contains the block that contains the element with index $ \ensuremath{\ensuremath{\mathit{i}}}$; and
  2. the index $ \ensuremath{\ensuremath{\mathit{j}}}$ of the element within its block.

To find the block that contains a particular element, we proceed the same way as we do in a DLList. We either start at the front of the list and traverse in the forward direction, or at the back of the list and traverse backwards until we reach the node we want. The only difference is that, each time we move from one node to the next, we skip over a whole block of elements.


\begin{leftbar}
\begin{flushleft}
\hspace*{1em} \ensuremath{\mathrm{get\_locatio...
...nsuremath{\mathit{i}}-\ensuremath{\mathit{idx}}}\\
\end{flushleft}\end{leftbar}

Remember that, with the exception of at most one block, each block contains at least $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ elements, so each step in our search gets us $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ elements closer to the element we are looking for. If we are searching forward, this means that we reach the node we want after $ O(1+\ensuremath{\ensuremath{\ensuremath{\mathit{i}}}}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$ steps. If we search backwards, then we reach the node we want after $ O(1+(\ensuremath{\ensuremath{\ensuremath{\mathit{n}}}}-\ensuremath{\ensuremath{\ensuremath{\mathit{i}}}})/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$ steps. The algorithm takes the smaller of these two quantities depending on the value of $ \ensuremath{\ensuremath{\mathit{i}}}$, so the time to locate the item with index $ \ensuremath{\ensuremath{\mathit{i}}}$ is $ O(1+\min\{\ensuremath{\ensuremath{\ensuremath{\mathit{i}}}},\ensuremath{\ensur...
...{\ensuremath{\mathit{i}}}}\}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$.

Once we know how to locate the item with index $ \ensuremath{\ensuremath{\mathit{i}}}$, the $ \ensuremath{\mathrm{get}(\ensuremath{\mathit{i}})}$ and $ \ensuremath{\mathrm{set}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ operations translate into getting or setting a particular index in the correct block:


\begin{leftbar}
\begin{flushleft}
\hspace*{1em} \ensuremath{\mathrm{get}(\ensure...
...nsuremath{\mathit{j}}, \ensuremath{\mathit{x}})}\\
\end{flushleft}\end{leftbar}

The running times of these operations are dominated by the time it takes to locate the item, so they also run in $ O(1+\min\{\ensuremath{\ensuremath{\ensuremath{\mathit{i}}}},\ensuremath{\ensur...
...{\ensuremath{\mathit{i}}}}\}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$ time.

3.3.3 Adding an Element

Adding elements to an SEList is a little more complicated. Before considering the general case, we consider the easier operation, $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{x}})}$, in which $ \ensuremath{\ensuremath{\mathit{x}}}$ is added to the end of the list. If the last block is full (or does not exist because there are no blocks yet), then we first allocate a new block and append it to the list of blocks. Now that we are sure that the last block exists and is not full, we append $ \ensuremath{\ensuremath{\mathit{x}}}$ to the last block.


\begin{leftbar}
\begin{flushleft}
\hspace*{1em} \ensuremath{\mathrm{append}(\ens...
... \gets \ensuremath{\ensuremath{\mathit{n}} + 1}}\\
\end{flushleft}\end{leftbar}

Things get more complicated when we add to the interior of the list using $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$. We first locate $ \ensuremath{\ensuremath{\mathit{i}}}$ to get the node $ \ensuremath{\ensuremath{\mathit{u}}}$ whose block contains the $ \ensuremath{\ensuremath{\mathit{i}}}$th list item. The problem is that we want to insert $ \ensuremath{\ensuremath{\mathit{x}}}$ into $ \ensuremath{\ensuremath{\mathit{u}}}$'s block, but we have to be prepared for the case where $ \ensuremath{\ensuremath{\mathit{u}}}$'s block already contains $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ elements, so that it is full and there is no room for $ \ensuremath{\ensuremath{\mathit{x}}}$.

Let $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ensuremath{\ensuremath{\e...
...math{\mathit{u}}}}_1,\ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_2,\ldots$ denote $ \ensuremath{\ensuremath{\mathit{u}}}$, $ \ensuremath{\ensuremath{\mathit{u}}.\ensuremath{\mathit{next}}}$, $ \ensuremath{\ensuremath{\mathit{u}}.\ensuremath{\mathit{next}}.\ensuremath{\mathit{next}}}$, and so on. We explore $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ensuremath{\ensuremath{\e...
...math{\mathit{u}}}}_1,\ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_2,\ldots$ looking for a node that can provide space for $ \ensuremath{\ensuremath{\mathit{x}}}$. Three cases can occur during our space exploration (see Figure 3.4):

Figure 3.4: The three cases that occur during the addition of an item $ \ensuremath{\ensuremath{\mathit{x}}}$ in the interior of an SEList. (This SEList has block size $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}=3$.)
 \includegraphics[width=\textwidth ]{figs-python/selist-add-a}  
 \includegraphics[width=\textwidth ]{figs-python/selist-add-b}  
 \includegraphics[width=\textwidth ]{figs-python/selist-add-c}  

  1. We quickly (in $ r+1\le \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}$ steps) find a node $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$ whose block is not full. In this case, we perform $ r$ shifts of an element from one block into the next, so that the free space in $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$ becomes a free space in $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$. We can then insert $ \ensuremath{\ensuremath{\mathit{x}}}$ into $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$'s block.

  2. We quickly (in $ r+1\le \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}$ steps) run off the end of the list of blocks. In this case, we add a new empty block to the end of the list of blocks and proceed as in the first case.

  3. After $ \ensuremath{\ensuremath{\mathit{b}}}$ steps we do not find any block that is not full. In this case, $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ldots,\ensuremath{\ensure...
...\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1}$ is a sequence of $ \ensuremath{\ensuremath{\mathit{b}}}$ blocks that each contain $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ elements. We insert a new block $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}}$ at the end of this sequence and spread the original $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1)$ elements so that each block of $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ldots,\ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}}$ contains exactly $ \ensuremath{\ensuremath{\mathit{b}}}$ elements. Now $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$'s block contains only $ \ensuremath{\ensuremath{\mathit{b}}}$ elements so it has room for us to insert $ \ensuremath{\ensuremath{\mathit{x}}}$.


\begin{leftbar}
% latex2html id marker 14000\begin{flushleft}
\hspace*{1em} \e...
... \gets \ensuremath{\ensuremath{\mathit{n}} + 1}}\\
\end{flushleft}\end{leftbar}

The running time of the $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ operation depends on which of the three cases above occurs. Cases 1 and 2 involve examining and shifting elements through at most $ \ensuremath{\ensuremath{\mathit{b}}}$ blocks and take $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$ time. Case 3 involves calling the $ \ensuremath{\mathrm{spread}(\ensuremath{\mathit{u}})}$ method, which moves $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1)$ elements and takes $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}^2)$ time. If we ignore the cost of Case 3 (which we will account for later with amortization) this means that the total running time to locate $ \ensuremath{\ensuremath{\mathit{i}}}$ and perform the insertion of $ \ensuremath{\ensuremath{\mathit{x}}}$ is $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+\min\{\ensuremath{\ensurem...
...{\ensuremath{\mathit{i}}}}\}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$.

3.3.4 Removing an Element

Removing an element from an SEList is similar to adding an element. We first locate the node $ \ensuremath{\ensuremath{\mathit{u}}}$ that contains the element with index $ \ensuremath{\ensuremath{\mathit{i}}}$. Now, we have to be prepared for the case where we cannot remove an element from $ \ensuremath{\ensuremath{\mathit{u}}}$ without causing $ \ensuremath{\ensuremath{\mathit{u}}}$'s block to become smaller than $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$.

Again, let $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ensuremath{\ensuremath{\e...
...math{\mathit{u}}}}_1,\ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_2,\ldots$ denote $ \ensuremath{\ensuremath{\mathit{u}}}$, $ \ensuremath{\ensuremath{\mathit{u}}.\ensuremath{\mathit{next}}}$, $ \ensuremath{\ensuremath{\mathit{u}}.\ensuremath{\mathit{next}}.\ensuremath{\mathit{next}}}$, and so on. We examine $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ensuremath{\ensuremath{\e...
...math{\mathit{u}}}}_1,\ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_2,\ldots$ in order to look for a node from which we can borrow an element to make the size of $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$'s block at least $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$. There are three cases to consider (see Figure 3.5):

Figure 3.5: The three cases that occur during the removal of an item $ \ensuremath{\ensuremath{\mathit{x}}}$ in the interior of an SEList. (This SEList has block size $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}=3$.)
\includegraphics[scale=0.90909]{figs-python/selist-remove-a}
\includegraphics[scale=0.90909]{figs-python/selist-remove-b}
\includegraphics[scale=0.90909]{figs-python/selist-remove-c}

  1. We quickly (in $ r+1\le \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}$ steps) find a node whose block contains more than $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ elements. In this case, we perform $ r$ shifts of an element from one block into the previous one, so that the extra element in $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$ becomes an extra element in $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$. We can then remove the appropriate element from $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$'s block.

  2. We quickly (in $ r+1\le \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}$ steps) run off the end of the list of blocks. In this case, $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$ is the last block, and there is no need for $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$'s block to contain at least $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ elements. Therefore, we proceed as above, borrowing an element from $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$ to make an extra element in $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$. If this causes $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$'s block to become empty, then we remove it.

  3. After $ \ensuremath{\ensuremath{\mathit{b}}}$ steps, we do not find any block containing more than $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ elements. In this case, $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ldots,\ensuremath{\ensure...
...\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1}$ is a sequence of $ \ensuremath{\ensuremath{\mathit{b}}}$ blocks that each contain $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ elements. We gather these $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1)$ elements into $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ldots,\ensuremath{\ensure...
...\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-2}$ so that each of these $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ blocks contains exactly $ \ensuremath{\ensuremath{\mathit{b}}}$ elements and we remove $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1}$, which is now empty. Now $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$'s block contains $ \ensuremath{\ensuremath{\mathit{b}}}$ elements and we can then remove the appropriate element from it.


\begin{leftbar}
% latex2html id marker 14215\begin{flushleft}
\hspace*{1em} \e...
... \gets \ensuremath{\ensuremath{\mathit{n}} - 1}}\\
\end{flushleft}\end{leftbar}

Like the $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ operation, the running time of the $ \ensuremath{\mathrm{remove}(\ensuremath{\mathit{i}})}$ operation is $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+\min\{\ensuremath{\ensurem...
...{\ensuremath{\mathit{i}}}}\}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$ if we ignore the cost of the $ \ensuremath{\mathrm{gather}(\ensuremath{\mathit{u}})}$ method that occurs in Case 3.

3.3.5 Amortized Analysis of Spreading and Gathering

Next, we consider the cost of the $ \ensuremath{\mathrm{gather}(\ensuremath{\mathit{u}})}$ and $ \ensuremath{\mathrm{spread}(\ensuremath{\mathit{u}})}$ methods that may be executed by the $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ and $ \ensuremath{\mathrm{remove}(\ensuremath{\mathit{i}})}$ methods. For the sake of completeness, here they are:


\begin{leftbar}
\begin{flushleft}
\hspace*{1em} \ensuremath{\mathrm{spread}(\ens...
...\gets \ensuremath{\ensuremath{\mathit{w}}.prev}}\\
\end{flushleft}\end{leftbar}

\begin{leftbar}
\begin{flushleft}
\hspace*{1em} \ensuremath{\mathrm{gather}(\ens...
...{\mathrm{remove\_node}(\ensuremath{\mathit{w}})}\\
\end{flushleft}\end{leftbar}

The running time of each of these methods is dominated by the two nested loops. Both the inner and outer loops execute at most $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ times, so the total running time of each of these methods is $ O((\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1)^2)=O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}^2)$. However, the following lemma shows that these methods execute on at most one out of every $ \ensuremath{\ensuremath{\mathit{b}}}$ calls to $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ or $ \ensuremath{\mathrm{remove}(\ensuremath{\mathit{i}})}$.

Lemma 3..1   If an empty SEList is created and any sequence of $ m\ge 1$ calls to $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ and $ \ensuremath{\mathrm{remove}(\ensuremath{\mathit{i}})}$ is performed, then the total time spent during all calls to $ \ensuremath{\mathrm{spread}()}$ and $ \ensuremath{\mathrm{gather}()}$ is $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}m)$.

Proof. We will use the potential method of amortized analysis. We say that a node $ \ensuremath{\ensuremath{\mathit{u}}}$ is fragile if $ \ensuremath{\ensuremath{\mathit{u}}}$'s block does not contain $ \ensuremath{\ensuremath{\mathit{b}}}$ elements (so that $ \ensuremath{\ensuremath{\mathit{u}}}$ is either the last node, or contains $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ or $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ elements). Any node whose block contains $ \ensuremath{\ensuremath{\mathit{b}}}$ elements is rugged. Define the potential of an SEList as the number of fragile nodes it contains. We will consider only the $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ operation and its relation to the number of calls to $ \ensuremath{\mathrm{spread}(\ensuremath{\mathit{u}})}$. The analysis of $ \ensuremath{\mathrm{remove}(\ensuremath{\mathit{i}})}$ and $ \ensuremath{\mathrm{gather}(\ensuremath{\mathit{u}})}$ is identical.

Notice that, if Case 1 occurs during the $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ method, then only one node, $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$ has the size of its block changed. Therefore, at most one node, namely $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_r$, goes from being rugged to being fragile. If Case 2 occurs, then a new node is created, and this node is fragile, but no other node changes size, so the number of fragile nodes increases by one. Thus, in either Case 1 or Case 2 the potential of the SEList increases by at most one.

Finally, if Case 3 occurs, it is because $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0,\ldots,\ensuremath{\ensure...
...\ensuremath{\mathit{u}}}}_{\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1}$ are all fragile nodes. Then $ \ensuremath{\ensuremath{spread}(}u_0\ensuremath{)}$ is called and these $ \ensuremath{\ensuremath{\mathit{b}}}$ fragile nodes are replaced with $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}+1$ rugged nodes. Finally, $ \ensuremath{\ensuremath{\mathit{x}}}$ is added to $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$'s block, making $ \ensuremath{\ensuremath{\ensuremath{\mathit{u}}}}_0$ fragile. In total the potential decreases by $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$.

In summary, the potential starts at 0 (there are no nodes in the list). Each time Case 1 or Case 2 occurs, the potential increases by at most 1. Each time Case 3 occurs, the potential decreases by $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$. The potential (which counts the number of fragile nodes) is never less than 0. We conclude that, for every occurrence of Case 3, there are at least $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}-1$ occurrences of Case 1 or Case 2. Thus, for every call to $ \ensuremath{\mathrm{spread}(\ensuremath{\mathit{u}})}$ there are at least $ \ensuremath{\ensuremath{\mathit{b}}}$ calls to $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$. This completes the proof. $ \qedsymbol$

3.3.6 Summary

The following theorem summarizes the performance of the SEList data structure:

Theorem 3..3   An SEList implements the List interface. Ignoring the cost of calls to $ \ensuremath{\mathrm{spread}(\ensuremath{\mathit{u}})}$ and $ \ensuremath{\mathrm{gather}(\ensuremath{\mathit{u}})}$, an SEList with block size $ \ensuremath{\ensuremath{\mathit{b}}}$ supports the operations Furthermore, beginning with an empty SEList, any sequence of $ m$ $ \ensuremath{\mathrm{add}(\ensuremath{\mathit{i}},\ensuremath{\mathit{x}})}$ and $ \ensuremath{\mathrm{remove}(\ensuremath{\mathit{i}})}$ operations results in a total of $ O(\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}m)$ time spent during all calls to $ \ensuremath{\mathrm{spread}(\ensuremath{\mathit{u}})}$ and $ \ensuremath{\mathrm{gather}(\ensuremath{\mathit{u}})}$.

The space (measured in words)3.1 used by an SEList that stores $ \ensuremath{\ensuremath{\mathit{n}}}$ elements is $ \ensuremath{\ensuremath{\ensuremath{\mathit{n}}}} +O(\ensuremath{\ensuremath{\...
...th{\ensuremath{\mathit{n}}}}/\ensuremath{\ensuremath{\ensuremath{\mathit{b}}}})$.

The SEList is a trade-off between an ArrayList and a DLList where the relative mix of these two structures depends on the block size $ \ensuremath{\ensuremath{\mathit{b}}}$. At the extreme $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}=2$, each SEList node stores at most three values, which is not much different than a DLList. At the other extreme, $ \ensuremath{\ensuremath{\ensuremath{\mathit{b}}}}>\ensuremath{\ensuremath{\ensuremath{\mathit{n}}}}$, all the elements are stored in a single array, just like in an ArrayList. In between these two extremes lies a trade-off between the time it takes to add or remove a list item and the time it takes to locate a particular list item.



Footnotes

... words)3.1
Recall Section 1.4 for a discussion of how memory is measured.
opendatastructures.org