Back to Roadmap
Track 06 of 10
AlgorithmsIntermediate Level~30 Mins
6. Sorting Algorithms (Bubble, Selection, Quick, Merge)
Understand comparison sorting mechanics from O(N²) quadratic loops to O(N log N) divide-and-conquer.
The "WHY" Core Principle
Comparison-based sorting lower bound is Ω(N log N). Simple sorts compare adjacent pairs taking O(N²) operations. Advanced sorts divide arrays recursively taking O(N log N).
Interactive Visualizer
Sorting Algorithm Bar Chart Stepper
Watch element comparisons and array position swaps in real time.
45
12
89
34
67
23
90
11
56
78
30
95
Interactive Code Snippets (1 Lessons)
Lesson 01
Bubble Sort — Adjacent Swaps O(N²)
O(N²)O(1)
Repeatedly swap adjacent out-of-order elements until the largest element 'bubbles' to the top.
WHY Under The Hood:
Each outer pass places 1 largest element in its final sorted position at the right end.
CPython C Struct Detail: Python tuple swap `arr[i], arr[j] = arr[j], arr[i]` executes bytecode `ROT_TWO`.
Bubble Sort — Adjacent Swaps O(N²)
Pyodide WASM EngineType, edit code, and click 'Run & Profile' to see live runtime ms and operation count!
Python 3.12 Code (Editable)
Expected:Time: O(N²)Space: O(1)