Linear search and bubble sort
About this lesson: Linear search and bubble sort
In short
Linear search starts at the first item and checks each in turn until it finds the target or reaches the end. Choose a target and step through.

What you'll explore
- Linear search: Check one by one
- Linear search starts at the first item and checks each in turn until it finds the target or reaches the end. Choose a target and step through.
- Bubble sort: Swap neighbours
- Bubble sort compares each pair of neighbours and swaps them if they are in the wrong order.
- Efficiency: Linear vs binary
- For a sorted list, binary search needs far fewer checks than linear search. Change the list size.
- Choosing an algorithm: One pass or sort first?
- To find the largest value, one pass is enough; sorting first would waste time. Change the list size.
- Check yourself: One pass
- Bubble sort, ascending, on [4, 2, 5, 1].
Also in this lesson
- Step by step
- Watch out for these
- Worst-case checks
- More than the lesson
- Stretch your brain
- Try it yourself
Words to know
- Linear search
- Checking each item in turn.
- Bubble sort
- Repeatedly swapping out-of-order neighbours.
- Pass
- One run through the list.
- Swap
- Exchanging two values.
- Efficiency
- How much time or memory an algorithm uses.
Sources
- Raspberry Pi Foundation, Isaac Computer Science: searching and sorting
- Khan Academy: algorithms
- Owen Astrachan (2003), "Bubble Sort: An Archaeological Algorithmic Analysis"
- BBC Bitesize, GCSE Computer Science: sorting algorithms