Topic 4 - P1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 81

Paper 1 Paper 2 Paper 3 All levels

Question 1 SL

Compilers translate source code into object [2]


code. Identify two other operations
performed by a compiler.
Question 2 SL

Outline the need for higher level languages. [2]


Explain two benefits of using sub- [4]
procedures within a computer program.
Identify three characteristics of a collection. [3]
Collection `NUMBERS`already exists and stores [6]
real numbers.
Construct in pseudocode an algorithm, using
the access methods of a collection, which
will iterate through the collection
`NUMBERS`and count how many elements
stored in the collection are in the interval
[−1,1].
The final answer should be output.
Question 3 SL

A company has expanded its office space into


nearby rooms and has decided to set up a local
area network (LAN) to support its operations.
The LAN will connect the room where the server is
installed to new computers in the additional office
space. The network engineer produced the
following Gantt chart for this task.

Define the term concurrent processing. [1]


Identify two tasks that will be carried out [1]
concurrently.
Identify two tasks that will be carried out [1]
sequentially.
After 5 years the company decided to [4]
replace the LAN with a wireless local area
network (WLAN).
Outline two advantages, to this company, of
installing a WLAN.
A WLAN will introduce additional security [4]
issues for the company.
Discuss any two of these issues and the
ways in which the company might resolve
them.
The company is considering expanding their [4]
network to allow employees to connect from
anywhere in the world. The expanded
network would need to provide security and
allow the employees full functionality of the
internal network.
Explain how setting up a virtual private
network (VPN) would provide a suitable
solution.
Question 4 HL

Images in computers are stored as two-dimensional


arrays.
A black-and-white image (Figure 1) is stored as a 10
× 10 two-dimensional array named MAT (Figure 2).
Each element of MAT holds a number for a colour; 1
represents the colour black and 0 represents the
colour white.

In an application, the black-and-white image can be


inverted (all white pixels are changed to black, and
all black pixels are changed to white).
Method `invert(N,A)`accepts a positive integer
`N`and an `N × N`two-dimensional array `A`that
holds the data for a simple black-and-white image;
it returns the inverted `N × N`two-dimensional array
`A`.

In the application, it is also possible to rotate an


image clockwise by 90 degrees (90°).
For example, when the simple black-and-white
image is rotated, the corresponding 10 × 10 two-
dimensional array MAT is updated.
This would mean the first row of the original MAT is
the last column in the rotated MAT, the second row
is the second-to-last last column, … and the last
row is the first column.

Consider the following algorithm fragment:


K=input()
loop for M=0 to K mod 4 - 1
A=rotate(N,A)
end loop
where:
`N`is an integer and `A` is the `N × N`two-

dimensional array that holds data about an


image
`K(K>=0)`is an integer showing how many times
the image should be rotated
method `rotate(N,A)`accepts an integer `N`and
an `N × N`two-dimensional array
`A`representing an image. It returns an `N ×

N`two-dimensional array representing the


image rotated clockwise by 90°.
The algorithm for method `rotate(N,A)`uses an
additional `N × N`two-dimensional array, named

The `N × N`dimensional array `B`is initialized and


updated using the values from `A`to represent the
image rotated clockwise by 90°.
Construct an algorithm in pseudocode for [3]
the method `invert(N,A)`.
State the number of degrees by which the [1]
image will be rotated if the input value of `K`
is 3.
Outline why it is more efficient that the loop [2]
in the given algorithm fragment executes `(K
mod 4)`times instead of `K`times. You may
give an appropriate example in your answer.
Construct the algorithm in pseudocode for [3]
the method `rotate(N,A)`described above.
To avoid inefficient use of memory, a new [6]
algorithm for the method `rotate(N,A)`is
constructed.
The `N × N`two-dimensional array `A`should
be rotated clockwise by 90°, without the use
of any additional arrays.
One way of rotating the two-dimensional
array `A`clockwise by 90° is to transpose
`A`, and then reverse each row of `A`.

The transpose of `A`is formed by turning all


