9618/23

Computer Science 9618/23May/June 2022

Cambridge AS Level · Fundamental Problem-solving and Programming Skills · worked solutions for every part, with the mark scheme

9
questions
75
marks
120
minutes

Topics Programming · Data Types and Structures · Software Development · Algorithm Design and Problem-solving

Q1ProgrammingAlgorithm Design and Problem-solvingData Types and StructuresFree sample

Refer to the insert for the list of pseudocode functions and operators.

(a)

The following table contains pseudocode examples.

Each example may include all or part of:

  • selection
  • iteration (repetition)
  • assignment.

Complete the table by placing one or more ticks (✓) in each row.

Pseudocode exampleSelectionIterationAssignment
FOR Index ← 1 TO 3
Safe[Index] ← GetResult()
NEXT Index
OTHERWISE : OUTPUT "ERROR 1202"
REPEAT UNTIL Index = 27
INPUT MyName
IF Mark > 74 THEN
Grade ← 'A'
ENDIF
5M
DifficultyMedium-Easy
Worked solution

Answer

Pseudocode exampleSelectionIterationAssignment
FOR Index ← 1 TO 3
Safe[Index] ← GetResult()
NEXT Index
OTHERWISE : OUTPUT "ERROR 1202"
REPEAT UNTIL Index = 27
INPUT MyName
IF Mark > 74 THEN
Grade ← 'A'
ENDIF
Final answer

See completed table

Detailed explanation

Background Concept

This question tests recognition of three basic programming constructs in pseudocode:

  • Selection chooses between alternatives depending on a condition. Common clues are IF ... THEN, ELSE, CASE OF, and OTHERWISE.
  • Iteration means repetition. Common clues are loop keywords such as FOR, WHILE, and REPEAT UNTIL.
  • Assignment stores a value into a variable or array element. In Cambridge pseudocode, assignment is shown with the arrow .

It is important not to confuse other statements with assignment. For example, INPUT reads data from the user, and OUTPUT displays data, but neither is written as an assignment statement.

Understanding the Question

You are given five short pseudocode examples. For each one, you must decide whether it contains:

  • selection
  • iteration
  • assignment

A row can have more than one tick because one piece of pseudocode may contain, for example, a loop and also an assignment inside that loop.

Approach

Go through each row and look for the key evidence:

  1. Is there a loop keyword such as FOR or REPEAT? If so, tick iteration.
  2. Is there a decision structure such as IF or OTHERWISE? If so, tick selection.
  3. Is there an assignment arrow ? If so, tick assignment.
  4. If none of these appear, leave the row blank.

Step-by-Step Reasoning

Row 1

FOR Index ← 1 TO 3 ... NEXT Index

  • FOR ... NEXT is a count-controlled loop, so this is iteration.
  • Safe[Index] ← GetResult() uses the assignment arrow, so this is assignment.
  • There is no decision such as IF, so it is not selection.

Row 2

OTHERWISE : OUTPUT "ERROR 1202"

  • OTHERWISE belongs to a selection structure such as CASE OF.
  • So this is selection.
  • There is no loop.
  • There is no assignment arrow.

Row 3

REPEAT UNTIL Index = 27

  • REPEAT UNTIL is a repetition structure, so this is iteration.
  • The condition controls when the loop stops, but the construct itself is still a loop, not a selection statement.
  • There is no assignment arrow.

Row 4

INPUT MyName

  • This takes data from the user.
  • It is not a selection structure.
  • It is not a loop.
  • It is not written as an assignment using .
  • So no ticks are needed.

Row 5

IF Mark > 74 THEN ... ENDIF

  • IF ... THEN is selection.
  • Grade ← 'A' is assignment.
  • There is no repetition, so it is not iteration.

Key Takeaways

  • IF, CASE, and OTHERWISE indicate selection.
  • FOR, WHILE, and REPEAT UNTIL indicate iteration.
  • The arrow indicates assignment.
  • INPUT and OUTPUT are separate kinds of statements and should not be ticked unless the row also contains one of the named constructs.

