9618 · 19.1
Algorithms
Algorithms are just step-by-step instructions for solving a problem, like a recipe for a computer. We'll look at common recipes for finding items in a list (searching) and putting a list in order (sorting).
Need to know
What you need to know
- **Advantage:** Works on any list, sorted or unsorted.
- **Advantage:** Simple to understand and implement.
- **Disadvantage:** Inefficient for large lists. The time taken grows linearly with the number of items ($O(n)$).
Explanation
Computer Recipes: Searching and Sorting
- Linear search: check each item in order.
- Binary search: halve sorted list each step.
- Bubble sort: compare adjacent pairs.
- Trace table for given algorithm input.