the rows of `A`into columns. For example,
the value in the first row and third column
(`A[1][3]`)is swapped with the value in the
third row and first column (`A[3][1]`).
Construct the new algorithm in pseudocode
for the method `rotate(N,A)`described
above.
Question 5 HL

A transport authority is investigating how many


people use a certain direct train route.
At the end of each day, the total number of
passengers who travelled on this route is stored in
a collection, `PASSENGERS`.
The first item was written to the collection on
Monday 1st May 2017.

The next items, collected on Tuesday and


Wednesday, were added like this:

Data for 30 complete weeks was added to the


collection.
Construct pseudocode that will read [4]
`PASSENGERS`into the two-dimensional array,
`2D_ARRAY`.

Construct the pseudocode for the [4]


procedure `total`, that takes as input a
column number of this two-dimensional
array and returns the sum of the elements in
that column.
The transport authority wishes to know how [3]
many passengers, on average, travel on
each day of the week.
Using the procedure `total`construct the
pseudocode to output the day of the week
with the highest average number of
passengers, and the value of this average.
You should make use of the sub procedure
`convert()`which converts the numbers0 to
6 into days of the week, for example
`convert(1)`will return “Tuesday”.

The transport authority stores details about [7]


the ticket prices in a one-dimensional array,
`FEES`, where `FEES[0]` contains the price of
a ticket for Monday to Friday, while
contains the price of a ticket for
`FEES[1]`
Saturday and Sunday.
The procedure `salesCalculate()`takes as
input the column and row indices that define
two specific days during the 30 weeks, and
outputs the total amount of money
generated from ticket sales between those
two days (inclusive).
Construct, in pseudocode, the procedure
`salesCalculate()`.
Question 6 HL

A number of devices in and around the home can


be operated by control systems.
A home owner wishes to install automatic lights to
illuminate a water fountain in her garden. These
lights will automatically turn on at sunset and turn
off at sunrise.
Describe two hardware components that [4]
would be an essential part of this control
system.
Explain the concept of feedback, with [3]
respect to computer control systems in
general.
The home owner has also installed a control [5]
system that waters the flowerbeds in the
garden. This system aims to maintain the
water content of the flowerbeds between a
minimum and a maximum value. However,
the system is only activated when the light
intensity is below a certain level.
Outline the algorithm involved in controlling
the watering system described above.
Question 7 SL

Distinguish between a variable and a [2]


constant.
Question 8 SL

List the output from the given algorithm for [3]


the following input.
2, 6, 8, 9, 12, 15, 18, 20
loop for Count from 0 to 7
input NUMBER
if NUMBER div 2 = NUMBER / 2 then
if NUMBER div 3 = NUMBER / 3 then
output NUMBER
end if
end if
end loop
Question 9 SL

A school teacher decides to write a program to


store class records and marks. Part of this program
involves using a sort algorithm. The algorithm
shown is a selection sort and to test it, the teacher
has set up an array`VALUES[]` with 5 elements of
test data.
LIMIT = 4
loop COUNTER1 from 0 to LIMIT – 1
MINIMUM = COUNTER1
loop COUNTER2 from COUNTER1 + 1 to LIMIT
if VALUES[COUNTER2] < VALUES[MINIMUM] then
MINIMUM = COUNTER2
end if
end loop
if MINIMUM ≠ COUNTER1 then
TEMPORARY = VALUES[MINIMUM]
VALUES[MINIMUM] = VALUES[COUNTER1]
VALUES[COUNTER1] = TEMPORARY
end if
end loop

Identify two variables that have been used in [1]


the algorithm.
Copy and complete the table below to trace [5]
the algorithm using the data set:
20, 6, 38, 50, 40

With reference to the algorithm in the flow [3]


chart, construct this algorithm in
pseudocode so that it performs the same
function.
State the type of sort in the algorithm [1]
constructed in c(i).
Construct an algorithm fragment to output [2]
the data in the array`VALUES[].`
The sorting algorithm could be part of a [3]
sub-program within a larger program.
Explain the benefits of using sub-programs
when constructing a larger program.
Question 10 SL

Two fundamental operations of a computer [2]


