COMPILED CANVAS
DSA IN JAVA

1 step or 1 million?

Reading the last box of a huge array takes 1 step

Tap to start →

READ

arr[i] is instant

38519

Java jumps straight to the box. O(1), like a locker number.

1 of 4 · keep tapping →
SEARCH

Box by box

38519

In an unsorted array you check one by one. O(n).

2 of 4 · keep tapping →
INSERT

Everything shifts

✗ Add at end: O(1)
✓ Add at front: O(n)

Adding at the front moves every value one seat right. O(n).

3 of 4 · keep tapping →
REVERSE

Two pointers

int i = 0, j = n - 1; while (i < j) swap(arr, i++, j--);

Swap the two ends and move inwards. No extra array.

4 of 4 · keep tapping →
⚠ MOST PEOPLE MISS THIS

The mistake

Indexes start at 0. An array of 10 boxes ends at index 9.

QUICK QUIZ

Can you get it?

Tap an answer. The full video explains why.

📸 SCREENSHOT THIS

Cheat sheet

  • arr[i]: O(1)
  • Loop / search: O(n)
  • Add at end: O(1)
  • Add at front: O(n)
  • Reverse: two pointers, O(1) space
COMPILED CANVAS

Want the full lesson?

▶ Watch the full videoPractice + free notes

Free DSA in Java course. Subscribe to Compiled Canvas on YouTube.

Watch the full video