AmbifulWorksheets
Cheat sheet
CBSE · Class 9 · Computational Thinking and AI

Searching and Sorting

Linear search checks every item; binary search halves a sorted list. Bubble sort and selection sort put a list in order pass by pass.

Key ideas

Remember

Linear search checksthe position of the item, or all n if it is not there
Binary search, worst case for n itemsthe smallest k with 2ᵏ > n: 100 items → 7, 1,000 → 10
Bubble pass on 5, 1, 4, 21, 4, 2, 5 (3 swaps)
Total bubble swapsthe number of pairs that are out of order
Selection sort, n itemsn − 1 passes

Watch out

Worked example

Bubble sort swaps neighbouring items that are in the wrong order. How many swaps in all does it make to sort 52, 28, 36, 43, 3, 54?

Working: every swap fixes one out-of-order pair; count those pairs

Answer: 7