are add and retrieve. State another two
fundamental operations.
Question 11 SL

Construct a trace table for the following [4]


algorithm
A=3
B=7
loop while B >= A
A=A+1
output(B − A)
B=B−1
end loop
Question 12 HL

A group of programmers are involved in creating a


new software product. They create many new sub-
programs but also use existing sub-programs within
the product.
Outline why a sub-program is considered an [2]
example of abstraction.
Evaluate the use of designing and [3]
developing different parts of software
products concurrently.
Outline one way in which users can be [2]
informed of software updates.
Question 13 HL

An oil and gas company has a networked computer


system for use of their employees in the Head
Office.
The company also uses the internet to enable
communication with employees working on
exploration and production in many remote
geographical areas.
The sub-sea oil and gas exploration and production
unit of the company relies on thousands of
kilometres of pipeline which are monitored by a
computer control system which can detect leaks.
The process of detecting leaks is carried out by
sensors which are continuously monitoring changes
in the flow and pressure of the liquids in the pipes.
This data is processed on a computer in the office.
If any of sensor values are outside of the
acceptable parameters stored on a disk in the
office, the following error routines are performed:
an alarm is sounded on the computer at the
office
an email message is sent to managers in the
Head Office.
Identify one hardware security measure that [1]
will ensure that confidential data from the
Head Office cannot be accessed.
Identify one software security measure that [1]
will ensure that confidential data from the
Head Office cannot be accessed.
Identify one network security measure. [1]
Explain the environmental benefit of using a [3]
computer control system to monitor the
pipeline.
Explain the relationship between sensors, [4]
output transducers and processor in this
situation.
Construct a system flowchart to represent [5]
the process described above.
Question 14 HL

Assume X = 5, Y = 3 and A = TRUE. [2]


Determine the value of the following
expression:
((X>5)XORA)AND(Y+2>4)
Show all your working.
Question 15 SL

Describe the steps involved in using the [4]


bubble sort algorithm to sort an array.
Question 16 SL

The following flowchart represents a standard


algorithm:
Copy and complete the table that traces the [4]
algorithm in the flowchart using an input
value of 19.

State the purpose of the algorithm. [1]


Construct the algorithm from the flowchart [6]
using pseudocode. Add additional
pseudocode to ensure that input is validated
to only allow positive integers to be entered.
Efficiency is an important consideration [4]
when designing algorithms to ensure they
don’t waste computer resources such as
memory or processing time.
Suggest two design considerations that
could be made to an algorithm that would
make it more efficient.
Question 17 SL

Consider the following algorithm. [3]

Determine the outputs that will be produced


by this algorithm.
Question 18 SL

A school has 100 students. All student names


(strings) and student ID numbers (five-digit
integers) are held in two separate one-dimensional
arrays named `SID`and `SNAMES`.

For example, student Pia Baranger has ID number


11876.
A binary search algorithm is not used to find a
particular name in array`SNAMES`.
The school offers its sporting program to students
and has a basketball team, a tennis team and a
football team. Each student must choose at least
one of these three sports.
Three collections,`BASKETBALL, TENNIS` and
`FOOTBALL`, are created. When a student chooses a

sporting activity, their ID number is added to the


appropriate collection.
For example:
BASKETBALL={10011, 11876, 10122}
TENNIS={10011, 11876, 10002}
FOOTBALL={10011, 10002, 22103, 32000}
The method `isIn(X, COL)`is available, where:
`X`is a five-digit integer representing an ID

number
`COL`is a collection that holds student ID

numbers.
The method `isIn(X, COL)`returns `True`if the ID
number `X`is in the collection `COL;
False`otherwise.

For example:
`isIn(11876, BASKETBALL)` returns `True`
`isIn(11876, FOOTBALL)` returns `False`
The football and tennis training sessions are held at
the same time. The football coach would like to
know how many students will not be able to attend
the football training session because they will be
attending the tennis training session.
State the reason for not using a binary [1]
search.
Construct an algorithm in pseudocode for [4]
the method `isIn(X, COL)`.
Construct an algorithm in pseudocode that [3]
will output the number of students who have
chosen both tennis and football. The
method `isIn()`should be used in your
answer.
The school coordinator would like to check [7]
whether there are students who have not
yet chosen any one of the three sports.
Construct an algorithm in pseudocode that
will output the names of students who have
not yet chosen any one of the three sports.
An appropriate message should be
displayed if every student has chosen a
sport.
Question 19 SL

