ReviseAlgo Logo
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
0
13
1
25
2
37
3
49
4
Boolean Arrayboolean[]
T
0
F
1
F
2
T
3
T
4
String ArrayString[]
abc
0
efg
1
uvw
2
pqr
3
xyz
4

Dynamic 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 size
Step-by-step1 / 3
marker
10
0
marker
30
1
marker
50
2
marker
70
3
marker
90
4

Array in memory

Five integers at consecutive addresses. Each cell shows its value; the number below is its index.