GCSE Computer Science · Topic 6
Algorithms: representation, searching and sorting
Algorithms, representation, searching and sorting is about writing clear algorithms and choosing efficient ones.
We will write pseudocode and flowcharts, and use trace tables to find errors.
Then we compare linear and binary search, bubble, insertion and merge sort, and measure efficiency.
- 5 subtopics
- 162 questions
- Free: 6.1 notes and 10 questions
In this topic
- 6.1Writing algorithms in pseudocode and flowcharts (exam reference languages)Free below · 20 questions
- 6.2Trace tables, dry-running and finding errors in algorithmsOpen in Full Marks · 26 questions
- 6.3Searching algorithms: linear and binary searchOpen in Full Marks · 62 questions
- 6.4Sorting algorithms: bubble, insertion and merge sortOpen in Full Marks · 31 questions
- 6.5Comparing the efficiency of algorithmsOpen in Full Marks · 23 questions
6.1 · Free notes
Writing algorithms in pseudocode and flowcharts (exam reference languages)
Key points
- An algorithm is a finite, step-by-step set of instructions that solves a problem. It can be written as pseudocode, as a flowchart or in structured English.
- Pseudocode is not a real programming language, so a computer cannot run it directly. Mark schemes reward correct logic, not perfect syntax, provided the layout is clear and consistent.
- Every algorithm is built from three constructs: sequence (steps in order), selection (IF / ELSE decisions) and iteration (loops).
- Know your board's reference style. AQA assigns with ← (score ← 5) and compares with =. OCR assigns with = and compares with ==. Edexcel uses words such as SET score TO 5.
- Selection uses IF ... THEN ... ELSE ... ENDIF, and OCR also has elseif and switch/case. Iteration is either count-controlled (FOR ... ENDFOR, runs a set number of times, both end values included) or condition-controlled (WHILE or REPEAT).
- WHILE tests its condition before each pass, so the body may never run. REPEAT ... UNTIL (do ... until in OCR) tests at the end, so the body always runs at least once.
- Input and output differ by board. AQA uses USERINPUT and OUTPUT, OCR uses input() and print(), and Edexcel uses RECEIVE ... FROM KEYBOARD and SEND ... TO DISPLAY.
- DIV gives the whole-number part of a division (17 DIV 5 = 3). MOD gives the remainder (17 MOD 5 = 2). Both are used for tasks such as testing odd/even or splitting hours and minutes.
- Flowchart symbols: an oval (terminator) for Start/End, a parallelogram for input/output, a rectangle for a process, a diamond for a decision, and a rectangle with double side lines for a subroutine. Arrows show the direction of flow.
- Flowchart rules: one Start and at least one End, and a decision diamond has one entry and two labelled exits (Yes/No or True/False). A loop is drawn as an arrow returning to an earlier point.
- Good practice: use meaningful identifiers, initialise variables before use (total ← 0), and indent loop and IF bodies. Subroutines are written as SUBROUTINE name(parameters) ... ENDSUBROUTINE in AQA, or procedure/function in OCR.
In more detail
- Worked pseudocode: total ← 0 / FOR i ← 1 TO 5 / total ← total + i / ENDFOR / OUTPUT total → outputs 15.
- Worked DIV and MOD: 135 minutes → 135 DIV 60 = 2 hours and 135 MOD 60 = 15 minutes.
- Worked flowchart: Start (oval) → input age (parallelogram) → "age ≥ 18?" (diamond) → output "Adult" or "Child" → End.
- REPEAT vs WHILE: REPEAT … UNTIL guess = 7 always runs at least once; WHILE guess ≠ 7 may not run at all if guess is already 7.
Practice
Writing algorithms in pseudocode and flowcharts (exam reference languages): 10 questions
Pick an answer to check it, or open the answer for the explanation.
1. Which flowchart symbol is used for a decision such as 'Is n > 10?'
- Parallelogram
- Rectangle
- Diamond
- Oval
Show answer
C: Diamond. A diamond represents a decision and has two labelled exits (Yes/No). Rectangles are processes, parallelograms are input/output and ovals are start/end.
2. Which flowchart symbol is used to show data being input or output?
- Rectangle
- Diamond
- Oval
- Parallelogram
Show answer
D: Parallelogram. A parallelogram is the standard symbol for input and output. A rectangle is a process, an oval marks start or end, and a diamond is a decision.
3. What is the value of 23 MOD 5?
- 4
- 18
- 5
- 3
Show answer
D: 3. MOD returns the remainder. 23 = 4 × 5 + 3, so 23 MOD 5 = 3. The value 4 is 23 DIV 5.
4. What is the value of 23 DIV 5?
- 4.6
- 4
- 5
- 3
Show answer
B: 4. DIV gives the whole-number part of the division: 5 goes into 23 four times, so 23 DIV 5 = 4. The remainder (3) is what MOD gives.
5. Which iteration structure always executes its body at least once?
- IF ... ENDIF
- FOR ... ENDFOR
- WHILE ... ENDWHILE
- REPEAT ... UNTIL
Show answer
D: REPEAT ... UNTIL. REPEAT ... UNTIL tests its condition after the body, so the body runs once before any test. WHILE tests first and may never run. IF is selection, not iteration.
6. A program must keep asking for a password until the user types the correct one. Which structure suits this?
- Sequence only
- A condition-controlled loop
- A count-controlled FOR loop
- A single IF statement
Show answer
B: A condition-controlled loop. The number of attempts is unknown, so a condition-controlled loop (WHILE or REPEAT) that ends when the password is correct is needed. FOR needs a known count.
7. What is output? total ← 0 FOR i ← 1 TO 4 total ← total + i ENDFOR OUTPUT total
- 6
- 4
- 15
- 10
Show answer
D: 10. The loop runs for i = 1, 2, 3 and 4 and adds each to total: 1 + 2 + 3 + 4 = 10. The end value 4 is included.
8. In AQA pseudocode, how many times does FOR i ← 0 TO 5 repeat its body?
- 7
- 5
- 6
- 4
Show answer
C: 6. A FOR loop includes both the start and the end value. i takes 0, 1, 2, 3, 4 and 5, which is 6 iterations.
9. Which of the following is NOT one of the three basic programming constructs?
- Compilation
- Selection
- Sequence
- Iteration
Show answer
A: Compilation. The three constructs are sequence, selection and iteration. Compilation is the translation of source code into machine code, not a construct for building algorithms.
10. How should a decision symbol in a correct flowchart be drawn?
- One entry and two labelled exits
- One entry and one unlabelled exit
- Two entries and no exits
- One entry and three unlabelled exits
Show answer
A: One entry and two labelled exits. A decision asks a yes/no question, so it has one flow line in and two labelled flow lines out (Yes/No or True/False).
Keep going in Full Marks
Full Marks has 20 questions on Writing algorithms in pseudocode and flowcharts (exam reference languages) (10 more than here), set out in practice levels. You also get notes and 3D models for all 5 subtopics of Algorithms: representation, searching and sorting, plus games, timed exams and past papers.