2020 HKACE Mock ICT 2D Eng

You might also like

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

Please stick the label here.

THE HONG KONG ASSOCIATION FOR COMPUTER EDUCATION

INFORMATION AND COMMUNICATION TECHNOLOGY

MOCK EXAMINATION 2020 Candidate Number

PAPER 2D
Software Development

Time Allowed: 11:15 am – 12:45 am


(1 hour 30 minutes)
This paper must be answered in English. Marker’s Use Only

Question No. Marks


INSTRUCTIONS
(1) After the announcement of the start of the examination,
1
you should stick the label in the space provided on Page
2
1.

(2) Tick the appropriate box for the programming language 3


used. No marks will be awarded if you tick either
4
more than one box or no boxes.

Total
(3) ANSWER ALL QUESTIONS. Write your answers in the
spaces provided in this Question-Answer Book. Do not
write in the margins.

(4) Supplementary answer sheets will be provided on


request. Write your candidate number and question
number on each sheet.

(5) No extra time will be given to candidates for filling in


candidate number and question number after the
‘Time is up’ announcement.

© 香港電腦教育學會 保留版權
THE HONG KONG ASSOCIATION FOR COMPUTER EDUCATION
All Rights Reserved 2020

HKACE-ICT MOCK EXAM 2020-2D 1


Answer all questions.

1. Peter is designing the new airport runway system. The tasks include Land Formation and Marine Works, Airfield
Facilities, Aprons Works, Runway Passenger Building, Automated People Mover System, Baggage Handling System,
Airport Support Facilities and Public Facilities. Peter uses Gantt Chart to organize and monitor the progress.

(a) (i) What do the two axes (x-axis and y-axis) of the Gantt Chart represent respectively?
________________________________________________________________________________________
________________________________________________________________________________________

(ii) Other than Gantt Chart, state TWO charts that can be found in the design phase of SDLC.
________________________________________________________________________________________
________________________________________________________________________________________
(3 marks)
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


(b) (i) According to the information provided, fill in the missing information in the table and complete the Gantt Chart
by referring to the dependency and duration of the tasks.

ID Task Dependent on Duration (x50 Days)


1 Land Formation and Marine Works / 6
2 Airfield Facilities 5
3 Aprons Works 1 2
4 Runway Passenger Building 5 5
5 Automated People Mover System 1
6 Baggage Handling System 6
7 Airport Support Facilities 4 4
8 Public Facilities 4 3

Duration( x50 days)


ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1
2
3
4
5
6
7
8
(6 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 2


ii) How many days are required for the whole process of the implementation of the new airport runway system?
________________________________________________________________________________________
(1 mark)

(c) In the implementation phase, Peter wants to store the dependency of the tasks into an array. Peter suggests to use 2D
Boolean Array. When task i is dependent on j,S[i,j] = T, otherwise S[i,j] = F.

(i) Complete the following table which shows the content of array S according to the information provided
in part (b).
j 1 2 3 4 5 6 7 8
i
1 F F F F F F F F
2
3 T F F F F F F F
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


4 F F F F T F F F
5 T F F F F F F F
6
7 F F F T F F F F
8 F F F T F F F F
(2 marks)
(ii) Peter wants to know the number of depending tasks of each task. The result is stored into an array C as shown
below:

ID 1 2 3 4 5 6 7 8
No. 3 0 1 2 1 0 0 0

Suppose all elements in array C are already initialized to 0. Complete the following pseudocode for the
algorithm to generate the above result:

For i from 1 to 8
For j from 1 to 8

If then

