Senior Secondary (HKDSE) · Information and Communication Technology

Programming : Practice Questions

5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on Programming .

10 questions27 marksFree, no account
Question 1
1 mark

Consider the following pseudocode snippet:


DECLARE x AS INTEGER
DECLARE y AS INTEGER
DECLARE result AS INTEGER

x = 25
y = 7
result = (x MOD y) + (x DIV y)

PRINT result

What will be the final value displayed by the program?

Question 2
1 mark

Consider the following pseudocode:


GLOBAL A = 20

SUBROUTINE UpdateValue(B)
A = A - B
B = B + 1
END SUBROUTINE

START
C = 7
CALL UpdateValue(C)
PRINT A
PRINT C
END START

If parameters are passed by value, what will be the output of PRINT A and PRINT C, respectively?

Question 3
1 mark

A program calculates the average of a list of numbers provided by the user. The user is prompted to enter five numbers. If the user accidentally enters '0' as one of the numbers, and the program performs a division by the count of numbers entered (which is 5), what type of error will occur if the program logic incorrectly attempts to sum numbers, but fails to handle specific numeric inputs or the count of valid numbers?

Question 4
1 mark

When developing a software project, a programmer decides to use comments and proper indentation throughout the source code. According to the syllabus, which of the following best describes the primary purpose of these practices?

Question 5
1 mark

Consider the following pseudocode for a linear search algorithm:


DECLARE numbers[5] AS INTEGER
numbers = [25, 10, 30, 15, 5]
DECLARE target AS INTEGER
target = 15
DECLARE foundIndex AS INTEGER
foundIndex = -1

FOR i FROM 0 TO 4 DO
IF numbers[i] == target THEN
foundIndex = i
BREAK
END IF
END FOR

PRINT foundIndex

What value will be displayed by the program?

Question 6
2 marks

Explain one reason why using meaningful variable names (e.g., totalScore instead of ts) is considered good programming style.

Write your answer out first, then check it against the worked solution.

Question 7
4 marks

A programmer is developing a module to process a list of integers. Compare Bubble Sort and Selection Sort in terms of their worst-case time complexity using Big O notation, and explain one reason why a programmer might choose to use Insertion Sort instead of these for a list that is already nearly sorted.

Write your answer out first, then check it against the worked solution.

Question 8
5 marks

A simple linear queue implementation uses an array Q of size \(N=10\) (indices 0 to 9), with pointers front and rear both initialized to 0. The rear pointer tracks the index of the next available slot for insertion. If 10 successful elements are inserted followed by 5 successful deletion operations, state the resulting values of front and rear. Also, explain the key limitation preventing further insertions and the technical term describing this inefficient usage of the array space.

Write your answer out first, then check it against the worked solution.

Question 9
4 marks

Consider the following pseudocode:

GLOBAL X = 10

SUBROUTINE Process(Y)
X = X + Y
Y = Y * 2
END SUBROUTINE

START
A = 5
CALL Process(A)
OUTPUT X
OUTPUT A
END START

(a) What will be the output of OUTPUT X and OUTPUT A if parameters are passed by value?

(b) What will be the output of OUTPUT X and OUTPUT A if parameters are passed by reference?

Write your answer out first, then check it against the worked solution.

Question 10
7 marks

A queue data structure can be implemented using a one-dimensional array. Assume a linear array queueArray of fixed size $$N=5$$ is used, with front and rear pointers tracking the head and tail of the queue, respectively. Initially, the queue is empty, with front = -1 and rear = -1.

(a) Design algorithms using pseudocode for the following operations. Ensure you handle conditions where the queue might be full or empty.

(i) ENQUEUE(item): Adds an item to the rear of the queue.

(ii) DEQUEUE(): Removes and returns an item from the front of the queue.

(b) Trace the execution of the following sequence of operations on the initially empty queue. For each step, show the values of front, rear, and the content of queueArray. Use '_' to denote an empty slot in the array.

1. ENQUEUE('A')
2. ENQUEUE('B')
3. DEQUEUE()
4. ENQUEUE('C')
5. ENQUEUE('D')
6. DEQUEUE()
7. ENQUEUE('E')
8. ENQUEUE('F')

(c) Explain one major limitation of implementing a queue using a simple linear array (as described above) and how a circular queue implementation addresses this limitation.

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, marked as you go.

Practise More