Skip to main content
WalesComputer ScienceSyllabus dot point

How do we design, express and judge the efficiency of an algorithm, and which standard searching and sorting algorithms must I know?

Design algorithms in pseudocode, apply the standard searching and sorting algorithms, and compare algorithm efficiency.

A focused answer to WJEC A-Level Computer Science Unit 1 algorithms, covering algorithm design and pseudocode, linear and binary search, bubble, insertion and merge sort, and comparing efficiency.

Generated by Claude Opus 4.813 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

WJEC wants you to design algorithms and express them in pseudocode, to know the standard searching and sorting algorithms by heart, and to compare their efficiency. Algorithms are the core skill of computer science, and this dot point is heavily examined: you will be asked to trace an algorithm by hand, to spot which algorithm a fragment shows, and to justify why one is faster than another for a given size of data.

The answer

Designing an algorithm

Good algorithm design uses the three control structures (sequence, selection, iteration), validates its inputs, and is decomposed into manageable sub-problems. Designing first and coding second means errors are caught early, when they are cheap to fix.

Searching algorithms

A linear search examines each item in turn until the target is found or the list ends; it works on any list but is slow for large data. A binary search works only on a sorted list: it examines the middle item, then discards the half that cannot contain the target, repeating until found. Halving the list each step makes binary search dramatically faster on large data.

Sorting algorithms

WJEC expects you to trace these by hand on a short list, so practise showing the list after each pass or each insertion until the order is automatic.

Comparing efficiency

Efficiency is measured by how the number of operations grows as the input grows, captured by Big-O notation: linear search is O(n), binary search is O(log n), bubble and insertion sort are O(n squared), and merge sort is O(n log n).

Examples in context

Example 1. Looking up a name in a phone book
A phone book is sorted alphabetically, so you open it in the middle, see whether your name falls before or after, and discard half the book each time. This everyday action is a binary search, and it explains why the algorithm needs sorted data: the discard step depends on order.
Example 2. Why merge sort wins on big data
Sorting a million records with bubble sort takes on the order of a million squared operations, which is a trillion. Merge sort takes about a million times twenty, which is twenty million. The same task that is impractical with bubble sort finishes quickly with merge sort, showing why the growth rate, not the raw step count, decides scalability.
Example 3. Choosing the simple algorithm anyway
For a list of ten items, insertion sort's simplicity and low overhead can beat merge sort's recursion, even though merge sort wins asymptotically. Examiners reward recognising that Big-O describes large-n behaviour, and that for tiny inputs a simple algorithm may be the sensible choice.

Try this

Q1. State the worst-case Big-O time complexity of a linear search and of a binary search. [2 marks]

  • Cue. Linear search is O(n); binary search is O(log n).

Q2. A bubble sort is applied to the list 3, 1, 2. State the list after the first complete pass. [2 marks]

  • Cue. 1, 2, 3 (3 swaps past 1 and 2; the largest, 3, ends up last).

Exam-style practice questions

Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

WJEC 20185 marksA binary search is performed on the sorted list 4, 9, 15, 23, 42, 56, 71, 88 to find 23. List the values examined at each step and state the number of comparisons.
Show worked answer →

Repeatedly examine the middle element and discard the half that cannot contain the target.

The list has 8 items (indices 1 to 8). The middle is taken as index 4, value 23.

Comparison 1: examine 23. It equals the target, so the search succeeds.

Here the target was found on the first comparison because it sat at the midpoint. Had we searched for 56, comparison 1 examines 23 (target is larger, discard the left half), comparison 2 examines 71 (target is smaller, discard the right of that half), comparison 3 examines 56 and succeeds.

Number of comparisons to find 23: one.

Markers reward choosing the midpoint, halving the search range each time, and the correct comparison count for the value asked.

WJEC 20224 marksExplain why a binary search is more efficient than a linear search on a large list, and state the essential precondition for using a binary search.
Show worked answer →

Compare how the number of comparisons grows, then give the precondition.

A linear search checks items one at a time from the start, so in the worst case it makes a number of comparisons equal to the number of items, growing linearly with list size. A binary search halves the remaining list at each step, so the worst case grows with the logarithm of the list size. For a list of one million items, linear search may need a million comparisons but binary search needs at most about twenty.

The essential precondition is that the list must already be sorted, because the algorithm relies on knowing which half to discard.

Markers reward the linear-versus-logarithmic growth contrast, a numerical illustration, and the precondition that the data must be sorted.

Related dot points

Sources & how we know this