Identify two essential features of a computer[2]


language.
Question 20 SL

For an identified application, explain why a [3]


binary search would be preferred to a linear
search.
Question 21 SL

A school has a local area network (LAN) connecting


its computers and peripheral devices. The LAN also
provides access to the internet.
Users have been troubled by slow speeds when
accessing the internet.
Describe the role of a router in this network. [3]
Outline two reasons why there might be a [4]
reduction in data transmission speed at
certain times.
Outline two measures that the school could [4]
take to safeguard its data from unlawful
access via the internet.
The inventory of office supplies used in the [4]
school is stored on the computer as a single
file.
Each of the office supplies in the inventory
(such as paper, ink, toner, printers, pens,
staplers, pencils and scissors) has a unique
ID number, name, maximum quantity,
minimum quantity and remaining quantity.
Outline the steps in an algorithm that would
output a list of supplies with the quantity to
be ordered.
Question 22 HL

Reverse Polish notation (RPN) is a method used to


represent mathematical expressions so they can be
evaluated without the need for parentheses.
An expression written in this form is known as
postfix notation, whereas an expression written the
traditional way is known as infix notation.
For example:
Infix notation: `(8 − 5) * 7`
Postfix notation: `8 5 − 7 *`
Both the infix and postfix expressions have the
same result: 21
RPN expressions are evaluated from left to right as
follows:
Each character is checked,
if it is a digit, it is pushed onto a stack.
if it is a mathematical operator, the last two
digits are popped from the stack and
evaluated as though the current operator
was between them. The result of this
operation is then pushed back onto the
stack.
The process is repeated until all the characters
in the RPN expression have been used.
The value left in the stack is the result of the
expression.
A collection named RPN already stores an
expression formatted in Reverse Polish notation.
The algorithm reads the values from the collection
and, using a stack data structure, evaluates it.
RPN.resetNext()
loop while RPN.hasNext()
VALUE = RPN.getNext()
loop while not (VALUE = '+' or VALUE = '-' or VALUE
= '*' or VALUE = '/')
stack.push(VALUE)
VALUE = RPN.getNext()
end loop
OPERAND2 = stack.pop()
OPERAND1 = stack.pop()
if VALUE = '+' then
NEW_VAL = OPERAND1 + OPERAND2
stack.push(NEW_VAL)
end if
if VALUE = '-' then
NEW_VAL = OPERAND1 - OPERAND2
stack.push(NEW_VAL)
end if
if VALUE = '*' then
NEW_VAL = OPERAND1 * OPERAND2
stack.push(NEW_VAL)
end if
if VALUE = '/' then
NEW_VAL = OPERAND1 / OPERAND2
stack.push(NEW_VAL)
end if
end loop
RESULT = stack.pop()
output 'The result is: ', RESULT
An alternative data structure in which the
expression used in part (a) may be stored is a
binary tree. If the tree is traversed using postorder
tree traversal, the output is formatted in RPN.
Copy and complete the trace table for the [6]
algorithm using the RPN collection data:
`5 2 + 25 16 − * 3 /`

Explain why a stack is used in the process of [3]


evaluating the expression in the algorithm.
Outline the steps involved in traversing the [4]
given tree using postorder tree traversal.
State the output from the given tree using [2]
inorder tree traversal.
Question 23 SL

A company has 600 employees whose names are


