Notes · Class 12 · CBSE · Science Computer Science

Sorting notes

Revision notes for the chapter: the key points, definitions and exam tips to remember.

Sorting arranges elements in a particular order (ascending or descending).

BUBBLE SORT

  • Repeatedly compare adjacent elements and swap if out of order.
  • After each pass, the largest element "bubbles" to the end.
  • n − 1 passes; time complexity O(n²).

SELECTION SORT

  • Find the smallest element in the unsorted part and swap it with the first unsorted element.
  • O(n²); fewer swaps than bubble sort.

INSERTION SORT

  • Take each element and insert it into its correct position in the sorted part on the left.
  • O(n²) worst case; O(n) if already nearly sorted.

TIME COMPLEXITY

  • Loops nested inside loops → O(n²). Single loop → O(n). Constant work → O(1).
Memory hook: "Bubble swaps neighbours, Selection picks the smallest, Insertion slots in place."

Sorting: practice questionsSorting cheat sheet

More Class 12 · CBSE · Science Computer Science notes

Practise Sorting

Sign up free to practise the full chapter after revising. Questions you get wrong come back until you've mastered them.

Start practising free

Free to start · No credit card needed