Algorithms (1)
Algorithms (1)
Exam Questions
Algorithms
Designing Algorithms / Explaining Algorithms
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Medium Questions
1 Describe what the algorithm represented by the flowchart is doing.
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
(2 marks)
2 The pseudocode algorithm shown has been written by a teacher to enter marks for the
students in her class and then to apply some simple processing.
Count ← 0
REPEAT
INPUT Score[Count]
IF Score[Count] >= 70
THEN
Grade[Count] ← "A"
ELSE
IF Score[Count] >= 60
THEN
Grade[Count] ← "B"
ELSE
IF Score[Count] >= 50
THEN
Grade[Count] ← "C"
ELSE
IF Score[Count] >= 40
THEN
Grade[Count] ← "D"
ELSE
IF Score[Count] >= 30
THEN
Grade[Count] ← "E"
ELSE
Grade[Count] ← "F"
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
Count ← Count + 1
UNTIL Count = 30
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
(3 marks)
3 B ← FALSE
INPUT Num
FOR Counter ← 1 TO 12
IF A[Counter] = Num
THEN
B ← TRUE
ENDIF
NEXT Counter
(1 mark)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
4 (a) The flowchart shows an algorithm that should allow 60 test results to be entered into the
variable Score.
Each test result is checked to see if it is 50 or more. If it is, the test result is assigned to
the Pass array. Otherwise, it is assigned to the Fail array.
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
(6 marks)
(b) Write a pseudocode routine that will check that each test result entered into the
algorithm is between 0 and 100 inclusive.
(4 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
5 The pseudocode represents an algorithm.
The pre-defined function DIV gives the value of the result of integer division. For example,
Y = 9 DIV 4 gives the value Y = 2
The pre-defined function MOD gives the value of the remainder of integer division. For
example, R = 9 MOD 4 gives the value R = 1
First ← 0
Last ← 0
INPUT Limit
FOR Counter ← 1 TO Limit
INPUT Value
IF Value >= 100
THEN
IF Value < 1000
THEN
First ← Value DIV 100
Last ← Value MOD 10
IF First = Last
THEN
OUTPUT Value
ENDIF
ENDIF
ENDIF
NEXT Counter
(2 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
6 (a) This algorithm checks the temperature of hot food being served to customers.
State how the final output from the algorithm could be improved.
(1 mark)
(1 mark)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8
7 This flowchart represents an algorithm.
(2 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 9
8 The variables P and Q are used to store data in a program. P stores a string. Q stores a
character.
Give the value of Position after the algorithm has been executed with the data in the
below question.
Write pseudocode statements to declare the variables P and Q, store "The world" in P
and store 'W' in Q
(1 mark)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 10
Hard Questions
1 Describe the purpose of the algorithm.
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 11
(2 marks)
X stores a string
extract the word fun from the string and output it.
(6 marks)
3 The one-dimensional (1D) array StudentName[] contains the names of students in a class.
The two-dimensional (2D) array StudentMark[] contains the mark for each subject, for each
student. The position of each student’s data in the two arrays is the same, for example,
the student in position 10 in StudentName[] and StudentMark[] is the same.
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 12
The variable ClassSize contains the number of students in the class. The variable SubjectNo
contains the number of subjects studied. All students study the same number of
subjects.
The arrays and variables have already been set up and the data stored.
calculates the combined total mark for each student for all their subjects
calculates the average mark for each student for all their subjects, rounded to the
nearest whole number
name
average mark
grade awarded
calculates, stores and outputs the number of distinctions, merits, passes and fails
for the whole class.
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 13
You must use pseudocode or program code and add comments to explain how your
code works.
(15 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 14
4 (a) Draw a flowchart for an algorithm to:
output the count of positive numbers when zero is input and end the algorithm.
(6 marks)
(b) Explain the changes you will make to your algorithm to also count the negative
numbers.
(2 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 15
5 A function LENGTH(X) finds the length of a string X and a function SUBSTRING(X,Y,Z) finds a
substring of X starting at position Y and Z characters long. The first character in the string
is position 1.
Show the value of the variable after each pseudocode statement has been executed.
03 R ← SUBSTRING(P,10,7) .............................................................
04 S ← LENGTH(R) ......................................................................... ..
05 T ← SUBSTRING(R,1,3) .................................................................
(5 marks)
B ← FALSE
INPUT Num
FOR Counter ← 1 TO 12
IF A[Counter] = Num
THEN
B ← TRUE
ENDIF
NEXT Counter
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 16
(4 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 17
7 The names of patients are stored in the one-dimensional (1D) array Patient[] of type
string. A separate two-dimensional (2D) array Readings[] stores the latest data recorded
about each patient. The array already contains the readings taken by a nurse for each
patient:
The hospital number given to the patient is used for the index on both arrays, this is a
value between 1 and 1000 inclusive.
When the data for a patient is checked a warning is given if any of the readings are out of
range.
If both readings are out of range, then a severe warning is given.
Write a procedure, using pseudocode or program code, that meets the following
requirements:
outputs an error message and exits the procedure if the number is not valid
output ‘Warning’ and the name of the reading e.g. ‘Pulse’ if one reading is out of
range
output ‘Severe warning’ and the names of the two readings ‘Pulse and
temperature’ if both readings are out of range
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 18
You must use pseudocode or program code and add comments to explain how your
code works.
(15 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 19
8 An algorithm has been written in pseudocode to allow some numbers to be input. All the
positive numbers that are input are totalled and this total is output at the end. An input
of 0 stops the algorithm.
01 Exit 1
02 WHILE Exit <> 0 DO
03 INPUT Number
04 IF Number > 0
05 THEN
06 Total Total + Number
07 ELSE
08 IF Number = 0
09 THEN
10 Exit 0
11 ENDIF
12 ENDIF
13 ENDWHILE
14 OUTPUT "The total value of your numbers is ", Total
Describe how you could change the corrected algorithm to record and output how
many positive numbers have been included in the final total.
(4 marks)
© 2024 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 20