currently stored using a collection called `NAMES`.
The names are stored as surname, first name. For
example: Smith, Jane, Uysal, Rafael, Ahmed,
Ishmael, Jonsonn, Sara, …
The names in the collection are kept in a random
order. However, it would be more useful if they were
kept in alphabetical order.
The company’s staff list is now organized in the
arrays in alphabetical order.
A binary search was used to find a specific name in
the array.
Construct a pseudocode algorithm that will [4]
store the surnames in one array and first
names in another.
Construct a pseudocode algorithm that will [5]
sort the surnames into alphabetical order
using the bubble sort method. The order of
the first names must also be changed so
that they keep the same index as their
corresponding surname.
Describe the process a binary search would [4]
follow to find a record in the surname array.
Outline one benefit of using sub- [2]
programmes to implement your algorithms
from parts (a) and (b).
Question 24 SL

Construct a trace table for the following [5]


algorithm.
K=1
N=1
M=2
loop while K < 5
output(N,M)
K=K+1
N=N+2
M=M*2
end loop
Question 25 SL

The array `DATA_ARR[]` is a one-dimensional array of


12 integers.

Algorithm 1 represents a method of searching the


array `DATA_ARR[]` to see if it contains a specific
value.
Algorithm 1
input TO_FIND
LIMIT = 11
LOC = FALSE
ITERATE = 0
loop while not LOC and ITERATE <= LIMIT
if DATA_ARR[ITERATE] = TO_FIND then
LOC = TRUE
end if
ITERATE = ITERATE + 1
end loop
if LOC then
output TO_FIND, 'is in the array'
else
output TO_FIND, 'is NOT in the array'
end if
Algorithm 2 represents an alternative method of
searching the array `DATA_ARR[]` to see if it contains
a specific value.
Algorithm 2
input TO_FIND
LOC = FALSE
LOW_LIM = 0
UP_LIM = 11
loop while LOW_LIM <= UP_LIM and LOC = FALSE
MID_VAL = (LOW_LIM + UP_LIM) div 2
if DATA_ARR[MID_VAL] = TO_FIND then
LOC = TRUE
else
if TO_FIND < DATA_ARR[MID_VAL] then
UP_LIM = MID_VAL - 1
else
LOW_LIM = MID_VAL + 1
end if
end if
end loop
if LOC = TRUE then
output TO_FIND, 'is in the array'
else
output TO_FIND, 'is NOT in the array'
end if
Copy and complete the trace table for [4]
Algorithm 1 using `TO_FIND = 39`.
The first value of the first row has been
done for you.

State the constant used in Algorithm 1. [1]


Copy and complete the trace table for [4]
Algorithm 2 using `TO_FIND = 50`.
The first two values of the first row have
been done for you.
Outline why `MID_VAL` could not be a [1]
constant.
Evaluate the use of a sequential search and [5]
a binary search including the advantages
and disadvantages of each.
Question 26 HL

The following flowchart is intended to represent an


algorithm in which numbers that are input cannot
be negative.
The flowchart contains a logic error that will affect
the algorithm’s functionality.
The algorithm is to be altered to restrict the values
that are input to whole numbers between 0 and
1000.
Identify the logic error in the algorithm. [1]
Outline how the error in the algorithm [2]
identified in part (i) can be corrected.
State the name of the method that could be [1]
used to restrict the values that are input.
A further change has been requested for the [8]
algorithm to enable it to calculate the
average of all the numbers entered. The
average will be output when the algorithm
terminates.
Based on the flowchart, construct this
algorithm using pseudocode. You must
include the required changes:
correction of logic error
only allow input of integers between 0
and 1000
calculation of average of all numbers
entered
output of final average.
Question 27 SL

Identify one fundamental operation of a [1]


computer.
Distinguish between fundamental and [2]
compound operations of a computer.
Question 28 SL

Outline the need for a translation process [2]


from high level language to machine code.
Question 29 SL

Explain why abstraction is required in the [3]


design of algorithms.
Question 30 SL

The following method, `calcBMI()`accepts person’s


height (H) in metres (m) and weight (W) in
kilograms (kg) and returns their Body Mass Index
(BMI).
calcBMI(H, W)
X=H*H
B=W/X
return B
endcalcBMI
Boris weighs 104 kg and is 2.00 m tall. His BMI can
be calculated by calling method `calcBMI()` as
follows
`BorisBMI = calcBMI(2.00, 104)`.

A person can belong to one of the following four


