Skip to main content

๐ŸŽฎ Sorting (Practice)

Companion to the Sorting Algorithms guide. Watch bubble sort settle elements one by one, then implement insertion sort yourself.

๐ŸŽฌ Watch it workโ€‹

Bubble Sort โ€” adjacent compare & swapStep 1 / 23
5
2
8
1
4
Unsorted. Bubble sort compares adjacent pairs and swaps if out of order.

๐Ÿ Your turnโ€‹

Loading editorโ€ฆ

๐Ÿง  Challenge yourselfโ€‹

  1. Modify it to sort in descending order.
  2. Count the number of swaps โ€” which input order maximizes them?
  3. Why is insertion sort O(n) on an already-sorted array but O(nยฒ) worst case?

Continue the path โ†’ Stacks & Queues