Skip to content

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

  1. Linear search: check each item in order.
  2. Binary search: halve sorted list each step.
  3. Bubble sort: compare adjacent pairs.
  4. Trace table for given algorithm input.