weight categories:
The data about a group of adults and their height
measurement (in metres) and weight measurement
(in kg) is held in three one-dimensional arrays.

Where
`NAME`is a one-dimensional array holding names
(currently sorted in alphabetical order).
`WEIGHT` is a one-dimensional array holding weight

measurement in kilograms.
`HEIGHT`is a one-dimensional array holding height
measurement in metres.
For example,
`NAME[0]`is Annie.

Her weight measurement is 52.40 kg and can be


found in `WEIGHT[0]`.
`HEIGHT[0]`is 1.56 which represents Annie’s height

measurement in metres.
State the value of variable `BorisBMI`. [1]
Use pseudocode to construct an algorithm [4]
which accepts a person’s BMI and outputs
the weight category the person belongs to.
State the name of the person whose height [1]
is held in `HEIGHT[3]`.
Identify one reason why a binary search [1]
algorithm cannot be used to find the name of
person whose height is given.
Describe how the name of person whose [2]
height is given could be output.
Construct an algorithm which will output the [6]
names of all the people whose BMI is
greater than this group’s average BMI.
You should call method `calcBMI()`in your
answer.
Question 31 SL

Consider the following algorithm, where [4]


`N`is a positive integer.

loop for K from 1 to N


loop for J from 1 to N
if K = J then
output K
end if
end loop
end loop
Question 32 SL

A teacher would like a simple program to store the


names, marks and grades of students in a set of
three parallel one-dimensional arrays called
`NAME[]`, `MARK[]`and`GRADE[]` .

The grade boundaries for the individual grades are


shown below:

The class has 30 students.


Identify two components in a conditional [2]
statement.
Construct an algorithm using pseudocode to [5]
take the marks that have been stored in
`MARK[]`, convert them into the appropriate
grade and store the calculated grades in
`GRADE[]`.

Outline how the name, mark and grade in [2]


the three arrays correspond to the same
student.
Construct an algorithm using pseudocode to [3]
output the names and grades of all students
who achieve a grade of Merit or Distinction.
Explain how you would change your [3]
algorithm in part (d) to allow a user to
choose a grade and output the names and
marks of the students who have achieved
this grade.
Question 33 SL

`NUMBERS` is a collection that holds only positive


integers.
A three-digit number has three digits: a hundreds
digit, a tens digit and a units digit.
For example, for 406, its hundreds digit is 4, its tens
digit is 0 and its units digit is 6.
An algorithm is needed to copy each three-digit
number from the collection `NUMBERS`, where the
hundreds digit is smaller than its tens digit and its
tens digit is smaller than its units digit, into a one-
dimensinal array named `THREE`. If there are no
such numbers in the collection then an appropriate
message should be displayed.
For example:
If`NUMBERS`=`{9, 3456, 12, 237, 45679, 368, 296}`
then the contents of the array,`THREE`, is:
If`NUMBERS`=`{1234, 56, 90, 324, 876}`
then the array `THREE`is empty and a message such
as “No such numbers”, should be outputted.
Consider the following algorithm. [3]
N = 372
X = N DIV 100
Y = X + 10 * (N MOD 100 DIV 10)
Z = Y + (N MOD 10) * 100
Determine the values of variables X, Y, and
`Z` after execution of this algorithm. Show

your working.
Construct this algorithm. You may assume [8]
that the array `THREE`is initialized with a
sufficient number of elements.
Describe how a selection sort algorithm [4]
could be used to sort the array `THREE`in
ascending order.
Question 34 HL

The flowchart below represents an algorithm that


