Close
Register
Close Window

BM40A1500 Data Structures and Algorithms

Chapter 2 Linear Data Structures

Show Source |    | About   «  2.1. The List ADT   ::   Contents   ::   2.3. Linked Lists  »

2.2. Array-Based List Implementation

2.2.1. Insert

Because the array-based list implementation is defined to store list elements in contiguous cells of the array, the insert, append, and remove methods must maintain this property.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

2.2.2. Append and Remove

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Removing an element from the head of the list is similar to insert in that all remaining elements must shift toward the head by one position to fill in the gap. If we want to remove the element at position \(i\), then \(n - i - 1\) elements must shift toward the head, as shown in the following slideshow.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

In the average case, insertion or removal each requires moving half of the elements, which is \(\Theta(n)\).

Aside from insert and remove, the only other operations that might require more than constant time are the constructor and clear. The other methods for Class List simply access the current list element or move the current position. They all require \(\Theta(1)\) time.

   «  2.1. The List ADT   ::   Contents   ::   2.3. Linked Lists  »

nsf
Close Window