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

SortIdeaTime
Bubblerepeatedly swap adjacent out-of-order pairs; largest bubbles to the endO(n²)
Selectionselect the smallest remaining and swap it into placeO(n²)
Insertiontake next element and insert into the sorted partO(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²)

Sorting: questions and notes

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 free

Free to start · No credit card needed