An array stores elements of the same type in contiguous memory, enabling O(1) random access by index.
| Operation | Time |
|---|---|
| Access | O(1) |
| Insert / Delete at end | O(1) |
| Insert / Delete in middle | O(n) — shifting elements |
Python's list is a dynamic array that grows automatically.
# Create
nums = [10, 20, 30]
# Access & modify
nums[0], nums[-1] # first & last
nums[1] = 25 # update
# Common operations
nums.sort(); nums.reverse()
max(nums); min(nums); sum(nums)
# Dynamic resizing
nums.append(40) # O(1) amortized
nums.pop() # O(1)
nums.remove(20) # O(n)