Describing the processes in an algorithm

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

Describing the processes in an algorithm

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is a better description of the process in the line Total ← 0 at the start of an algorithm?
A Checks if Total is equal to zero
B Sets the variable Total to zero before the loop starts
2. A loop runs FOR Count ← 1 TO 5 and each time adds a number to Total. Which describes what the loop repeats?
A It repeats 5 times, adding each input number to Total
B It loops and does the calculation
3. Which sentence correctly describes a decision: IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF?
A It checks the mark and outputs a message
B If Mark is 50 or more it outputs Pass, otherwise it outputs Fail
4. In what order should you describe the processes of an algorithm?
A In the order they happen: set up variables, loop, decision, then output
B Start with the output, then go back to the variables
5. Which description of Total ← Total + Number inside a loop is better?
A Adds the number just entered to the running total
B Makes Total equal to Total plus Number

Match the Pairs

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

Left columnRight column
1Total ← 0 AIF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
2OUTPUT Total BCopying code is not a description. The answer must explain in words what the line does with the data.
3Describe what the loop repeats: for each of the 10 numbers, the next value is input and added to the total. CToo vague: it does not say what is repeated or what happens to the data, so it gains no marks.
4Describe the decision and its outcomes: if the mark is 50 or more, Pass is output, otherwise Fail is output. DFOR Count ← 1 TO 10 INPUT Num Total ← Total + Num NEXT Count
5The program loops and does stuff with the numbers, then it finishes. EInitialising: the variable Total is set to zero before the loop so it can start adding up values.
6Total ← Total + Num is the process, so the answer just copies the code line. FFinal output: after the loop has finished, the value stored in Total is displayed to the user.

Definitions

Describe the processes

Fill in the Blanks

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

1.
Total ← _ Count ← 0 FOR Index ← 1 TO 10
2.
___ Index ← 1 TO 10 Total ← Total + Mark[Index] NEXT Index
3.
IF Mark[Index] > Highest ____ Highest ← Mark[Index] ENDIF
4.
Average ← Total / 10 ______ Average
5.
WHILE Count < 5 DO Count ← Count _ 1 ENDWHILE

Spot the Error

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

Question 1
A Total ← 0
B FOR Count ← 1 TO 5
C INPUT Mark
D Total ← Mark
E NEXT Count
F OUTPUT Total
Question 2
A Count ← 0
B WHILE Count > 5 DO
C OUTPUT Count
D Count ← Count + 1
E ENDWHILE
Question 3
A Total ← 0
B // Repeat 5 times
C FOR N ← 1 TO 4
D Total ← Total + N
E NEXT N
Question 4
A Total ← 1
B FOR N ← 1 TO 5
C Total ← Total + N
D NEXT N
E OUTPUT Total
Question 5
A INPUT Age
B IF Age >= 18 THEN
C OUTPUT "Child"
D ELSE
E OUTPUT "Child"
F ENDIF

Answer Key

Describing the processes in an algorithm
Section A: Quick Questions
Q1
B — Sets the variable Total to zero before the loop starts
Q2
A — It repeats 5 times, adding each input number to Total
Q3
B — If Mark is 50 or more it outputs Pass, otherwise it outputs Fail
Q4
A — In the order they happen: set up variables, loop, decision, then output
Q5
A — Adds the number just entered to the running total
Section B: Match the Pairs
Q1
Total ← 0 → Initialising: the variable Total is set to zero before the loop so it can start adding up values.
Q2
OUTPUT Total → Final output: after the loop has finished, the value stored in Total is displayed to the user.
Q3
Describe what the loop repeats: for each of the 10 numbers, the next value is input and added to the total. → FOR Count ← 1 TO 10 INPUT Num Total ← Total + Num NEXT Count
Q4
Describe the decision and its outcomes: if the mark is 50 or more, Pass is output, otherwise Fail is output. → IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Q5
The program loops and does stuff with the numbers, then it finishes. → Too vague: it does not say what is repeated or what happens to the data, so it gains no marks.
Q6
Total ← Total + Num is the process, so the answer just copies the code line. → Copying code is not a description. The answer must explain in words what the line does with the data.
Section C: Definitions
Q1
Describe the processes — State, in order and in plain words, what each part of the algorithm does with the data: set up variables, what the loop repeats, what the decision does, then the output.
Section D: Fill in the Blanks
Q1
Total ← 0 Count ← 0 FOR Index ← 1 TO 10
Q2
FOR Index ← 1 TO 10 Total ← Total + Mark[Index] NEXT Index
Q3
IF Mark[Index] > Highest THEN Highest ← Mark[Index] ENDIF
Q4
Average ← Total / 10 OUTPUT Average
Q5
WHILE Count < 5 DO Count ← Count + 1 ENDWHILE
Section E: Spot the Error
Q1
D — The loop should add each mark to the running total. Total ← Mark overwrites the total each time. It should be Total ← Total + Mark.
Q2
B — Count starts at 0, so Count > 5 is false straight away and the loop never repeats. The loop should repeat while Count < 5.
Q3
B — The comment describes the loop wrongly. FOR N ← 1 TO 4 repeats 4 times, so the comment should say Repeat 4 times.
Q4
A — The variable must be set up to 0 before the loop so that only the numbers are added. Starting at 1 makes the final total too big. It should be Total ← 0.
Q5
C — The THEN branch runs when Age >= 18, so it must output Adult. Outputting Child here gives the wrong outcome for the decision. It should be OUTPUT "Adult".