Cheat sheet · Class 12 · CBSE · Science Computer Science
Sorting cheat sheet
The whole chapter on one page: key formulas, facts and the points to remember, for quick revision before a test.
CBSE Class 12 · Computer Science
Cheat sheet
Chapter 7Sorting
Bubble swaps neighbours; Selection picks the minimum; Insertion inserts into place.
1. Algorithms
| Sort | Idea | Time |
|---|---|---|
| Bubble | repeatedly swap adjacent out-of-order pairs; largest bubbles to the end | O(n²) |
| Selection | select the smallest remaining and swap it into place | O(n²) |
| Insertion | take next element and insert into the sorted part | O(n²); O(n) if nearly sorted |
2. Bubble Sort
for i in range(n - 1):
for j in range(n - 1 - i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
3. Key Points
- Passes in bubble sort: n − 1.
- Stop early if no swaps in a pass.
- Sorting enables binary search.
- Python's sort() is O(n log n).
Remember: Bubble, selection, insertion | O(n²)
More Class 12 · CBSE · Science Computer Science cheat sheets
Practise Sorting
Sign up free to practise the full chapter. Questions you get wrong come back until you've mastered them.
Start practising freeFree to start · No credit card needed