9618/21

Computer Science 9618/21May/June 2022

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

8
questions
75
marks
120
minutes

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

Q1Algorithm Design and Problem-solvingData Types and StructuresProgrammingFree sample

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

(a)

A programmer draws a program flowchart to show the sequence of steps required to solve a problem.

Give the technical term for a sequence of steps that describe how to solve a problem.

1M
DifficultyEasy
Worked solution

Answer

  • Algorithm
Final answer

Algorithm

Detailed explanation

Background Concept

An algorithm is a finite sequence of clearly defined steps used to solve a problem or complete a task. In Computer Science, a flowchart, structured English and pseudocode are all different ways of representing an algorithm.

A flowchart is not the algorithm itself; it is a diagram showing the algorithm. The underlying idea being described is still the sequence of steps, and the technical term for that is algorithm.

Understanding the Question

The question says a programmer draws a flowchart to show the sequence of steps needed to solve a problem. It then asks for the technical term for that sequence of steps.

The important clue is the phrase "sequence of steps ... to solve a problem". That definition matches algorithm exactly.

Approach

For a definition question like this, match the wording in the question to the standard Computer Science term.

  • "sequence of steps"
  • "solve a problem"

That pair of ideas points directly to algorithm.

Step-by-Step Reasoning

A flowchart is a way of representing the logic of a solution.

The solution itself, when described as an ordered set of steps, is called an algorithm.

So the correct technical term is:

  • algorithm

Key Takeaways

  • An algorithm is a step-by-step method for solving a problem.
  • A flowchart is one way to show an algorithm.
  • In exam questions, definition wording is often a direct clue to the required term.

Common Mistakes

  • Writing "flowchart" instead of "algorithm". A flowchart is the diagram, not the step sequence itself.
  • Writing "program". A program is coded implementation; the question is asking for the abstract step-by-step method.

Things to Be Careful About

  • Read exactly what is being named: the representation or the thing being represented.
  • Here, the flowchart shows the sequence of steps, so the answer is not the diagram type, but the underlying concept: algorithm.
Techniques used
recognise the formal term for a step-by-step problem-solving methodlink the idea of a flowchart to the algorithm it represents
(b)

The table lists some of the variables used in a program.

(i)

Complete the table by writing the most appropriate data type for each variable.

VariableUse of variableData type
TempStores the average temperature
PetNameStores the name of my pet
MyDOBTo calculate the number of days until my next birthday
LightOnStores state of light; light is only on or off
4M
DifficultyMedium-Easy
Worked solution

Answer

VariableData type
TempREAL
PetNameSTRING
MyDOBDATE
LightOnBOOLEAN
Final answer

REAL, STRING, DATE, BOOLEAN

Detailed explanation

Background Concept

A data type tells the program what kind of value a variable will store. Choosing the correct data type matters because it affects:

  • what operations can be performed on the value
  • how the value is stored
  • how accurately the value represents the real-world data

Common data types at this level include:

  • INTEGER: whole numbers only
  • REAL: numbers with a fractional part allowed
  • STRING: text
  • BOOLEAN: only TRUE or FALSE
  • DATE: calendar dates

When a question says "most appropriate", you should choose the best-fit type, not just a type that might work.

Understanding the Question

You are given four variable names and a short description of what each one stores. Your task is to complete the table with the most suitable data type for each variable.

The descriptions are the key:

  • average temperature
  • pet's name
  • date of birth for birthday calculation
  • whether a light is on or off

Each description strongly suggests one specific data type.

Approach

For each variable, ask:

  1. Is the value numeric, text, date, or logical?
  2. If numeric, can it contain decimals?
  3. Is there a more specialised type that fits better than a general one?

Then choose the most appropriate type.

Step-by-Step Reasoning

Temp

  • It stores an average temperature.
  • An average can easily include decimal values such as 18.5.
  • Therefore INTEGER would be too limited.
  • The most suitable type is REAL.

PetName

  • A pet's name is text.
  • Text is stored as a STRING.

MyDOB

  • This is used to calculate the number of days until the next birthday.
  • Since it represents a date, the best type is DATE.
  • Although some systems might store dates as strings internally, the question asks for the most appropriate type, so DATE is better than STRING.

LightOn

  • The light has only two possible states: on or off.
  • A two-state value is best represented by BOOLEAN.
  • This would typically be TRUE for on and FALSE for off.

So the completed table is:

  • TempREAL
  • PetNameSTRING
  • MyDOBDATE
  • LightOnBOOLEAN

