GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free

Demo lesson: try every tab (Learn, Watch, Predict, Practice) as often as you like. It doesn't use up your 3 free topics.

Sign up free to unlock all 99
TopicsSorting

Bubble sort

beginneravg O(n²) · worst O(n²)
  • comparing
  • swapping
  • final place
38
12
71
5
56
23
90
44
0
1
2
3
4
5
6
7

Sort 8 numbers. On every pass, the biggest unsorted value bubbles to the end.

1 / 55
1void bubbleSort(int[] a) {
2 int n = a.length;
3 for (int i = 0; i < n - 1; i++) {
4 boolean swapped = false;
5 for (int j = 0; j < n - 1 - i; j++) {
6 if (a[j] > a[j + 1]) {
7 swap(a, j, j + 1);
8 swapped = true;
9 }
10 }
11 if (!swapped) break;
12 }
13}

Variables

n =
8

Work done

Comparisons
0
Swaps
0

Shortcuts: Space play/pause · ← → step · M sound