Topic 4 - P1
Topic 4 - P1
Topic 4 - P1
Question 1 SL
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
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.
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
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