Common Mistakes

  • Ticking assignment for INPUT MyName: INPUT stores a user-entered value, but in exam terminology it is not an assignment statement unless is used.
  • Missing selection in OTHERWISE: even though the full CASE statement is not shown, OTHERWISE is still part of selection.
  • Ticking selection for REPEAT UNTIL: the loop uses a condition, but it is still iteration, not selection.
  • Forgetting that one row can have more than one tick: the FOR example and the IF example both contain two constructs.

Things to Be Careful About

  • In Cambridge pseudocode, assignment must be identified by .
  • A condition by itself does not automatically mean selection; check whether it is controlling a choice (IF) or a repetition (REPEAT UNTIL).
  • Read the whole row, not just the first keyword, because another construct may appear inside it.
  • Leave cells blank where a construct is absent; do not force one tick per row.
Techniques used
identify loop constructs from pseudocode keywordsrecognise selection statements from IF and OTHERWISEspot assignment statements using the assignment arrowdistinguish input and output statements from assignment
(b)
(i)

Program variables have values as follows:

VariableValue
AAATRUE
BBBFALSE
Count99

Complete the table by evaluating each expression.

ExpressionEvaluation
AAA AND (Count > 99)
AAA AND (NOT BBB)
(Count <= 99) AND (AAA OR BBB)
(BBB AND Count > 50) OR NOT AAA
2M
DifficultyMedium-Easy
Worked solution

Answer

ExpressionEvaluation
AAA AND (Count > 99)FALSE
AAA AND (NOT BBB)TRUE
(Count <= 99) AND (AAA OR BBB)TRUE
(BBB AND Count > 50) OR NOT AAAFALSE
Final answer

See completed table

Detailed explanation

Background Concept

A Boolean expression is an expression that evaluates to either TRUE or FALSE. In this question, the expressions combine:

  • Boolean variables such as AAA and BBB
  • relational tests such as Count > 99
  • logical operators AND, OR, and NOT

Key rules:

  • NOT reverses a Boolean value.
  • AND is only TRUE if both parts are TRUE.
  • OR is TRUE if at least one part is TRUE.
  • Comparisons such as >, <, <=, = also produce TRUE or FALSE.
  • Parentheses tell you what to work out first.

Understanding the Question

You are told that:

  • AAA = TRUE
  • BBB = FALSE
  • Count = 99

You must substitute those values into each expression and work out the final Boolean result. The answer in each row must be either TRUE or FALSE.

Approach

For each expression:

  1. Replace variable names with their values.
  2. Evaluate any comparisons such as Count > 99.
  3. Apply NOT where needed.
  4. Combine the remaining Boolean values using AND or OR.
  5. Use parentheses to keep the correct order.

Step-by-Step Reasoning

1. AAA AND (Count > 99)

Substitute the values:

  • AAA becomes TRUE
  • Count > 99 becomes 99 > 99, which is FALSE

So the expression becomes:

  • TRUE AND FALSE

AND needs both sides to be true, so the result is:

  • FALSE

2. AAA AND (NOT BBB)

Substitute the values:

  • AAA becomes TRUE
  • BBB becomes FALSE

Now evaluate NOT BBB:

  • NOT FALSE = TRUE

So the expression becomes:

  • TRUE AND TRUE

Therefore the result is:

  • TRUE

3. (Count <= 99) AND (AAA OR BBB)

Evaluate the left side:

  • Count <= 99 becomes 99 <= 99, which is TRUE

Evaluate the right side:

  • AAA OR BBB becomes TRUE OR FALSE, which is TRUE

Now combine them:

  • TRUE AND TRUE = TRUE

So the result is:

  • TRUE

4. (BBB AND Count > 50) OR NOT AAA

