Data Structures · Visualization

Array: Introduction

Array

An array is a collection of items stored in one continuous block of memory, one right after another. Time: O(1) to read/update by index, O(n) to search by value. Space: O(n).

Big-O: Random access O(1); insert/delete in the middle O(n).

Array: Introduction

Array

An array is a collection of items stored in one continuous block of memory, one right after another. Because every item sits at a known distance from the start, the computer can jump straight to any position using its index instead of searching for it. Indexing usually starts at 0, so the first item is at index 0, the second at index 1, and so on.

How Array: Introduction Works

  1. Reserve a block of memory big enough to hold all the elements.
  2. Store each element in order, side by side, with no gaps.
  3. Give each element an index based on its position, starting at 0.
  4. To read a value, calculate its memory location directly from the index (no searching needed).

Array: Introduction Worked Example

Input: Create an array of 4 exam scores: [88, 92, 75, 100]

  1. score[0] = 88
  2. score[1] = 92
  3. score[2] = 75
  4. score[3] = 100
  5. Accessing score[2] jumps directly to the 3rd slot and returns 75.

Output: score = [88, 92, 75, 100], score[2] = 75

📖 Introduction: this is an overview of the topic, so there's nothing to run here. Pick an operation from the side menu to see a live, step-by-step animation.
Array: Introduction
A first look at how values sit side-by-side in memory, each one reachable directly by its index.
88
0
92
1
75
2
100
3
Active / shifting Result
Array: Introduction
Press ▶ Run to watch it step by step.
Python · Arrays in Code
# Array: contiguous, indexable storage
arr = [88, 92, 75, 100]

# Random access is O(1)
print(arr[2])              # 8

for v in arr:              # iterate O(n)
    print(v, end=" ")
# example: intro on [88, 92, 75, 100]

Array: Introduction Time & Space Complexity

TimeO(1) to read/update by index, O(n) to search by value
SpaceO(n)

When to Use Array: Introduction

  • Storing a fixed or predictable list of items, like days of the week
  • Building the underlying storage for other structures (stacks, heaps, hash tables)
  • Any time you need fast, index-based access to elements
  • Image pixels, matrices, and lookup tables

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.