(3 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 3


2. Mary creates a linked list to represent how multiple units in a train are linked. Each unit is named by an
alphabet. She uses parallel arrays to implement the linked list. Array UNIT stores the name of the unit. Array
NEXT stores the address of the next node. The first node in UNIT stores START.

(a) LL1
Address UNIT NEXT
0 START 4
1 A -2
2 B 1
3 C 7
4 D 3
5 E -2
6 F 2
7 G 6
8 H 5

(i) Other than linked list, suggest another data structure and state the major difference while inserting a new
element.
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


(ii) What is the purpose of using -2 as a location of next unit?

(iii) Other than -2, give other possible values that Mary can use?

(iv) Write down the content of next four nodes after START in order.

(v) How many nodes are there in this linked list excluding the first node START?

(7 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 4


(b) Suppose the sequence of units is A→F→G→C→E→B→D→H. Fill in the missing column NEXT in LL2.

LL2
Address UNIT NEXT
0 START 1
1 A
2 E
3 F
4 B
5 D
6 C
7 G
8 H
(2 marks)

(c) Mary designs another structure by adding another array PREV. In each node, PREV points to the previous
node, as shown in the following example.

LL3
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


Address UNIT PREV NEXT
0 START -1 4
1 A 2 5
2 E 6 1
3 F 4 7
4 B 0 3
5 D 1 8
6 C 7 2
7 G 3 6
8 H 5 -2

(i) Give one advantage of adding PREV to the structure.

(1 mark)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 5


(ii) Mary designs an operation DELETE(Z) that will delete the node with address Z.
Updates LL3 after executing DELETE(6):

LL3
Address UNIT PREV NEXT
0 START
1
2
3
4
5
6
7
8
(3 marks)

(iii) The LL3 is implemented by parallel arrays UNIT, PREV and NEXT.
For example, UNIT[8]stores H, Previous[8] stores 5 and NEXT[8] stores -2.
Assume that Z is NOT the start node or the end node of the linked list, complete the following
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


algorithm for the operation DELETE(Z).

Subprogram DELETE(Z):

NEXT[ PREV[Z] ]  __________________________

PREV[ NEXT[Z] ]  __________________________

(2 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 6


3. The following algorithm ALG1 processes an integer array item with indices from 1 to n.
ALG1
Line 1 for i from 2 to n do
Line 2 t  item[i]
Line 3 for j from i-1 downto 1 do
Line 4 if item[j] > t then
Line 5 item[j+1]  item[j]
Line 6 item[j]  t

(a) Assume that n = 6 and ALG1 is executed with the following initial content of item.

1 2 3 4 5 6
item: 64 37 55 80 42 73

(i) Fill in the content of item after the first pass and the second pass in the loop in Line 1.
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


After the first pass
1 2 3 4 5 6
item:

After the second pass


1 2 3 4 5 6
item:

(ii) How many times will Line 4 be executed?

(iii) What is the purpose of the algorithm ALG1?

(iv) During the third pass of the loop in Line 1, the content of each element in the array item do not change.
Do you agree? Explain your answer briefly.

(5 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 7


(b) A procedure swap(x,y) exchanges contents in two parameters x and y. Complete the missing parts in the
following program using the procedure swap which performs the same as ALG 1.

for i  2 to n do

for j  i-1 downto 1 do

if then

(3 marks)

(c) Consider the following algorithm ALG2:


ALG2
Line 1 for i from 2 to n do
Line 2 j  i - 1
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


Line 3 t  item[i]
Line 4 while (j >= 1) and (t < item[j]) do
Line 5 if item[j] > t then
Line 6 item[j+1]  item[j]
Line 7 item[j]  t
Line 8 j  j - 1

(i) If the same content of item in (a) is used in ALG2. How many times will Line 5 be executed?

(ii) If n = 100 (i.e. 100 elements in the array item). What is the minimum possible number of execution of
Line 5 in ALG2?

(2 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 8


(d) Complete the pseudocode of the following subprogram check to check if contents in item satisfy your expected result
as mentioned in a(iii). Boolean value True or False will be returned for valid and invalid checking result respectively.

Subprogram check

Valid  __________________

for i from _______ to _______ do

if ________________________________ then

_____________________________

Return ___________________

(5 marks)
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 9


4. Sudoku is a logic-based number-placement puzzle. The aim is to fill a 9×9 grid with digits so that each column,
each row, and each box that compose the grid contain all of the digits from 1 to 9.

Each 9x9 sudoku can be divided into 9 boxes, as shown below:

A valid sudoku solution must satisfy the following rules:

1. Number 1-9 can only appear once in each column.


2. Number 1-9 can only appear once in each row.
3. Number 1-9 can only appear once in each box.
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


The following shows some valid and invalid sudoku solution.

Valid sudoku solution:


5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9

Invalid sudoku solution:


(Duplicated digits are highlighted in bold and underlined.)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 10


Lily is going to write a program to check if a Sudoku solution is valid or not. The Sudoku solution is stored in
a global two-dimensional array sol. The first row and column are indexed as 0. The data structure of sol is
shown below:

Element Value
sol[0][0] a
sol[6][4] b
sol[3][7] c
sol[8][8] d

(a) Lily creates a subprogram checkUniq(data[]) which return True if the elements in data are unique
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


and contains the digits 1-9 exactly once. The input parameter data[] is an array containing 9 elements and
the index of the first element is 0.

The following shows the pseudocode for checkUniq(data[]). Complete the subprogram.

checkUniq(data[])
f  True
j  0
while j < 9 do
k  j + 1
while k < 9 do
if data[j] = data[k] then
f  False
k  k + 1
if data[j] > 9 or data[j] < 1 then
f  False
j  j + 1
return f

(3 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 11


(b) To check if a sudoku solution is valid or not, Lily created the following subprograms checkRow(I),
checkCol(I) and checkBox(I).
Subprogram Description
checkCol(I) Check if the Ith column contains all of the digits from 1 to 9.
Return true if yes, false otherwise. The first column is
numbered 0.
checkRow(I) Check if the Ith row contains all of the digits from 1 to 9. Return
true if yes, false otherwise. The first row is numbered 0.
checkBox(I) Check if the Ith box contains all of the digits from 1 to 9. Return
true if yes, false otherwise. The boxes are numbered in the
following manner:
5 3 4 6 7 8 9 1 2
6
1
0
7
9
2
8
1
3
1
9
4
5
2
3
5
2
4
6
8
7
8 5 9 7 6 1 4 2 3
4
7
3
2
1
6
3
8
9
4
5
2
3
4
7
8
5
9
5
1
6
9 6 1 5 3 7 2 8 4
2
6
8 7 4
7
1 9 6
8
3 5
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


3 4 5 2 8 6 1 7 9

By making use of the subprogram checkUniq(data[]) , Lily has completed the subprograms
checkCol(I) and checkRow(I). The following shows the pseudocode for checkBox(I) .

Complete the subprogram.


Remark:
1. You should make use of the subprogram checkUniq(data[]) in your answer.
2. AR is a integer array of 9 elements, the index of the first element is 0.
checkBox(I)
for c  0 to 8 do
AR[c]  0

X  (integral part of I / 3)*3


Y  (remainder of I/3)*3

for k  0 to 8 do
P  X + remainder of k/3
Q  Y + integral part of k/3
AR[k] = sol[P][Q]

return checkUniq(AR)

(3 marks)

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 12


(c) Complete the subprogram checkSol() in pseudocode which determine if the solution stored in the global
array sol is valid or not. The subprogram should return a Boolean value to indicate whether the solution is
valid or not. You should make use of the subprograms checkCol(), checkRow() and checkBox().

checkSol():
Answers written in the margins will not be marked.

Answers written in the margins will not be marked.


(3 marks)
(d) To create a puzzle, Lily takes a valid sudoku solution and hide some of cells randomly. She also wants to
show some hints by showing the possible values for each hidden cell. An example is shown below.

Hidden cell

Hints

Each hidden cell is represented by the integer value 0 in the global array sol. Lily wants to develop
another subprogram findHints(X, Y)which finds out all the possible choices for the empty cell at the
Xth row and Yth column. X and Y are both integer values and the first row and the first column are both
denoted by the integer value 1. The subprogram should output the possible choices of the cell. In case the
specified cell is invalid or not an empty cell, the subprogram should output the string value "NA".

For example, according to the above sudoku puzzle, the findHints(X, Y) should return the following
values.
Expression Output Remark
findHints(1, 8) "456" The 1st row, 8th column
findHints(9, 4) "257" The 9th row, 4th column
The 8th row, 4th column, contains
findHints(8, 4) "NA"
the value 8 already
findHints(10, 2) "NA" Invalid row
findHints(2, 10) "NA" Invalid column
Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 13


The following shows the declaration of the global array sol in Pascal, C, Java and Visual Basic.
Programming Language Declaration
Pascal var sol:array[0..8, 0..8] of integer;
C int sol[9][9];
Java int[][] sol = new int[9][9];
Visual Basic Dim sol(9, 9) As Integer
Complete the subprogram findHints()using Pascal, C, Java or Visual Basic. You may define
local variables if necessary.

Choose your programming language: Pascal  C Java  Visual Basic 


Answers written in the margins will not be marked.

Answers written in the margins will not be marked.

(6 marks)
END OF PAPER

Answers written in the margins will not be marked.

HKACE-ICT MOCK EXAM 2020-2D 14

You might also like