Computer Science 9618/23 — May/June 2022
Cambridge AS Level · Fundamental Problem-solving and Programming Skills · worked solutions for every part, with the mark scheme
Topics Programming · Data Types and Structures · Software Development · Algorithm Design and Problem-solving
Refer to the insert for the list of pseudocode functions and operators.
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 example | Selection | Iteration | Assignment |
|---|---|---|---|
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 |
Answer
| Pseudocode example | Selection | Iteration | Assignment |
|---|---|---|---|
FOR Index ← 1 TO 3Safe[Index] ← GetResult()NEXT Index | ✓ | ✓ | |
OTHERWISE : OUTPUT "ERROR 1202" | ✓ | ||
REPEAT UNTIL Index = 27 | ✓ | ||
INPUT MyName | |||
IF Mark > 74 THENGrade ← 'A'ENDIF | ✓ | ✓ |
See completed table
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, andOTHERWISE. - Iteration means repetition. Common clues are loop keywords such as
FOR,WHILE, andREPEAT 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:
- Is there a loop keyword such as
FORorREPEAT? If so, tick iteration. - Is there a decision structure such as
IForOTHERWISE? If so, tick selection. - Is there an assignment arrow
←? If so, tick assignment. - If none of these appear, leave the row blank.
Step-by-Step Reasoning
Row 1
FOR Index ← 1 TO 3 ... NEXT Index
FOR ... NEXTis 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"
OTHERWISEbelongs to a selection structure such asCASE OF.- So this is selection.
- There is no loop.
- There is no assignment arrow.
Row 3
REPEAT UNTIL Index = 27
REPEAT UNTILis 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 ... THENis selection.Grade ← 'A'is assignment.- There is no repetition, so it is not iteration.
Key Takeaways
IF,CASE, andOTHERWISEindicate selection.FOR,WHILE, andREPEAT UNTILindicate iteration.- The arrow
←indicates assignment. INPUTandOUTPUTare 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:INPUTstores a user-entered value, but in exam terminology it is not an assignment statement unless←is used. - Missing selection in
OTHERWISE: even though the fullCASEstatement is not shown,OTHERWISEis 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
FORexample and theIFexample 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.
Program variables have values as follows:
| Variable | Value |
|---|---|
| AAA | TRUE |
| BBB | FALSE |
| Count | 99 |
Complete the table by evaluating each expression.
| Expression | Evaluation |
|---|---|
AAA AND (Count > 99) | |
AAA AND (NOT BBB) | |
(Count <= 99) AND (AAA OR BBB) | |
(BBB AND Count > 50) OR NOT AAA |
Answer
| Expression | Evaluation |
|---|---|
AAA AND (Count > 99) | FALSE |
AAA AND (NOT BBB) | TRUE |
(Count <= 99) AND (AAA OR BBB) | TRUE |
(BBB AND Count > 50) OR NOT AAA | FALSE |
See completed table
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
AAAandBBB - relational tests such as
Count > 99 - logical operators
AND,OR, andNOT
Key rules:
NOTreverses a Boolean value.ANDis onlyTRUEif both parts areTRUE.ORisTRUEif at least one part isTRUE.- Comparisons such as
>,<,<=,=also produceTRUEorFALSE. - Parentheses tell you what to work out first.
Understanding the Question
You are told that:
AAA = TRUEBBB = FALSECount = 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:
- Replace variable names with their values.
- Evaluate any comparisons such as
Count > 99. - Apply
NOTwhere needed. - Combine the remaining Boolean values using
ANDorOR. - Use parentheses to keep the correct order.
Step-by-Step Reasoning
1. AAA AND (Count > 99)
Substitute the values:
AAAbecomesTRUECount > 99becomes99 > 99, which isFALSE
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:
AAAbecomesTRUEBBBbecomesFALSE
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 <= 99becomes99 <= 99, which isTRUE
Evaluate the right side:
AAA OR BBBbecomesTRUE OR FALSE, which isTRUE
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:
BBBisFALSECount > 50becomes99 > 50, which isTRUEFALSE AND TRUE = FALSE
Now evaluate the right side:
AAAisTRUENOT 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.
NOTchangesTRUEtoFALSEandFALSEtoTRUE.- Parentheses help you evaluate complex logical expressions correctly.
Common Mistakes
- Treating
99 > 99as true: it is false, because 99 is not greater than 99. - Forgetting to apply
NOTfirst: for example,NOT BBBmust be worked out before theAND. - Mixing up
ANDandOR:ANDneeds both sides true;ORneeds 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, so99 <= 99isTRUE.- If a Boolean variable is already given as
TRUEorFALSE, 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
TRUEorFALSE.
Give an example of when a variable of type Boolean would be used.
Answer
- A Boolean variable could be used as a flag, for example
Found, to show whether an item has been located in a search.
A Boolean flag such as Found to show whether an item has been located in a search.
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
TRUEorFALSE. - 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
FoundorIsValid.
Things to Be Careful About
- Make sure your example can only be
TRUEorFALSE. - Use a realistic variable name if possible, such as
Found,IsOpen, orLoggedIn. - One clear example is enough for a 1-mark question; do not overcomplicate it.
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