Computational thinking
- An algorithm is a set of step-by-step instructions to solve a problem.
- Decomposition means breaking a problem into smaller parts. Abstraction means removing unnecessary detail to focus on what matters. Pattern recognition means spotting similarities.
Building blocks
- Sequence: steps run in order. Selection: a decision chooses which steps run (IF… THEN… ELSE). Iteration: steps are repeated (loops such as FOR and WHILE).
- Algorithms can be written as flowcharts or pseudocode (structured English that looks like simple code).
- Flowchart symbols: an oval for start and end, a rectangle for a process, a diamond for a decision, and a parallelogram for input or output.
Searching
- A linear search checks each item in turn from the start. It works on any list, but is slow for long lists.
- A binary search only works on a sorted list. It checks the middle item, then throws away the half that can't contain the target, and repeats. It is much faster for long lists.
Sorting
- A bubble sort compares each pair of neighbouring items and swaps them if they are in the wrong order. It repeats passes until no swaps are needed. After the first pass, the largest item is at the end.
- A merge sort splits the list into single items, then merges them back together in order. It is faster for long lists.
Key terms
- Algorithm
- A set of step-by-step instructions to solve a problem.
- Decomposition
- Breaking a problem into smaller parts.
- Abstraction
- Removing unnecessary detail to focus on what matters.
- Sequence
- Steps carried out in order.
- Selection
- Choosing which steps to run, using a decision.
- Iteration
- Repeating steps, using a loop.
- Flowchart
- A diagram that shows an algorithm using symbols.
- Pseudocode
- An algorithm written in structured English, like simple code.
- Linear search
- Checking each item in a list in turn.
- Binary search
- Searching a sorted list by repeatedly checking the middle item.
- Bubble sort
- Sorting by comparing and swapping neighbouring items.
- Merge sort
- Sorting by splitting a list up and merging it back in order.