Writing exam answers about algorithms

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

Writing exam answers about algorithms

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A question says 'State the purpose of the algorithm'. Which answer is best?
A It sets Max to the first number, then uses a FOR loop and an IF to compare each number
B It finds the largest of 10 numbers entered by the user
2. A question says 'Describe the processes in the algorithm'. Which answer fits?
A Each mark is added to Total in a loop, then Total is divided by the number of marks
B It calculates the average mark
3. Which answer correctly identifies an error in the line IF Age = > 18 THEN?
A The algorithm is wrong and does not work
B The relational operator is written wrongly; it should be > or >=
4. The line Total = 0 is meant to set a variable. What is the correct suggestion to fix it?
A Replace = with the assignment arrow: Total ← 0
B Replace 0 with the word zero
5. A student must identify the error in a loop: FOR Count ← 1 TO 10 with no NEXT. Which is the precise answer?
A There is no NEXT Count to end the FOR loop
B The loop is not good

Match the Pairs

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

Left columnRight column
1State the purpose of the algorithm ANot precise: it does not say what is wrong with the condition, for example that < should be <= so that 100 is included.
2Describe the processes in the algorithm BToo vague: it lists features of the code but does not say what the algorithm does with the data, so it earns no marks for describing processes.
3Identify an error: name the exact line and say what is wrong with it CWrite one sentence saying what the algorithm achieves overall, e.g. it finds the largest of 10 numbers entered
4Suggest a correction: write the replacement code using the right symbols in the condition DLine 4: = is used for assignment, it should be ←
5The algorithm uses a loop and an IF and some variables. ESay what the algorithm does with its data step by step, e.g. it adds each mark to Total and counts the marks
6Line 6 is wrong because the condition does not work. FChange WHILE Mark > 100 to WHILE Mark >= 100

Definitions

command word

Fill in the Blanks

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

1.
Error: Count = Count + 1 uses = to assign Correction: Count _ Count + 1
2.
Error: Mark > 50 does not include 50 Correction: Mark _ 50
3.
Error: OR used in a range check Correction: Age ≥ 11 ___ Age ≤ 16
4.
Error: Total is not set to zero first Correction: Total ← _ before the loop
5.
// Purpose: find the largest Mark IF Mark _ Largest THEN Largest ← Mark

Spot the Error

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

Question 1
A INPUT Mark
B Grade = "Fail"
C IF Mark >= 50 THEN
D Grade ← "Pass"
E ENDIF
Question 2
A Total ← 1
B INPUT Mark
C Total ← Total + Mark
D OUTPUT Total
Question 3
A Pass ← 0
B INPUT Mark
C // 50 or more is a pass
D IF Mark > 50 THEN
E Pass ← Pass + 1
F ENDIF
Question 4
A Number ← 1
B WHILE Number < 5 DO
C OUTPUT Number
D Number ← Number - 1
E ENDWHILE
Question 5
A INPUT Age
B Price ← 10
C IF Age < 5 AND Age > 65 THEN
D Price ← 0
E ENDIF
F OUTPUT Price

Answer Key

Writing exam answers about algorithms
Section A: Quick Questions
Q1
B — It finds the largest of 10 numbers entered by the user
Q2
A — Each mark is added to Total in a loop, then Total is divided by the number of marks
Q3
B — The relational operator is written wrongly; it should be > or >=
Q4
A — Replace = with the assignment arrow: Total ← 0
Q5
A — There is no NEXT Count to end the FOR loop
Section B: Match the Pairs
Q1
State the purpose of the algorithm → Write one sentence saying what the algorithm achieves overall, e.g. it finds the largest of 10 numbers entered
Q2
Describe the processes in the algorithm → Say what the algorithm does with its data step by step, e.g. it adds each mark to Total and counts the marks
Q3
Identify an error: name the exact line and say what is wrong with it → Line 4: = is used for assignment, it should be ←
Q4
Suggest a correction: write the replacement code using the right symbols in the condition → Change WHILE Mark > 100 to WHILE Mark >= 100
Q5
The algorithm uses a loop and an IF and some variables. → Too vague: it lists features of the code but does not say what the algorithm does with the data, so it earns no marks for describing processes.
Q6
Line 6 is wrong because the condition does not work. → Not precise: it does not say what is wrong with the condition, for example that < should be <= so that 100 is included.
Section C: Definitions
Q1
command word — The exam word that tells you what to write: state the purpose, describe the processes, identify the error, suggest the correction, each in precise terms.
Section D: Fill in the Blanks
Q1
Error: Count = Count + 1 uses = to assign Correction: Count ← Count + 1
Q2
Error: Mark > 50 does not include 50 Correction: Mark ≥ 50
Q3
Error: OR used in a range check Correction: Age ≥ 11 AND Age ≤ 16
Q4
Error: Total is not set to zero first Correction: Total ← 0 before the loop
Q5
// Purpose: find the largest Mark IF Mark > Largest THEN Largest ← Mark
Section E: Spot the Error
Q1
B — Identify the error: = is used for assignment. In pseudocode a value is assigned with the arrow, so the correction is Grade ← "Fail".
Q2
A — Identify the error: the total is not set to zero before totalling, so the answer is 1 too big. Suggest the correction: Total ← 0.
Q3
D — Identify the error: > leaves out a mark of exactly 50, but 50 or more is a pass. Suggest the correction: use the symbol >= in IF Mark >= 50 THEN.
Q4
D — Identify the error: Number goes down, so Number < 5 is always true and the loop never ends. Suggest the correction: Number ← Number + 1.
Q5
C — Identify the error: no age can be both under 5 and over 65, so AND is wrong and the condition is never true. Suggest the correction: use OR.