Ib Coding Questions SL Chapter 4
Ib Coding Questions SL Chapter 4
SECTION B
(a) Represent, as a single logical expression, the conditions that cause Harry to be tired. [3]
(b) Construct the truth table to show when Harry is tired. [4]
A professor notices that students are generally very tired and decides to investigate the
relationship of tiredness with Work, Hunger and Sun.
Consider the following truth table which shows the conditions for Tired based on Work,
Hunger and Sun.
W H S T
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
2214-7014
1 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–5– M14/4/COMSC/SP1/ENG/TZ0/XX
(Question 12 continued)
The conditions for one of the students to be tired can be expressed in the following array,
TIRED, where the index is equivalent to the combination of W, H and S in the truth table.
TIRED
[0] [1] [2] [3] [4] [5] [6] [7]
0 0 1 0 0 0 1 1
(c) Identify a relationship between the value of S and the index of the array TIRED. [1]
(d) Construct an algorithm, TEST, in pseudocode, to output the conditions W, H and S from
the array TIRED for a student who is tired. [4]
A collection, STUDENT, is used to hold the name and the array TIRED for each student.
(e) Outline the way in which your algorithm could be used to output the names of all those
students who are tired due to Work and Hunger. [3]
13. An international organization has offices located across several countries. For some of
its activities, for example human resource management, it has been decided to adopt a
“Software-as-a-Service” (SaaS) solution in order to keep the running costs low.
Each office makes some data available to external customers through the use of an extranet
and allows employees to work from home through a VPN.
14. The faceplate of a car stereo has six buttons for selecting one of six preferred radio stations.
As part of the internal representation of a microprocessor there is an array with six positions,
carrying the information about the radio frequencies, as follows.
Radio
[0] [1] [2] [3] [4] [5]
100.4 88.7 90.2 104.5 93.8 106.2
(b) Outline how a numerical frequency could be stored in a fixed-length string. [2]
A display in the faceplate shows the name and frequency of the selected radio station. The name
is automatically captured when storing a preference.
(d) Outline how a collection of objects could be used to store the name and frequency data in
the radio. [2]
(e) Construct an algorithm, in pseudocode, to access and display the name and frequency of
a station when a button is pressed. [4]
2214-7014
3 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–3– N14/4/COMSC/SP1/ENG/TZ0/XX
begin
K=3
P=1
No Yes
K>1
output P output K
K = K −1
P = P×K
end
Trace the algorithm and show the outputs that will be produced. [3]
NUMBERS
[0] [1] [2] [3] [4] [5]
(b) Construct the algorithm that will output the average of all values in the array NUMBERS. [4]
The method minPos() determines the index of the smallest value in an array.
The method maxPos()determines the index of the largest value in an array. For example,
NUMBERS.maxPos() is 3.
S=NUMBERS.minPos()
L=NUMBERS.maxPos()
T=NUMBERS[S]
NUMBERS[S]=NUMBERS[L]
NUMBERS[L]=T
(c) (i) Show the contents of the array NUMBERS after the algorithm is applied. [2]
8814-7014
5 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–2– M15/4/COMSC/SP1/ENG/TZ0/XX
Section A
2. Outline one example of the use of a virtual private network (VPN). [3]
4. Trace the following algorithmic fragment for N = 6. Show all working in a trace table.
SUM = 0
loop COUNT from 1 to (N div 2)
if N mod COUNT = 0 then
SUM = SUM + COUNT
end if
end loop
if SUM = N then
output "perfect"
else
output "not perfect"
end if [4]
5. Outline two usability features in relation to the characteristics of a new laptop. [4]
6. Describe one way that software developers can ensure that the users are aware of any
available updates for their products. [2]
7. Six students are planning their group 4 project, which is due in two days. They have to
produce a scientific report and give an animated computer presentation based on their
analysis of water samples. These water samples are to be taken from four local lakes.
(a) Based on this information, identify four tasks that should be done by the students,
listing the tasks in the order that they could be completed. [2]
(b) Outline how two of the tasks identified in part (a) could be completed concurrently. [2]
(c) Draw a Gantt chart to show the tasks from part (a), indicating the concurrency outlined
in part (b). You do not need to include the timings for the tasks. [2]
6 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–4– M15/4/COMSC/SP1/ENG/TZ0/XX
9. Six lawyers and one secretary work together in the same building and are connected via a
LAN to a central server. Each has their own workstation.
(a) Outline the concept of the Open Systems Interconnection (OSI) model in
communication across a network. [3]
The LAN has one server, which is connected to the internet. The workstations are connected
to the server by cable. There is also a wireless connection.
(c) Outline one advantage and one disadvantage of allowing wireless access to the server. [4]
Print jobs are sent to a shared printer from all workstations and added to the print queue
in the order in which they are sent. A priority is given to each job based on the number of
pages requested.
• The lowest priority (4) is given to jobs with more than 50 pages.
The jobs sent to the printer are held in a collection of objects. Each object includes the
priority that has been given and the time it was sent to be printed.
If any job has been waiting more than 10 minutes it is moved to the front of the queue and is
the next to be printed.
(d) Outline the steps needed to search the collection and return the next job to be printed. [5]
10. (a) Identify two differences and two similarities between a bubble sort and a selection sort
when sorting an array of 10 elements. [4]
A cycling tour lasts for 15 days. The total time for each competitor is recorded in a
one-dimensional array, TIMES[]. After each day’s race, the array entry for each competitor
is increased by their time for that day.
There are 150 competitors and the 10 fastest times are transferred to the array FASTEST[]
and displayed on a screen each day.
(b) Explain why a selection sort would be more efficient than a bubble sort in this case. [2]
(c) Construct an algorithm to transfer the 10 fastest times from the array TIMES[] to the
array FASTEST[]. Assume that the array TIMES[] is not sorted. [6]
The race organizers need to display the names of the 10 fastest competitors, as well as
their times, on the screen. There is another array, NAMES[], which contains the names of
all competitors in the same order as their times in TIMES[] (for example, NAMES[5] and
TIMES[5] are the name and time of the same competitor).
(d) Compare the use of two arrays, to hold the competitor’s times and names, with the use
of objects. [3]
7 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–3– N15/4/COMSC/SP1/ENG/TZ0/XX
6. A sub-program all_even() accepts a positive integer N and outputs true if all digits of N
are even, otherwise it outputs false. For example, all_even(246) outputs true and
all_even(256) outputs false.
(a) Explain why this algorithm does not obtain the correct result. [2]
(b) Outline what should be changed in the algorithm to obtain the correct result. [3]
Turn over
8 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–6– N15/4/COMSC/SP1/ENG/TZ0/XX
9. A candy company manufactures 20 different kinds of candy, each identified by a product ID.
An array, Product_ID, is used to store the product IDs, and another array, Unit_Price, is
used to store the price per unit of each type of candy. The unit price of the product identified
by Product_ID[N] is equal to Unit_Price[N] for any index N.
Product_ID Unit_Price
Mints-1A [0] 15.20
Choco-1B [1] 18.10
Jelly-1Q [2] 16.30
…
Choco-2A [19] 11.90
(b) Explain the steps that would be needed in an algorithm to calculate the average unit
price. [3]
(c) Construct the algorithm that will output the price of a candy after its product ID is
entered by the user. The algorithm should output an appropriate message if the
product ID entered does not appear in the array Product_ID. [6]
The company maintains two warehouses each of which stocks a selection of the 20 types of
candy indicated above.
The first warehouse stocks 15 items and their IDs are stored in an array, One. The second
warehouse stocks 10 items and their IDs are stored in an array, Two.
All product IDs common to both warehouses will be placed in an array, Three.
(d) (i) State the maximum number of common product IDs which can be placed
in Three. [1]
(ii) Construct the algorithm that will place all product IDs common to both
warehouses in Three. [4]
9 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–3– M16/4/COMSC/SP1/ENG/TZ0/XX
10. Trace the following fragment, for N=139 and L=3, by copying and completing the trace table given
below.
D = N div L
Z = 1
B = false
D Z B Z<L ? output
… … … … …
[4]
Turn over
10 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–6– M16/4/COMSC/SP1/ENG/TZ0/XX
13. A local charity organizes a half-marathon to raise money. The rules to participate in the
half-marathon are as follows:
� Participants belong to a team and each team must have at least three and at most five
participants
� Each participant registers for the event independently from the other members of their
team, and they all declare their team name when registering
� For scoring, the team’s final time is the sum of the times of its three fastest participants.
Participants that do not cross the finishing line within 2 hours after the start, are assigned
a default time of 1000 minutes. The winning team is the team with the smallest sum total.
During registration, an array, PARTICIPANTS, with 450 positions is used to hold the
abbreviated team names that are declared by each participant. Simultaneously, a collection
TNAMES is generated: any new team name that is declared is added to the collection.
(a) State the minimum size of TNAMES to ensure the names of all potential teams can
be stored. [1]
Part of the array PARTICIPANTS is shown below, where, for example, the first participant
declared that they are part of team TK. The initial part of the collection TNAMES is also shown,
with arrows indicating the direction of growth.
PARTICIPANTS
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] …
TK W AC TK W TK AC W TK TK AC QA AC W AC …
TNAMES
TK W AC QA …
Both PARTICIPANTS and TNAMES are used to construct the array, TEAM, that groups all
participants who belong to the same team. Part of the array TEAM is shown below.
TEAM
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] …
3 4 6 5 7 8 10 13 9 0 12 73 14 15 2 …
In TEAM, each element is related to one other index in the array, shown by the arrows on the
above diagram. This relation will eventually form a closed path (for this example 0, 3, 5, 8, 9
and back to 0). The relation reflects the information in PARTICIPANTS, by grouping people
who declared the same team name during registration.
Hence, participants 0, 3, 5, 8 and 9 are on the same team and, from PARTICIPANTS, that team
is TK.
11 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–7– M16/4/COMSC/SP1/ENG/TZ0/XX
(Question 13 continued)
(b) Identify the position in PARTICIPANTS of the second participant that registered for
team QA.[1]
Part of the algorithm that generates the TEAM array is shown below, in pseudocode.
TNAMES.resetNext()
loop while TNAMES.hasNext()
CURRENT = TNAME.getNext()
T = 0; P = 0; MINP = 0 // variables’ initialization
//*
//* Code to be completed in part (c)(i)
//*
//* Code to be completed in part (c)(ii)
//*
end loop
output TEAM
(c) In order to complete this code, and return the correct TEAM array,
(i) construct pseudocode to find MINP, the first index in PARTICIPANTS of the
CURRENT team, and use it to start the construction of TEAM[3]
(ii) construct pseudocode to find the other participants belonging to the CURRENT
team, implementing the idea of the closed paths in the TEAM array. [4]
As part of the program to determine the winning team, an array, TIMING, is maintained in
parallel to PARTICIPANTS. For example, TIMING[5] and PARTICIPANTS[5] relate to the
same participant.
TIMING is initialized to zero before the race starts, and updated with the finishing times for
each participant. The algorithm sum3best is able to output the sum of the three fastest times
from any group of times that are passed to the algorithm.
(d) Describe the steps of an algorithm that will find the winning team, as defined by the
marathon rules on page 6. Clearly mention the use of existing or of new data structures. [6]
12 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–3– N16/4/COMSC/SP1/ENG/TZ0/XX
6. Consider the following algorithm that inputs X and N, and outputs P.
X,N
P=1
P P=P*X
N=N-1
(a) Determine how many times multiplication is performed when the algorithm is executed. [1]
(b) Construct a trace table for the algorithm when X=2 and N=4. Use the following
headings in your table.
X N P N>0 output
[4]
(c) State the purpose of the algorithm. [1]
Turn over
13 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–5– N16/4/COMSC/SP1/ENG/TZ0/XX
(a) Identify two reasons why consistent grammar and syntax should be essential features
of a higher level programming language. [2]
(b) Identify two features of a user interface that will allow application programmers to
interact more easily with the programming language. [2]
Application programmers who use this programming language will be able to choose to use
either an interpreter or a compiler.
One of the predefined sub-programs in the new language is sumOdd(). It accepts an integer
N as input. If N<=0 it outputs -1, otherwise it outputs the sum of the first N odd numbers.
For example:
sumOdd(4) outputs 16, because 4 is not less than 0, and 1 + 3 + 5 + 7 = 16.
sumOdd(−3) outputs −1, because −3 is less than 0.
(f) Outline the need for predefined sub-programs and collections. [2]
Turn over
14 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–6– N16/4/COMSC/SP1/ENG/TZ0/XX
10. In a school there are 2400 students and each student uses one locker. Each locker has a unique
number from 1 to 2400.
The lockers are to be painted in four colours: red, white, yellow and blue, in order of locker
numbers, as shown in the following table.
Locker
1 2 3 4 5 6 7 8 … 2399 2400
Number
Colour red white yellow blue red white yellow blue … yellow blue
The pattern of colours continues in this manner. For example, locker number 15 will be
painted yellow.
(a) State the colour that locker number 442 will be painted. [1]
Each student is responsible for painting his or her locker. Some students do not know how
to determine the colour they should use.
For example STUDENT_NAME[1] is Sarah Anner. She is responsible for locker number 1256
and this locker has not been painted yet.
(c) (i) State the name of the student who is responsible for painting locker number 811.[1]
(ii) Construct, in pseudocode, an algorithm that counts and outputs the number of
lockers that have been painted so far.[4]
(d) Describe an efficient algorithm, which accepts a student’s name as input, and outputs
the corresponding locker number and whether or not it has been painted. [4]
15 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–4– M17/4/COMSC/SP1/ENG/TZ0/XX
12. (a) By copying the table below, trace the following algorithm using the data in the
collection DATA. Note: B and C are also collections and are initially empty.
DATA = {2,4,-1,3}
loop while DATA.hasNext()
A = DATA.getNext()
if A >= 0 then
if A mod 2 = 0 then
B.addItem(A)
else
C.addItem(A)
end if
end if
end loop
Contents Contents
DATA.hasNext() ? A A >= 0? A mod 2 = 0?
of B of C
[3]
(b) Outline the steps involved in performing a binary search on an array of ascending
numbers. Note: you can assume that the search value is present in the array and that
initially LOW is the index of the first value in the array and HI is the index of the last value. [4]
(c) A collection called NUMBERS is to be searched to see if it contains a specified value.
Construct an algorithm in pseudocode to perform the following:
yyinput the number, S, to be searched for
yyread in the values from the NUMBERS collection into the array D. Note: you can
assume that the array is large enough and that the collection is not empty
yyperform a linear search for S on the array D
yyoutput the message “found ” or “not found ” as appropriate. [5]
A binary search can be performed on the array D, if the values in D are in ascending order.
As the values are being read from NUMBERS into D they are checked to see if they are in order.
(d) Without writing pseudocode, suggest how this check could be performed. [3]
16 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–3– N17/4/COMSC/SP1/ENG/TZ0/XX
(a) Determine the number of times the comparison K = J will be performed. [1]
(b) Determine the number of times the statement output K will be executed. [1]
(c) Construct the algorithm which performs the same task using a single while loop,
instead of nested for loops. [4]
8. The machine instruction cycle is the process by which a program instruction is fetched,
decoded, executed and the results are stored.
(a) State where all instructions and data are stored. [1]
(b) Outline the role of the data bus and address bus in this process. [2]
Turn over
17 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–6– N17/4/COMSC/SP1/ENG/TZ0/XX
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
P S E U D O C O D E
(b) Consider the following algorithm. The function len() returns the number of characters
in an array (for example, len(S) is 10).
K = 0
CL = 0
loop while K < len(S)
if S[K] = "E" then
CL = CL + 1
end if
K = K + 1
end loop
output CL
For this algorithm, copy and complete the following trace table. [4]
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10][11][12][13][14][15][16][17][18][19][20][21][22][23][24][25]
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10][11][12][13][14][15][16][17][18][19][20][21][22][23][24][25]
F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
(c) Construct an algorithm which creates the array SUBSTITUTE. You may assume that a
positive integer N and array UPCASELETTERS are given. [5]
18 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–7– N17/4/COMSC/SP1/ENG/TZ0/XX
(Question 13 continued)
The following algorithm fragment inputs the characters, one by one, from the input sentence,
and outputs its cryptogram using the method encode().
The method encode() accepts a character CH and two arrays UPCASELETTERS and
SUBSTITUTE, as defined above, and returns the corresponding character CRYPTEDCH of the
character CH.
(d) Explain the steps to construct an algorithm for the method encode(). [5]
19 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–3– M18/4/COMSC/SP1/ENG/TZ0/XX
Begin
K = 47
N = 10
YES NO
K mod N < 3
Output K Output K
End K = K div 2
Turn over
20 / 21
compiled by www.ibtutorials.com
Vinod Mishra
www.ibtutorials.com +91 9768363526, Mumbai, India
Process to an Easy 7
–6– M18/4/COMSC/SP1/ENG/TZ0/XX
2, 4, 1, −2, −4, 1, 0
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
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.
212
The next items, collected on Tuesday and Wednesday, were added like this:
(b) Assuming that the first item read from the collection is from Monday 1st January 2018,
construct pseudocode that will read PASSENGERS into an array, P_ARRAY.[4]
(c) Using P_ARRAY, construct pseudocode to 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. [7]
21 / 21
compiled by www.ibtutorials.com