Computer Science 9618/21 — 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 · Algorithm Design and Problem-solving · Software Development
Refer to the insert for the list of pseudocode functions and operators.
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.
Answer
- Algorithm
Algorithm
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.
The table lists some of the variables used in a program.
Complete the table by writing the most appropriate data type for each variable.
| Variable | Use of variable | Data type |
|---|---|---|
Temp | Stores the average temperature | |
PetName | Stores the name of my pet | |
MyDOB | To calculate the number of days until my next birthday | |
LightOn | Stores state of light; light is only on or off |
Answer
| Variable | Data type |
|---|---|
Temp | REAL |
PetName | STRING |
MyDOB | DATE |
LightOn | BOOLEAN |
REAL, STRING, DATE, BOOLEAN
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
TRUEorFALSE - 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:
- Is the value numeric, text, date, or logical?
- If numeric, can it contain decimals?
- 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
INTEGERwould 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
DATEis better thanSTRING.
LightOn
- The light has only two possible states: on or off.
- A two-state value is best represented by
BOOLEAN. - This would typically be
TRUEfor on andFALSEfor off.
So the completed table is:
Temp→REALPetName→STRINGMyDOB→DATELightOn→BOOLEAN
Key Takeaways
- Use
REALfor values that may contain decimals. - Use
STRINGfor text. - Use
DATEwhen the variable represents a calendar date. - Use
BOOLEANfor yes/no or true/false states. - "Most appropriate" means the best semantic match.
Common Mistakes
- Choosing
INTEGERfor temperature averages, forgetting that averages can be fractional. - Choosing
STRINGfor a date because it can be written as text. It can be stored that way, butDATEis the more appropriate type here. - Choosing
INTEGERorSTRINGforLightOninstead ofBOOLEAN.
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,
BOOLEANis normally the correct answer.
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 ..............................................................................................................................
Answer
- Variable:
Temp - Reason: it is abbreviated, so the name is not fully meaningful and could be misunderstood.
Temp — it is abbreviated and not fully meaningful
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:
- identify that variable
- 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.
PetNameis clear and descriptive.LightOnclearly suggests a Boolean state.MyDOBis reasonably meaningful, though abbreviated.Tempis 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,
Tempis not as clear as a full descriptive name.
Complete the table by evaluating each expression.
| Expression | Evaluation |
|---|---|
INT((31 / 3) + 1) | |
MID(TO_UPPER("Version"), 4, 2) | |
TRUE AND (NOT FALSE) | |
NUM_TO_STR(27 MOD 3) |
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 = TRUETRUE AND TRUE = TRUE
-
NUM_TO_STR(27 MOD 3)27 MOD 3 = 0NUM_TO_STR(0) = "0"
Answer
| Expression | Evaluation |
|---|---|
INT((31 / 3) + 1) | 11 |
MID(TO_UPPER("Version"), 4, 2) | SI |
TRUE AND (NOT FALSE) | TRUE |
NUM_TO_STR(27 MOD 3) | "0" |
11, SI, TRUE, "0"
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_UPPERandNUM_TO_STR - Boolean operators such as
ANDandNOT - modulus using
MOD
Key function meanings:
INT(x)returns the integer part of a numberTO_UPPER(text)converts letters to uppercaseMID(text, start, length)returns a section of a stringNUM_TO_STR(number)converts a numeric value into a stringMODreturns 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_UPPERandMID - Boolean logic with
ANDandNOT - remainder and type conversion with
MODandNUM_TO_STR
Approach
Take each expression one stage at a time.
- Evaluate the innermost part first.
- Apply any function to that result.
- 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:
Then add 1:
Now apply INT.
For a positive number, INT removes the fractional part, leaving:
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.
INTremoves the fractional part.MIDuses a start position and length, and string positions are 1-based.NOTchangesFALSEtoTRUEand vice versa.MODgives a remainder.NUM_TO_STRchanges a numeric result into text.
Common Mistakes
- Writing
10for the first expression by applyingINTtoo early to31 / 3before adding 1. - Using 0-based indexing for
MIDand getting the wrong substring. - Forgetting to apply
TO_UPPERbefore taking the substring. - Writing
0instead of"0"forNUM_TO_STR(27 MOD 3), which loses the fact that the final result is a string. - Evaluating
TRUE AND (NOT FALSE)asFALSEby mishandlingNOT.
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.
INTis applied after the whole bracketed expression is found.MODdoes not mean division result; it means remainder.- When a conversion function is used, make sure your final answer matches the converted form.
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