Skip to main content

Arrays

Arrays are contiguous blocks of memory that store elements of the same type.

Implementation

# Initialize an array
arr = [1, 2, 3, 4, 5]

# Access element
first = arr[0]

# Modify element
arr[0] = 10

# Add element to end
arr.append(6)

# Remove last element
arr.pop()

Operations

OperationTime ComplexitySpace Complexity
AccessO(1)O(1)O(1)O(1)
SearchO(n)O(n)O(1)O(1)
InsertO(n)O(n)O(1)O(1)
DeleteO(n)O(n)O(1)O(1)
SortO(nlogn)O(n \log n)O(1)O(1)