Key Takeaways

  • Use REAL for values that may contain decimals.
  • Use STRING for text.
  • Use DATE when the variable represents a calendar date.
  • Use BOOLEAN for yes/no or true/false states.
  • "Most appropriate" means the best semantic match.

Common Mistakes

  • Choosing INTEGER for temperature averages, forgetting that averages can be fractional.
  • Choosing STRING for a date because it can be written as text. It can be stored that way, but DATE is the more appropriate type here.
  • Choosing INTEGER or STRING for LightOn instead of BOOLEAN.

Things to Be Careful About

  • Do not pick a type just because it could hold the data; pick the one that best represents its meaning.
  • Watch words like "average", which often signal a need for REAL.
  • For on/off, true/false, yes/no values, BOOLEAN is normally the correct answer.
Techniques used
match each variable use to the most suitable data typedistinguish numeric, textual, date and logical datachoose the most appropriate rather than merely possible type
(ii)

One of the names used for a variable in the table in part 1(b)(i) is not an example of good practice.

Identify the variable and give a reason why it is not good practice to use that name.

Variable .............................................................................................................................

Reason ..............................................................................................................................

2M
DifficultyMedium-Easy
Worked solution

Answer

  • Variable: Temp
  • Reason: it is abbreviated, so the name is not fully meaningful and could be misunderstood.
Final answer

Temp — it is abbreviated and not fully meaningful

Detailed explanation

Background Concept

Good variable names are important because they make code easier to read, understand and maintain. A good variable name should usually be:

  • meaningful
  • descriptive
  • unambiguous
  • consistent with naming conventions

Poor names are often:

  • too short
  • abbreviated unnecessarily
  • vague
  • misleading

A reader should be able to tell the purpose of the variable from its name.

Understanding the Question

The question says one variable name from part 1(b)(i) is not good practice. You must:

  1. identify that variable
  2. give a reason why it is poor practice

The names given are Temp, PetName, MyDOB and LightOn.

The least good one is the one that is least clear or least descriptive.

Approach

Compare each variable name against good naming rules.

  • PetName is clear and descriptive.
  • LightOn clearly suggests a Boolean state.
  • MyDOB is reasonably meaningful, though abbreviated.
  • Temp is the weakest because it is shortened and can be unclear.

So the best choice is Temp, and the reason should focus on abbreviation or lack of clarity.

Step-by-Step Reasoning

Look at Temp.

This could mean:

  • temperature
  • temporary
  • something else shortened to "temp"

Because it is abbreviated, it is less clear than a fuller name such as Temperature or AverageTemperature.

That makes it poor practice compared with the other names, which are more self-explanatory.

A valid exam reason is therefore that it is abbreviated and not fully meaningful, or that it could be misunderstood.

Key Takeaways

  • Good variable names should explain purpose clearly.
  • Avoid unnecessary abbreviations.
  • Descriptive identifiers make programs easier to understand and maintain.

Common Mistakes

  • Naming the wrong variable without giving a valid reason.
  • Giving a weak reason such as "I do not like the name" instead of a technical reason.
  • Saying a name is wrong because it contains capitals; capitals are often acceptable in camelCase or similar styles.

Things to Be Careful About

  • The question asks for one name that is not good practice, so choose the clearest weak example.
  • Your reason must be about naming quality, such as clarity, meaning or ambiguity.
  • Keep the reason linked directly to the chosen identifier; here, Temp is not as clear as a full descriptive name.
Techniques used
evaluate identifier quality against naming conventionsidentify an abbreviated variable namejustify why descriptive names improve readability
(c)

Complete the table by evaluating each expression.

ExpressionEvaluation
INT((31 / 3) + 1)
MID(TO_UPPER("Version"), 4, 2)
TRUE AND (NOT FALSE)
NUM_TO_STR(27 MOD 3)
4M
DifficultyMedium-Easy
Worked solution

Working

  • INT((31 / 3) + 1)

    • 31 / 3 = 10.333...
    • 10.333... + 1 = 11.333...
    • INT(11.333...) = 11
  • MID(TO_UPPER("Version"), 4, 2)

    • TO_UPPER("Version") = "VERSION"
    • Characters 4 to 5 = SI
  • TRUE AND (NOT FALSE)

    • NOT FALSE = TRUE
    • TRUE AND TRUE = TRUE
  • NUM_TO_STR(27 MOD 3)

    • 27 MOD 3 = 0
    • NUM_TO_STR(0) = "0"

Answer

