Arrays
Contiguous memory, index access, and resize costs.
What you will learn
- O(1) index access
- Understand fixed vs dynamic arrays
- Know when cache locality helps
An array stores elements in contiguous memory. Access by index is O(1). Inserting in the middle is O(n) because elements shift.
python
nums = [10, 20, 30, 40]
print(nums[2]) # O(1) access
nums.insert(1, 15) # O(n) insertTry it yourself
Given an array, write a function to reverse it in-place.