allows a user to enter the number of sides, length
of side and apothem (see diagram below) for a
regular polygon. It then calculates and outputs the
area and perimeter of this shape.
Worked example: a regular hexagon
Number of sides = 6
Length of side = 10 cm
Apothem = 8.66 cm
Perimeter = Number of sides × Length of side
= 6 × 10
= 60 cm
Area =Perimeter×Apothem2
=60×8.662
= 259.8 cm2
From the flowchart, pseudocode is to be created
that will include sub‑programs to calculate and
return the perimeter and area of the shape.
Construct pseudocode for the body of the [2]
following sub-program to calculate and
return the perimeter of the shape.
SUB_PERIMETER(NUM_SIDES,
LENGTH_SIDE)
// Pseudocode to be added
end SUB_PERIMETER
Construct a similar sub-program to the one [4]
in part (i) to calculate and return the area of
the shape.
You must use an appropriate name for the
sub-program and appropriate names for the
parameters.
Construct pseudocode based on the [5]
flowchart to collect input from the user, call
the sub-programs created in parts (i) and
(ii), and output the results.
Without using pseudocode, explain how [4]
your algorithms could be altered to also find
the area and circumference of a circle.
Note:
Area of circle = πr2
Circumference of circle = 2πr
Question 35 HL

A school teacher decides to write a program to


store class records and marks. Part of this program
involves using a sort algorithm. The algorithm
shown is a selection sort and to test it, the teacher
has set up an array`VALUES[]` with 5 elements of
test data.
LIMIT = 4
loop COUNTER1 from 0 to LIMIT – 1
MINIMUM = COUNTER1
loop COUNTER2 from COUNTER1 + 1 to LIMIT
if VALUES[COUNTER2] < VALUES[MINIMUM] then
MINIMUM = COUNTER2
end if
end loop
if MINIMUM ≠ COUNTER1 then
TEMPORARY = VALUES[MINIMUM]
VALUES[MINIMUM] = VALUES[COUNTER1]
VALUES[COUNTER1] = TEMPORARY
end if
end loop

Copy and complete the table below to trace [5]


the algorithm using the data set:
20, 6, 38, 50, 40

With reference to the algorithm in the flow [3]


chart, construct this algorithm in
pseudocode so that it performs the same
function.
State the type of sort in the algorithm [1]
constructed in b(i).
Construct an algorithm fragment to output [2]
the data in the array`VALUES[]`
Question 36 SL

A transport authority is investigating how many


people use a certain direct train route, which is
used every day of the week.
At the end of each day, the total number of
passengers who travelled on this route is stored in
a collection,`PASSENGERS`.
The first item was written to the collection on
Monday 1st January 2018.

The next items, collected on Tuesday and


Wednesday, were added like this:

The collection`DATA`contains the following [4]


data:
2, 4, 1, −2, −4, 1, 0
Consider the following pseudocode:
COUNTER = 0
SUM = 0
DATA.resetNext()
loop for X from 0 to 6
if DATA.getNext() > 0
ARRAY[X] = DATA.getNext()
COUNTER = COUNTER + 1
SUM = SUM + ARRAY[X]
end if
end loop
output SUM/COUNTER
Trace the pseudocode using the table
below:

Assuming that the first item read from the [4]


collection is from Monday 1st January 2018,
construct pseudocode that will read
`PASSENGERS`into an array, `P_ARRAY`.

Using `P_ARRAY`, construct pseudocode to [7]


output the day of the week with the highest
average number of passengers. Use the sub
procedure `convert()`which converts the
numbers 0 to 6 into days of the week, for
example `convert(1)`will return “Tuesday”.
Note: you should not assume that data for
an exact number of weeks is stored.
Question 37 HL

Outline what is meant by a sorting algorithm. [2]


Outline one difference between a bubble [2]
sort algorithm and a selection sort
algorithm.
Question 38 SL

A medical centre uses a computer system to


manage both patients’ data and appointments. This
system, which is used by the doctors, nurses and
secretaries, has two unordered files: a patients’ file
and an appointments’ file, both of which can only
be accessed sequentially.
Every evening the following processing takes place:
a list of appointments for the next day is
printed out
reminders are sent by SMS text messages to
the patients’ mobile devices.
Outline the pseudocode that the processing [5]
must follow when the system sends out the
text reminders.
Describe two different methods that the [4]
medical centre could use that would allow
data to be restored should it be lost for any
reason.
The medical centre is concerned about the [6]
privacy of the data it is storing and has to
make decisions concerning:
access to the data stored on this
system
storing the data locally or through the
use of a cloud service.
Discuss the issues that should be
considered before making these decisions.

You might also like