Please stick the barcode label here.
2012-DSE
ICT
HONG KONG EXAMINATIONS AND ASSESSMENT AUTHORITY
Candidate Number
HONG KONG DIPLOMA OF SECONDARY EDUCATION EXAMINATION 2012
Pascal D
INFORMATION AND COMMUNICATION TECHNOLOGY Programming
Language Used
C D
PAPER 2D (Please tick one) Visual Basic D
Software Development Java D
Question-Answer Book
11.15 am - 12.45 pm (1 hour 30 minutes)
This paper must be answered in English
INSTRUCTIONS
(1) After the announcement of the start of the
examination, you should first write your Candidate
. Number in the space provided on Page 1 and stick
barcode labels in the spaces provided on Pages 1, 3,
5 and 7.
(2) Tick the appropriate box for the programming
language used. No marks will be awarded if you
tick either more than one box or no boxes.
(3) ANSWER ALL QUESTIONS. Write your answers in
the spaces provided in this Question-Answer book.
Do not write in the margins. Answers written in the
margins will not be marked.
(4) Supplementary answer sheets will be supplied on
request. Write your candidate number, mark the
question number box and stick a barcode label on
each sheet, and fasten them with string INSIDE this
book.
(5) No extra time will be given to candidates for sticking
on the barcode labels or filling in the question number
boxes after the 'Time is up' announcement.
2012-DSE-ICT 2D-l 60 Ill II I 111111 111111111
* A 2 0 0 E O 2 D *
Please stick the barcode label here.
(b) The following algorithm, ALG2, processes a non-negative integer variable, N, and stores the results in
an array, Y, with indexes from 1 to 6. N is smaller than 64.
ALG2
Step 1: Initialise each element in with a value o.
Step 2: j � 1 Y
Step 3: While N > o do Steps 4 to 7
Step 4: If N >= z [ j J Then do Steps 5 to 6
Step 5: Y[j] � 1
Step 6: N � N - Z [j]
Step 7: j � j + 1
z is an array with the following initial values.
u
Z 1 Z 2 Z[3] Z 4] Z(S Z 6]
[ ] [ ] [ ] [ eu
32 16 8 4 2 1
(i) Suppose N = 4 8. Dry run ALG2. Fill in the content of . -�
Y .s
I Y[l] I Y [2 ] I Y [3] I 4
Y[ ] I Y[5] I 6
Y[ 1
.s
(ii) In the worst case, how many iterations of the loop will be executed?
-�
(iii) Give a value of N (N > O) and show that ALG2 will execute fewer iterations than ALG1 does.
(6 marks)
Answers written in the margins will not be marked.
2012-DSE-ICT 2D-3 62