Standard methods of solution

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Standard methods of solution

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a standard method?
A A brand new algorithm invented fresh for every problem
B A tried-and-tested algorithm for a common task that programmers reuse
2. Which task uses the standard method of totalling?
A Adding up all the marks in an array
B Finding where the name Zoe is stored
3. Which standard method fits this problem: 'How many students scored over 50?'
A Counting
B Bubble sort
4. Which standard method fits this problem: 'Find the highest temperature this week'?
A Finding the maximum
B Calculating the average
5. Which standard method fits this problem: 'Is the item 'Pen' in the list?'
A Totalling
B Linear search

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Total ← Total + Marks[i] ATotal is reset to 0 inside the loop, so it is wiped every time. The standard method sets it to 0 once before the loop.
2IF Marks[i] > Max THEN Max ← Marks[i] BIF Nums[i] > Nums[i + 1] THEN Temp ← Nums[i]
3Linear search is a standard method that checks each item in turn until the target is found CIF Names[i] = Target THEN Found ← TRUE
4Bubble sort is a standard method that swaps neighbouring items that are in the wrong order DCounting should add 1 each time, not add the value. This adds the mark itself, so it totals instead of counting.
5Count ← Count + Marks[i] ETotalling: adds each array value to a running total inside a loop
6FOR i ← 1 TO 10 Total ← 0 Total ← Total + Marks[i] NEXT i FFinding the maximum: keeps the largest value seen so far

Definitions

standard method

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Total ← 0 FOR i ← 1 TO 10 Total ← Total _ Mark[i]
2.
FOR i ← 1 TO 10 IF Mark[i] > 50 THEN Count ← Count + _ NEXT i
3.
Max ← Mark[1] IF Mark[i] _ Max THEN Max ← Mark[i]
4.
Found ← FALSE FOR i ← 1 TO 10 IF Name[i] = Target THEN Found ← ____
5.
Temp ← Num[j] Num[j] ← Num[j + 1] Num[j + 1] ← ____

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Total : INTEGER
B Total ← 1
C FOR i ← 1 TO 5
D Total ← Total + Num[i]
E NEXT i
Question 2
A Count = 0
B FOR i ← 1 TO 10
C IF Mark[i] >= 50 THEN
D Count ← Count + 1
E ENDIF
F NEXT i
Question 3
A Max ← Num[1]
B FOR i ← 2 TO 10
C IF Num[i] < Max THEN
D Max ← Num[i]
E ENDIF
F NEXT i
Question 4
A Min ← 0
B FOR i ← 2 TO 10
C IF Num[i] < Min THEN
D Min ← Num[i]
E ENDIF
F NEXT i
Question 5
A Found ← FALSE
B FOR i ← 0 TO 5
C IF Names[i] = Target THEN
D Found ← TRUE
E ENDIF
F NEXT i

Answer Key

Standard methods of solution
Section A: Quick Questions
Q1
B — A tried-and-tested algorithm for a common task that programmers reuse
Q2
A — Adding up all the marks in an array
Q3
A — Counting
Q4
A — Finding the maximum
Q5
B — Linear search
Section B: Match the Pairs
Q1
Total ← Total + Marks[i] → Totalling: adds each array value to a running total inside a loop
Q2
IF Marks[i] > Max THEN Max ← Marks[i] → Finding the maximum: keeps the largest value seen so far
Q3
Linear search is a standard method that checks each item in turn until the target is found → IF Names[i] = Target THEN Found ← TRUE
Q4
Bubble sort is a standard method that swaps neighbouring items that are in the wrong order → IF Nums[i] > Nums[i + 1] THEN Temp ← Nums[i]
Q5
Count ← Count + Marks[i] → Counting should add 1 each time, not add the value. This adds the mark itself, so it totals instead of counting.
Q6
FOR i ← 1 TO 10 Total ← 0 Total ← Total + Marks[i] NEXT i → Total is reset to 0 inside the loop, so it is wiped every time. The standard method sets it to 0 once before the loop.
Section C: Definitions
Q1
standard method — A tried-and-tested algorithm for a common task, such as totalling, counting, max/min, average, linear search or bubble sort, that programmers reuse instead of inventing a new solution.
Section D: Fill in the Blanks
Q1
Total ← 0 FOR i ← 1 TO 10 Total ← Total + Mark[i]
Q2
FOR i ← 1 TO 10 IF Mark[i] > 50 THEN Count ← Count + 1 NEXT i
Q3
Max ← Mark[1] IF Mark[i] > Max THEN Max ← Mark[i]
Q4
Found ← FALSE FOR i ← 1 TO 10 IF Name[i] = Target THEN Found ← TRUE
Q5
Temp ← Num[j] Num[j] ← Num[j + 1] Num[j + 1] ← Temp
Section E: Spot the Error
Q1
B — A running total must start at 0. Starting at 1 makes every answer one too high. The line should be Total ← 0.
Q2
A — In Cambridge pseudocode a value is stored with the assignment arrow ←. The = sign is a comparison. The line should be Count ← 0.
Q3
C — To find the maximum, replace Max when an item is bigger than it. Using < finds the minimum instead. The line should be IF Num[i] > Max THEN.
Q4
A — Min must start as the first item in the array. If it starts at 0, no positive value is ever smaller, so the minimum stays 0. The line should be Min ← Num[1].
Q5
B — A linear search must check every element from the first. Cambridge arrays start at index 1, so index 0 does not exist. The line should be FOR i ← 1 TO 5.