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:

  1. Allocates a default “large” capacity array in memory initially.
  2. Inserts elements into this backing array while tracking the count .
  3. Once equals the array length capacity, it allocates a new backing array of double size ().
  4. 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(element,index,array,nelement, index, array, n)

if index<0index < 0 or index>nindex > n then

return false\text{false}

if n==array.lengthn == array.\text{length} then

newArrayAllocate empty array of length 2array.lengthnewArray \gets \text{Allocate empty array of length } 2 \cdot array.\text{length}

for i0 to n1i \gets 0 \text{ to } n - 1 do

newArray[i]array[i]newArray[i] \gets array[i]

arraynewArrayarray \gets newArray

if index==nindex == n then

array[index]elementarray[index] \gets element

else

for in1 down to indexi \gets n - 1 \text{ down to } index do

array[i+1]array[i]array[i + 1] \gets array[i]

array[index]elementarray[index] \gets element

nn+1n \gets n + 1

return true\text{true}

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(element,array,nelement, array, n)

for i0 to n1i \gets 0 \text{ to } n - 1 do

if array[i]==elementarray[i] == element then

return true\text{true}

return false\text{false}

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(index,array,nindex, array, n)

if index<0index < 0 or indexnindex \ge n then

return false\text{false}

if index<n1index < n - 1 then

for iindex to n2i \gets index \text{ to } n - 2 do

array[i]array[i+1]array[i] \gets array[i + 1]

nn1n \gets n - 1

return true\text{true}


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.

Related Notes