Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

AQA GCSE CS · 3.1.1

Representing Algorithms

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 16 marks. Total 26 marks.

Name

Class

Date

Mark  / 26

Section A

Circle the letter of the correct answer. One mark each.

  1. 1In AQA pseudo-code, what does the left arrow mean?1
    1. AReturn a value from a subroutine
    2. BOutput the value to the screen
    3. CComparison: test whether two values are equal
    4. DAssignment: store the value on the right in the variable on the left
  2. 2What is the value of SUBSTRING(1, 3, 'binary')?1
    1. A'bin'
    2. B'in'
    3. C'ina'
    4. D'nar'
  3. 3What is the value of POSITION('computer', 'm')?1
    1. A1
    2. B2
    3. C3
    4. D4
  4. 4Which loop is guaranteed to run at least once?1
    1. AFOR ... ENDFOR
    2. BIF ... ENDIF
    3. CREPEAT ... UNTIL
    4. DWHILE ... ENDWHILE
  5. 5What is the result of 17 DIV 5?1
    1. A2
    2. B3
    3. C3.4
    4. D85
  6. 6What is the result of 17 MOD 5?1
    1. A0
    2. B2
    3. C3
    4. D3.4
  7. 7Which flowchart symbol is drawn as a parallelogram?1
    1. AProcess
    2. BTerminal
    3. CInput or output
    4. DDecision
  8. 8In a flowchart, what does an arrow that travels back up the page to an earlier decision indicate?1
    1. ASelection
    2. BThe end of the algorithm
    3. CA subroutine call
    4. DIteration
  9. 9When completing a trace table, what should you write each time a variable changes?1
    1. AA new row showing the changed value
    2. BThe value in the same cell, overwriting the old one
    3. CNothing, only the final value matters
    4. DOnly the loop counter
  10. 10Which AQA keyword closes a FOR loop?1
    1. AENDFOR
    2. BUNTIL
    3. CNEXT
    4. DLOOP

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1StateState the difference between a WHILE loop and a REPEAT UNTIL loop.2
  2. 2DescribeDescribe the purpose of a trace table and explain how it is used to find an error in an algorithm.4
  3. 3DescribeA flowchart contains a diamond shaped symbol. Describe the purpose of this symbol and state what must be true of the paths leaving it.3
  4. 4ExplainExplain two advantages of writing an algorithm in pseudo-code before writing it in a programming language.4
  5. 5ExplainLook at this algorithm. n ← 5 total ← 1 WHILE n > 1 total ← total * n n ← n - 1 ENDWHILE OUTPUT total State the value output and explain what the algorithm calculates.3

Mark scheme

Section A

1D2C3B4C5B6B7C8D9A10A

Section B

1 State the difference between a WHILE loop and a REPEAT UNTIL loop. 2

One mark for each of the following, to a maximum of 2.

  • A WHILE loop tests its condition before the body runs, so it may run zero times
  • A REPEAT loop tests its condition after the body runs, so it always runs at least once

Model answer. A WHILE loop tests its condition before the body is executed, so if the condition is false at the start the body never runs at all. A REPEAT UNTIL loop tests its condition after the body has been executed, so the body always runs at least once whatever the condition.

2 Describe the purpose of a trace table and explain how it is used to find an error in an algorithm. 4

One mark for each of the following, to a maximum of 4.

  • A trace table records the value of each variable at each step of the algorithm
  • The algorithm is executed by hand rather than run on a computer
  • The recorded values are compared with the values that were expected
  • The first row where the value differs identifies the line containing the error

Model answer. A trace table is a table with one column for each variable, and one for any output, in which the value of every variable is written down after each step of the algorithm. The algorithm is executed by hand rather than run on a computer, so the programmer can see exactly what happens inside it. Each recorded value is then compared with what was expected at that point, and the first row in which the actual value differs from the expected value shows precisely where the algorithm first goes wrong. That narrows a fault down to a single line, which is far quicker than reading the whole algorithm and guessing.

3 A flowchart contains a diamond shaped symbol. Describe the purpose of this symbol and state what must be true of the paths leaving it. 3

One mark for each of the following, to a maximum of 3.

  • The diamond represents a decision
  • It contains a condition that evaluates to either true or false
  • Exactly two paths leave it and both must be labelled

Model answer. The diamond is the decision symbol and it contains a condition that can only evaluate to true or false, such as whether a total is greater than one hundred. Exactly two flow lines leave the symbol, one followed when the condition is true and one when it is false, and both must be clearly labelled Yes and No so that the reader can tell which path is which. If a backward flow line returns to the diamond from below then the decision is controlling a loop rather than a simple selection.

4 Explain two advantages of writing an algorithm in pseudo-code before writing it in a programming language. 4

One mark for each of the following, to a maximum of 4.

  • Pseudo-code is not tied to one programming language
  • So the same design can be implemented in Python, C# or VB.NET
  • The logic can be checked before any code is written
  • Which saves time because errors in the method are corrected on paper rather than debugged in code

Model answer. The first advantage is that pseudo-code is not tied to any one programming language, so the designer does not have to worry about the exact syntax of Python or C# while working out the method. The same pseudo-code can then be handed to any programmer and implemented in whichever language the project uses. The second advantage is that the logic of the solution can be checked, for example with a trace table, before a single line of real code exists. A mistake in the method costs a couple of minutes to fix while it is still pseudo-code, but once it has been built into working code it has to be found by debugging, which takes far longer.

5 Look at this algorithm. n ← 5 total ← 1 WHILE n > 1 total ← total * n n ← n - 1 ENDWHILE OUTPUT total State the value output and explain what the algorithm calculates. 3

One mark for each of the following, to a maximum of 3.

  • The output is 120
  • The algorithm repeatedly multiplies the running total by n while decreasing n
  • It calculates the factorial of the starting value of n

Model answer. The loop multiplies total by 5, then by 4, then by 3, then by 2, stopping when n reaches 1, so total becomes 120. The algorithm therefore calculates the factorial of the starting value of n, that is the product of every whole number from n down to 1. Tracing it row by row confirms this: total takes the values 5, 20, 60 and 120 as n falls from 5 to 1.