Chapter 3 · Simulation

Array Simulator

← Chapter 3
Ready.

Array Simulator

An array stores its elements in consecutive memory cells, so any element can be reached directly by its index. Inserting or deleting in the middle, however, forces every later element to shift.

How to use it

  • Size + Random Array fills the array with 1–12 random values; Shuffle and Clear act on the whole array.
  • With Index and Value: Get reads a cell, Set overwrites it, Insert shifts the elements right to make room, and Delete removes an element and shifts the rest left.
  • Linear Search, Traverse, Reverse and Bubble Sort are animated; Cancel stops the animation and restores the array.
  • Clicking a cell copies its index and value into the input boxes.

Costs

OperationTime
Get / setO(1)
Insert at / delete from index iO(n − i) shifts
Linear search, traversalO(n)
ReversalO(n), n/2 swaps
Bubble sortO(n²) comparisons

The counters along the bottom show how many comparisons and swaps/shifts the current operation has made.