First evaluate the left bracket:

  • BBB is FALSE
  • Count > 50 becomes 99 > 50, which is TRUE
  • FALSE AND TRUE = FALSE

Now evaluate the right side:

  • AAA is TRUE
  • NOT AAA = FALSE

Now combine both sides:

  • FALSE OR FALSE = FALSE

So the result is:

  • FALSE

Key Takeaways

  • Replace variables with their given values before evaluating the expression.
  • Relational comparisons produce Boolean results.
  • NOT changes TRUE to FALSE and FALSE to TRUE.
  • Parentheses help you evaluate complex logical expressions correctly.

Common Mistakes

  • Treating 99 > 99 as true: it is false, because 99 is not greater than 99.
  • Forgetting to apply NOT first: for example, NOT BBB must be worked out before the AND.
  • Mixing up AND and OR: AND needs both sides true; OR needs only one true.
  • Ignoring the brackets: brackets show which part of the expression must be evaluated together.

Things to Be Careful About

  • <= means less than or equal to, so 99 <= 99 is TRUE.
  • If a Boolean variable is already given as TRUE or FALSE, do not reinterpret it.
  • Work systematically line by line; this reduces sign and logic errors.
  • In exams, final Boolean values should be written exactly as TRUE or FALSE.
Techniques used
substitute given variable values into each expressionevaluate relational conditions to Boolean valuesapply NOT before AND and ORuse parentheses to control the order of evaluation
(ii)

Give an example of when a variable of type Boolean would be used.

1M
DifficultyEasy
Worked solution

Answer

  • A Boolean variable could be used as a flag, for example Found, to show whether an item has been located in a search.
Final answer

A Boolean flag such as Found to show whether an item has been located in a search.

Detailed explanation

Background Concept

A Boolean data type stores only one of two possible values: TRUE or FALSE. It is used when a program needs to record a yes/no, on/off, found/not found, valid/invalid, or similar two-state condition.

Boolean variables are often called flags because they signal whether something has happened or whether a condition is currently true.

Understanding the Question

The question asks for an example of when a Boolean variable would be used. That means you do not need a definition of Boolean; you need a realistic programming situation where only two states are possible.

Approach

Think of a program variable that answers a yes/no question, such as:

  • Has the item been found?
  • Is the password correct?
  • Is the file open?
  • Is the user logged in?

Any one valid example is enough.

Step-by-Step Reasoning

A good example is a search program.

When a program looks through data for a target item, it often uses a flag variable such as Found.

  • Before the search starts, Found ← FALSE
  • If the item is discovered, Found ← TRUE

This is a suitable Boolean variable because the condition has only two possible states:

  • the item has been found
  • the item has not been found

That matches the Boolean data type exactly.

Key Takeaways

  • Boolean variables store only TRUE or FALSE.
  • They are best used for two-state conditions.
  • Common uses include flags in searches, validation checks, login status, and loop control.

Common Mistakes

  • Giving a non-Boolean example: for example, a person's age or a total score is not Boolean because it can have many values.
  • Describing the data type instead of giving a use: the question asks for an example of use, not just a definition.
  • Giving a vague answer: saying "for decisions" is weaker than naming a specific variable such as Found or IsValid.

Things to Be Careful About

  • Make sure your example can only be TRUE or FALSE.
  • Use a realistic variable name if possible, such as Found, IsOpen, or LoggedIn.
  • One clear example is enough for a 1-mark question; do not overcomplicate it.
Techniques used
identify a two-state conditionmatch the condition to a Boolean flag variable

The rest of this paper

8 more questions
  • Q2Software Development4M
  • Q3Software Development · Programming7M
  • Q4Software Development4M
  • Q5Data Types and Structures · Programming12M
  • Q6Programming · Algorithm Design and Problem-solving10M
  • Q7Data Types and Structures · Programming8M
  • Q8Software Development6M
  • Q9Programming · Data Types and Structures16M
Loading the full paper…