ExpressionEvaluation
INT((31 / 3) + 1)11
MID(TO_UPPER("Version"), 4, 2)SI
TRUE AND (NOT FALSE)TRUE
NUM_TO_STR(27 MOD 3)"0"
Final answer

11, SI, TRUE, "0"

Detailed explanation

Background Concept

This question tests expression evaluation in pseudocode. That includes several different ideas:

  • arithmetic operations such as division and addition
  • built-in functions such as INT, MID, TO_UPPER and NUM_TO_STR
  • Boolean operators such as AND and NOT
  • modulus using MOD

Key function meanings:

  • INT(x) returns the integer part of a number
  • TO_UPPER(text) converts letters to uppercase
  • MID(text, start, length) returns a section of a string
  • NUM_TO_STR(number) converts a numeric value into a string
  • MOD returns the remainder after division

In Cambridge pseudocode, string positions are counted from 1.

Understanding the Question

You are given four separate expressions and must write the value each one produces.

This is not about writing code; it is about reading pseudocode accurately and applying the functions and operators in the correct order.

The four expressions test different skills:

  • numeric evaluation with INT
  • string processing with TO_UPPER and MID
  • Boolean logic with AND and NOT
  • remainder and type conversion with MOD and NUM_TO_STR

Approach

Take each expression one stage at a time.

  1. Evaluate the innermost part first.
  2. Apply any function to that result.
  3. Keep track of the data type of the result.

For example, if the final operation is NUM_TO_STR, the result is a string, not a number.

Step-by-Step Reasoning

1. INT((31 / 3) + 1)

Start with the brackets:

31÷3=10.33331 \div 3 = 10.333\ldots

Then add 1:

10.333+1=11.33310.333\ldots + 1 = 11.333\ldots

Now apply INT.
For a positive number, INT removes the fractional part, leaving:

1111

So the evaluation is 11.

2. MID(TO_UPPER("Version"), 4, 2)

First apply TO_UPPER:

  • "Version" becomes "VERSION"

Now number the characters using 1-based indexing:

  • 1 = V
  • 2 = E
  • 3 = R
  • 4 = S
  • 5 = I
  • 6 = O
  • 7 = N

MID(text, 4, 2) means start at character 4 and take 2 characters.
That gives:

  • character 4 = S
  • character 5 = I

So the result is SI.

3. TRUE AND (NOT FALSE)

Start inside the brackets:

  • NOT FALSE = TRUE

Now the expression becomes:

  • TRUE AND TRUE

AND is only TRUE if both sides are TRUE, so the result is:

  • TRUE

4. NUM_TO_STR(27 MOD 3)

First find the remainder when 27 is divided by 3.

Since 27 divides exactly by 3, the remainder is:

  • 0

Now apply NUM_TO_STR.
This converts the number 0 into the string "0".

So the final result is "0".

Key Takeaways

  • Evaluate expressions from the inside outward.
  • INT removes the fractional part.
  • MID uses a start position and length, and string positions are 1-based.
  • NOT changes FALSE to TRUE and vice versa.
  • MOD gives a remainder.
  • NUM_TO_STR changes a numeric result into text.

Common Mistakes

  • Writing 10 for the first expression by applying INT too early to 31 / 3 before adding 1.
  • Using 0-based indexing for MID and getting the wrong substring.
  • Forgetting to apply TO_UPPER before taking the substring.
  • Writing 0 instead of "0" for NUM_TO_STR(27 MOD 3), which loses the fact that the final result is a string.
  • Evaluating TRUE AND (NOT FALSE) as FALSE by mishandling NOT.

Things to Be Careful About

  • Keep track of data type as well as value.
  • In string questions, check carefully whether positions start at 0 or 1; here they are 1-based.
  • INT is applied after the whole bracketed expression is found.
  • MOD does not mean division result; it means remainder.
  • When a conversion function is used, make sure your final answer matches the converted form.
Techniques used
evaluate arithmetic expressions in the correct orderapply built-in pseudocode functions to stringsuse Boolean logic with NOT and ANDcalculate a remainder with MOD and convert it to a string

The rest of this paper

7 more questions
  • Q2Software Development7M
  • Q3Algorithm Design and Problem-solving · Programming4M
  • Q4Data Types and Structures6M
  • Q5Data Types and Structures · Programming6M
  • Q6Programming9M
  • Q7Programming · Algorithm Design and Problem-solving11M
  • Q8Programming · Data Types and Structures · Software Development21M
Loading the full paper…