Data Structure

Array

A fixed-size, contiguous block of memory holding elements of the same type. Because every element is the same size, the address of any slot can be computed directly — that's what makes reads instant but insertion/deletion costly.

AccessO(1)
SearchO(n)
Insert / DeleteO(n)
MemoryContiguous

Try It — Animated Flow

14
82
37
56
91
20
Array access uses base + (index × size) to jump straight to the slot — no scanning.
Step 1 / 2
Pointer / current
Comparing
Swapping / removing
Newly inserted
Settled

Java Implementation

Real-Life Usage

Image pixel buffers
A bitmap is a 2D array of pixel values — every pixel is accessed by (x, y) index in O(1), which is why image processing is so fast.
Spreadsheets & grids
Rows and columns map directly to array indices, so jumping to any cell doesn't require scanning the sheet.
Leaderboards by rank
A fixed top-10 leaderboard is naturally an array — rank N is just index N-1, no traversal needed.
Fixed-size buffers
Audio sample buffers and lookup tables use arrays because their size is known ahead of time and speed of access matters most.

Trade-offs

Reach for an array when
  • The size is known up front, or rarely changes
  • You need fast random access by index
  • Cache-friendly, contiguous iteration matters
Avoid it when
  • You insert/delete from the middle frequently
  • The size is unpredictable and grows a lot
  • You need O(1) insert at both ends (use a Queue/Deque)