EasyVery High Frequency20 min
Array Fundamentals
Memory layout, indexing, traversal techniques, and in-place modification patterns.
Arrays store elements in contiguous memory, giving O(1) random access by index. Every other operation — insert, delete, search — flows from this single property.
What is an Array?
Types of Arrays
Elements must all be the same type. The index always starts at 0.
Integer Arrayint[]
1
013
125
237
349
4Boolean Arrayboolean[]
T
0F
1F
2T
3T
4String ArrayString[]
abc
0efg
1uvw
2pqr
3xyz
4Dynamic Arrays
Operation Complexities at a Glance
Operation
Time
Note
Access by index
O(1)
Direct address formula — instant
Traversal
O(n)
Visit each element exactly once
Insert at end
O(1)*
Amortized; O(n) when capacity doubles
Insert at middle / start
O(n)
Must shift all elements after insertion point
Delete at end
O(1)
Just decrement the size pointer
Delete at middle / start
O(n)
Must shift all elements left to fill gap
Search — unsorted
O(n)
Must scan every element
Search — sorted
O(log n)
Binary search halves candidates each step
Operations — Step by Step
Access by Index
O(1)Constant time regardless of array sizeStep-by-step1 / 3
Array in memory
Five integers at consecutive addresses. Each cell shows its value; the number below is its index.