0% found this document useful (0 votes)
7 views

Topic_4-_Home_Assignment-_FA2

Uploaded by

Sahaj Khurana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Topic_4-_Home_Assignment-_FA2

Uploaded by

Sahaj Khurana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Subject: Computer Science HL/SL DP Year 2

Topic 4 Type: Formative Assessment 1I Max Marks: 30


Time allocated: 50 mins Time Taken: Date: August 21, 2024

1. Given the integer array DATA:

and the following algorithm:

K=5
A=1
B=0
while K >= 0
if DATA[K] mod 2 < 1
then
A = A * DATA[K]
else
B=B+1
end if
K=K-1
end while
output(A)
output(B)

(a) Deduce the purpose of this algorithm.

[2]

2. There are 1000 rooms where students can live on a college campus. The rooms are numbered
from 1 to 1000. The bill for each room must be paid each month.

The room numbers of the students who have paid their bills for the month of May so far are
stored in the ROOMNUMS array (see Figure 1).

Figure 1: Example data stored in the ROOMNUMS array

For example, the bill for room number 93 has been paid. This can be seen in ROOMNUMS[6].

(a) State two characteristics of a linear array. [2]


Figure 2 shows two examples of input and output for the data stored in the ROOMNUMS array
as given in Figure 1.

Figure 2: Examples of input and output

(b) Construct an algorithm in pseudocode for the sub-program check().

[5]

(c) Construct an algorithm in pseudocode to sort the ROOMNUMS array in ascending


order using the selection sort algorithm.

[6]

3. (a) The collection DATA contains the following 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:

[4]
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:

(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]

You might also like