Abstract
An Array List (often called a Vector) is a dynamically resizing array where no empty slots are present between elements. Users can only insert elements at contiguous indices between and inclusive (where represents the total element count), optimizing the structure for high-speed constant-time index lookups.
- Category: Bounded Contiguous Structures
- Backbone Layout: Contiguous blocks of homogeneous computer memory.
- Key Advantage: Constant-time data location arithmetic using raw offsets.
Properties of a Backing Array
An array is a homogeneous data structure where each element is stored in adjacent memory locations. Homogeneous means all elements are of the exact same data type (e.g., int, double) and share an identical byte size .
Random Access Arithmetic
Because each cell shares the same size and layout blocks are perfectly contiguous in hardware memory, the system calculates the location of any element in constant time given the starting base address :
Memory Address Calculation Example
Suppose an array of integers () is initialized at base address in decimal memory. The physical start address of cell under 0-based indexing is:
Handling Variable Data
If array structures require all elements to be the exact same size, how can they contain strings of varying lengths?
- Answer: The array does not store the string characters directly. Instead, it stores a fixed-size pointer indicating the independent external memory address containing that unique string data.
Dynamic Capacity Resizing
When initializing an Array List with an unknown number of total elements, the structure manages memory allocation via a dynamic growth loop:
- Allocates a default “large” capacity array in memory initially.
- Inserts elements into this backing array while tracking the count .
- Once equals the array length capacity, it allocates a new backing array of double size ().
- Copies all elements from the old array into the new array sequentially, updates the reference, and frees the old space.
Algorithmic Operations
Insert(element, index)
Inserts an item at a specific target index. If adding to the front, all existing elements must slide forward to open a space.
- Time Complexity: Amortized Best Case (appending to the back); Worst Case (inserting at index 0 or triggering an internal array resize).
Algorithm 10 Array List Insertion
procedure Insert()
if or then
return
if then
for do
if then
else
for do
return
Find(element)
Performs a linear scan from index 0 across the structure to match the target element.
- Time Complexity: Best Case (first slot match); Worst Case (item missing or sitting in the final slot).
- Optimization: If the underlying array is maintained in a sorted sequence, search speeds improve to using Binary Search.
Algorithm 11 Linear Array Search
procedure Find()
for do
if then
return
return
Remove(index)
Removes an entry at a given index and shifts all trailing elements left by one index to avoid leaving structural gaps.
- Time Complexity: Best Case (deleting the last item); Worst Case (deleting from index 0).
Algorithm 12 Array List Removal
procedure Remove()
if or then
return
if then
for do
return
Performance Summary
- Random Access: constant time lookup.
- Search Complexity: if sorted via Binary Search; if unsorted.
- Insert/Delete Mechanics: general cost due to sequential cell shifting.
- Memory Footprint: Continuous block safety; can trade off potential memory overhead if pre-allocated block capacity goes unused.
- Optimal Environment: Fixed-size contexts or architectures dominated by index lookups.
- Weakest Environment: Systems tracking heavy insertion or removal routines targeted at the front of the sequence.