User interface language: English | Español

Date November 2020 Marks available 1 Reference code 20N.1.SL.TZ0.9
Level SL Paper 1 Time zone no time zone
Command term State Question number 9 Adapted from N/A

Question

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:

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 search.

[1]
a.

Construct an algorithm in pseudocode for the method isIn(X, COL).

[4]
b.

Construct an algorithm in pseudocode that will output the number of students who have chosen both tennis and football. The method isIn() should be used in your answer.

[3]
c.

The school coordinator would like to check 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.

[7]
d.

Markscheme

Award [1 max].

Because the array SNAMES is not sorted/ordered;

a.

Award [4 max].
Award [1] for initializing and returning/outputting flag;
Award [1] for a while loop;
Award [1] for correct comparison and updating flag;
Award [1] for the correct use of collection methods (resetNext(), hasNext() and getNext());

Example 1:

isIn(X,COL)
   PRESENT=False
   COL.resetNext()
   loop while COL.hasNext()and not PRESENT
     Y= COL.getNext()
      if X== Y
         then PRESENT=True
      end if
   end loop
   return PRESENT
end isIn

Example 2:

isIn(X,COL)
   P=0
   COL.resetNext()
   loop while COL.hasNext()
      if X== COL.getNext()
         then P=1
      end if
   end loop
   if P==1                              // NOTE: instead of if statement only
     then return True                   // the statement : return P==1
     else return False                  // may be written
   end if
end isIn

b.

Award [3 max].
Award [1] for initializing, updating and returning/outputting COUNT;
Award [1] for a while loop;
Award [1] for calling method isIn();
Award [1] for correct use of collection methods (resetNext(), hasNext() and getNext();

Example 1 (loop through collection FOOTBALL):

COUNT=0
FOOTBALL.resetNext()
loop while FOOTBALL.hasNext()
X== FOOTBALL.getNext()
if isIn(X,TENNIS)
then COUNT=COUNT+1
end if
end loop
output COUNT

Example 2 (loop through collection TENNIS):

COUNT=0
TENNIS.resetNext()
loop while TENNIS.hasNext()
if isIn(TENNIS.getNext(),FOOTBALL)
then COUNT=COUNT+1
end if
end loop
output COUNT
c.

Award [7 max].

Award [1] for the use of flag;
Award [1] for looping through the array SID;
Award [2] for correct use of logical operators not/and/or in if statement, 1 mark for minor error;
Award [1] for the correct call of method isIn();
Award [1] for outputting the name from the array SNAMES within the loop;
Award [1] for outputting message(if needed) after the loop;

Example 1:

FLAG=True
loop for K=0 to 99
if not( isIn(SID[K],FOOTBALL)or isIn(SID[K],BASKETBALL) or isIn(SID[K],TENNIS))
then
output SNAME[K]
FLAG=False
end if
end loop
if FLAG
output 'Each of the students is on at least one of the three teams'
end if

Note: the condition in if statement could be written as
not(isIn(SID[K],FOOTBALL))and not(isIn(SID[K],BASKETBALL))and not(isIn(SID[K],TENNIS))

Example 2:

Award [1] for the use of flag
Award [1] for looping through the array SID
Award [1] for nested if statements
Award [1] for correct logical expressions in each of these ifs
Award [1] for the correct call of method isIn()
Award [1] for outputting the name from the array SNAMES within the loop
Award [1] for outputting message(if needed) after the loop

X=1
loop for K=0 to 99
if not(isIn(SID[K],FOOTBALL))
then if not (isIn(SID[K],BASKETBALL))
then if not(isIn(SID[K],TENNIS))
then
output SNAME[K]
X=0
end if
end if
end if
end loop
if X==1
output 'Every student has chosen a sport'
end if
d.

Examiners report

Most candidates recognised that a binary search would only work with sorted data.

a.

Candidates were required to produce an algorithm for the method described in the question. Most candidates achieved some marks for this algorithm, but full marks were rare. The scenario involved the use of a collection, so collection methods were expected within the algorithm. Many candidates failed to demonstrate the use of collection methods.

b.

Candidates were required to construct a second algorithm involving the use of the method defined in part b. As with part b, the use of collection methods was also expected, but was often missing. Candidates who attempted the question, however, generally achieved some marks.

c.

A final algorithm was required based on the question scenario. Some candidates did not attempt this question. A small number of candidates achieved high marks by demonstrating good programming skills. However, a large number of candidates scored low marks for the construction of a partial solution or a solution that was partially correct.

d.

Syllabus sections

Topic 4: Computational thinking, problem-solving and programming » 4.2 Connecting computational thinking and program design
Show 59 related questions
Topic 4: Computational thinking, problem-solving and programming

View options