First 50 of 190 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.
Continue in the practice tool above to load more questions, 50 at a time.
Question 1Algorithms and computational thinking
Which of the following best describes an algorithm?
- A programming language used to solve computational problems
- A finite sequence of well-defined, unambiguous steps that solves a problem in finite time Correct answer.
- A computer program that has been compiled into machine code
- A diagram showing the hardware components of a computer system
Explanation
An algorithm is a finite, ordered set of precise steps that solves a problem or performs a task. It exists independently of any programming language; a program is only one possible implementation of an algorithm.
Question 2Algorithms and computational thinking
Which of the following is NOT a required property of an algorithm?
- Finiteness: it must terminate after a finite number of steps
- Definiteness: each step must be precisely and unambiguously defined
- It must be written in the C++ programming language Correct answer.
- Effectiveness: each step must be basic enough to be carried out exactly
Explanation
Algorithms are language-independent: the same algorithm can be expressed in pseudocode, a flowchart, or any programming language. Finiteness, definiteness, and effectiveness are classical required properties of algorithms.
Question 3Algorithms and computational thinking
Trace the pseudocode: x <- 5; y <- 3; x <- x + 2*y; y <- x - y. What is the final value of y?
- 8 Correct answer.
- 5
- 11
- 3
Explanation
First x becomes 5 + 2*3 = 11. Then y becomes x - y = 11 - 3 = 8. Note that the updated value of x (11), not the original 5, is used in the last assignment.
Question 4Algorithms and computational thinking
In a flowchart, what does a diamond-shaped symbol represent?
- An input or output operation
- The start or end of the algorithm
- A decision point with a conditional test (e.g. yes/no branches) Correct answer.
- A processing step such as a calculation
Explanation
In standard flowchart notation, the diamond denotes a decision: a condition is tested and the flow splits into branches (typically yes/no or true/false).
Question 5Algorithms and computational thinking
What precondition must hold for binary search to work correctly on an array?
- The data must be sorted Correct answer.
- The data must contain no duplicate values
- The data must consist of numbers only
- The array must contain an even number of elements
Explanation
Binary search works by comparing the target with the middle element and discarding half of the remaining range. This halving logic is only valid when the data are ordered.
Question 6Algorithms and computational thinking
A sorted array contains 1000 elements. Using binary search, what is the maximum number of comparisons needed to find a target value (or conclude it is absent)?
- 500
- 100
- 10 Correct answer.
- 1000
Explanation
Each comparison halves the search range. Since 2^10 = 1024 >= 1000, at most 10 comparisons are needed (ceiling of log2(1000)). This illustrates the logarithmic efficiency of binary search.
Question 7Algorithms and computational thinking
In the worst case, how many comparisons does linear (sequential) search need on an array of n elements?
- 1
- n/2
- log2 n
- n Correct answer.
Explanation
Linear search checks elements one by one from the start. In the worst case (target absent or in the last position) all n elements are examined, so n comparisons are made.
Question 8Algorithms and computational thinking
Trace the pseudocode: s <- 0; for i <- 1 to 5 do s <- s + i. What is the final value of s?
- 10
- 15 Correct answer.
- 20
- 5
Explanation
The loop accumulates 1 + 2 + 3 + 4 + 5 = 15. This is the classic accumulator pattern: a variable initialized to zero that gathers a running total.
Question 9Algorithms and computational thinking
Trace the pseudocode: n <- 1; c <- 0; while n < 100 do { n <- n * 2; c <- c + 1 }. What is the final value of c?
- 6
- 7 Correct answer.
- 8
- 100
Explanation
The values of n at each test are 1, 2, 4, 8, 16, 32, 64 (loop runs), then 128 (loop stops). The body executed 7 times, so c = 7.
Question 10Algorithms and computational thinking
Trace the pseudocode: a <- 4; b <- 7; temp <- a; a <- b; b <- temp. What are the final values?
- a = 4, b = 7
- a = 7, b = 7
- a = 7, b = 4 Correct answer.
- a = 4, b = 4
Explanation
The temporary variable preserves the original value of a (4). After a <- b, a is 7; then b <- temp restores the original a into b, giving a = 7 and b = 4. This is the standard swap idiom.
Question 11Algorithms and computational thinking
An ascending bubble sort performs one full pass over the array [6, 3, 8, 2], swapping adjacent elements whenever they are out of order. What does the array look like after this first pass?
- [2, 3, 6, 8]
- [3, 6, 2, 8] Correct answer.
- [3, 6, 8, 2]
- [6, 3, 2, 8]
Explanation
Compare 6 and 3: swap, giving [3, 6, 8, 2]. Compare 6 and 8: no swap. Compare 8 and 2: swap, giving [3, 6, 2, 8]. After one pass the largest element (8) has 'bubbled' to the last position.
Question 12Algorithms and computational thinking
Approximately how many comparisons does binary search need in the worst case on a sorted telephone directory of 1,000,000 names?
- About 500,000
- About 1,000
- About 1,000,000
- About 20 Correct answer.
Explanation
Binary search halves the range each step, and 2^20 = 1,048,576 >= 1,000,000, so about 20 comparisons suffice. This logarithmic behaviour is why binary search is preferred for large sorted datasets.
Question 13Algorithms and computational thinking
In computational thinking, what is 'decomposition'?
- Breaking a complex problem down into smaller, more manageable sub-problems Correct answer.
- Removing all unnecessary detail from a problem to focus on the essentials
- Looking for similarities and recurring structures within problems
- Writing a step-by-step solution that a computer can execute
Explanation
Decomposition means splitting a large problem into smaller parts that can be solved (and programmed) separately, then combined. It is one of the four pillars of computational thinking.
Question 14Algorithms and computational thinking
Trace the pseudocode: x <- 12; if x MOD 2 = 0 then y <- x / 2 else y <- 3*x + 1. What is the final value of y?
- 37
- 6 Correct answer.
- 12
- 24
Explanation
12 MOD 2 = 0, so the condition is true and the then-branch executes: y = 12 / 2 = 6. The else-branch (3*x + 1) is skipped entirely.
Question 15Algorithms and computational thinking
Trace the pseudocode: c <- 0; for i <- 1 to 3 do { for j <- 1 to 4 do c <- c + 1 }. What is the final value of c?
- 7
- 12 Correct answer.
- 16
- 64
Explanation
The inner loop runs 4 times for each of the 3 outer iterations, so the body executes 3 x 4 = 12 times. Nested-loop costs multiply rather than add.
Question 16Algorithms and computational thinking
An algorithm must read numbers one at a time and stop as soon as a negative number is entered, then output how many non-negative numbers were read. Which control structure is most appropriate for the reading step?
- A counted for-loop from 1 to 100
- A while-loop that continues as long as the number entered is non-negative Correct answer.
- A nested pair of for-loops
- A single if-else statement with no loop
Explanation
The number of inputs is unknown in advance; the repetition must be controlled by a condition (input >= 0). A while-loop with a sentinel value is the natural choice for condition-controlled repetition.
Question 17Algorithms and computational thinking
Given a <- 10 and b <- 3, what are the values of q <- a DIV b (integer quotient) and r <- a MOD b (remainder)?
- q = 3, r = 1 Correct answer.
- q = 3, r = 3
- q = 3.33, r = 0
- q = 1, r = 3
Explanation
DIV gives the integer quotient: 10 DIV 3 = 3. MOD gives the remainder: 10 MOD 3 = 1. They satisfy a = q*b + r, i.e. 10 = 3*3 + 1.
Question 18Algorithms and computational thinking
Trace the pseudocode: n <- 153; s <- 0; while n > 0 do { d <- n MOD 10; s <- s + d*d*d; n <- n DIV 10 }. What is the final value of s?
- 27
- 9
- 153 Correct answer.
- 126
Explanation
The loop extracts digits 3, 5, 1 and cubes them: 27 + 125 + 1 = 153. Because s equals the original number, 153 is an Armstrong (narcissistic) number.
Question 19Data representation and relational databases
What is the decimal value of the binary number 1011?
- 13
- 11 Correct answer.
- 9
- 1011
Explanation
1011 binary = 1*8 + 0*4 + 1*2 + 1*1 = 8 + 2 + 1 = 11. Each position is a power of two, starting from 2^0 on the right.
Question 20Data representation and relational databases
What is the binary representation of the decimal number 25?
- 10101
- 11100
- 11001 Correct answer.
- 10011
Explanation
25 = 16 + 8 + 1, so bits 4, 3 and 0 are set: 11001. Repeated division by 2 gives the same result: remainders 1, 0, 0, 1, 1 read bottom-up.
Question 21Data representation and relational databases
What is the decimal value of the hexadecimal number 2F?
- 47 Correct answer.
- 215
- 43
- 35
Explanation
In hex, F = 15. So 2F = 2*16 + 15 = 32 + 15 = 47.
Question 22Data representation and relational databases
What is the hexadecimal representation of the binary number 10110101?
- B5 Correct answer.
- A5
- B4
- 265
Explanation
Group the bits into nibbles: 1011 0101. 1011 = 11 = B, and 0101 = 5. Hence 10110101 binary = B5 hex.
Question 23Data representation and relational databases
What is the decimal value of the octal number 17?
- 17
- 15 Correct answer.
- 23
- 111
Explanation
Octal is base 8, so 17 octal = 1*8 + 7 = 15 in decimal.
Question 24Data representation and relational databases
What range of decimal integers can be represented with 8 bits using two's complement?
- 0 to 255
- -127 to 128
- -128 to 127 Correct answer.
- -255 to 255
Explanation
With n bits in two's complement, the range is -2^(n-1) to 2^(n-1) - 1. For 8 bits that is -128 to 127. The range is asymmetric because one pattern (10000000) represents -128 and there is no +128.
Question 25Data representation and relational databases
How is the decimal number -5 represented in 8-bit two's complement?
- 11111011 Correct answer.
- 10000101
- 11111010
- 00000101
Explanation
Start with +5 = 00000101. Invert all bits: 11111010. Add 1: 11111011. This is the standard invert-and-add-one procedure for negating in two's complement.
Question 26Data representation and relational databases
How many bytes are there in 4 KB (kilobytes) of memory, using the binary convention 1 KB = 1024 bytes?
- 4000
- 4096 Correct answer.
- 1024
- 400
Explanation
1 KB = 1024 bytes, so 4 KB = 4 x 1024 = 4096 bytes. The binary convention uses powers of two because memory is addressed in binary.
Question 27Data representation and relational databases
What is the minimum number of bits needed to represent 256 different values?
- 256
- 16
- 2
- 8 Correct answer.
Explanation
With n bits you can represent 2^n distinct values. Since 2^8 = 256, exactly 8 bits are needed.
Question 28Data representation and relational databases
In the ASCII encoding, the character 'A' has code 65. What is the ASCII code of the character 'F'?
- 69
- 70 Correct answer.
- 71
- 66
Explanation
Uppercase letters occupy consecutive ASCII codes. 'F' is 5 positions after 'A', so its code is 65 + 5 = 70.
Question 29Data representation and relational databases
A colour image uses 8 bits for each of the red, green and blue channels per pixel. How many bits are used to store the colour of one pixel?
- 8
- 16
- 24 Correct answer.
- 32
Explanation
Three channels x 8 bits = 24 bits per pixel. This 'true colour' scheme allows 2^24 (about 16.7 million) distinct colours.
Question 30Data representation and relational databases
What is the largest decimal value that can be stored in an unsigned 8-bit integer?
- 255 Correct answer.
- 256
- 127
- 128
Explanation
Unsigned 8-bit values run from 0 to 2^8 - 1 = 255. The count of distinct values is 256, but because it starts at 0, the maximum is 255.
Question 31Data representation and relational databases
What is the result of the binary addition 1011 + 110?
- 1111
- 10010
- 10001 Correct answer.
- 1101
Explanation
Aligning by the right: 1011 + 0110. Units: 1+0=1; twos: 1+1=10, write 0 carry 1; fours: 0+1+carry=10, write 0 carry 1; eights: 1+0+carry=10, write 0 carry 1; final carry gives 1. Result: 10001 (= 11 + 6 = 17 in decimal).
Question 32Data representation and relational databases
Why is hexadecimal notation widely used in computing?
- Because computers perform calculations directly in base 16
- Because it is a compact, human-friendly shorthand for binary patterns Correct answer.
- Because it allows negative numbers to be stored without a sign bit
- Because it doubles the storage capacity of memory chips
Explanation
One hex digit corresponds exactly to four bits, so long binary patterns (memory addresses, colour codes, machine code) can be written and read compactly with easy mental conversion.
Question 33Data representation and relational databases
A mono sound is recorded for 10 seconds at 1000 samples per second with 8 bits (1 byte) per sample, without compression. How many bytes of storage does the recording require?
- 80,000
- 10,000 Correct answer.
- 1,000
- 800
Explanation
File size = duration x sampling rate x bytes per sample = 10 s x 1000 samples/s x 1 byte = 10,000 bytes.
Question 34Data representation and relational databases
The 8-bit pattern 11111111 represents which decimal value when interpreted as a two's complement signed integer?
- 255
- -255
- -1 Correct answer.
- 0
Explanation
In two's complement, 11111111 = -1: inverting gives 00000000 and adding 1 gives 00000001 (=1), so the pattern is the negative of 1. The leading 1 signals a negative number.
Question 35Programming and C++ foundations
In programming, what is a variable?
- A named memory location that stores a value which can change during program execution Correct answer.
- A fixed value that can never be altered after compilation
- A reserved word that starts a loop
- A hardware component inside the CPU
Explanation
A variable is a named reference to a memory location whose contents the program can read and modify. Its name, type, and value are its key attributes.
Question 36Programming and C++ foundations
In C++, which statement correctly reads an integer from the keyboard into the variable x?
- cout << x;
- cin >> x; Correct answer.
- read x;
- x = input;
Explanation
cin is the standard input stream and >> is the extraction operator, so cin >> x; reads a value into x. cout with << does the opposite (output).
Question 37Programming and C++ foundations
What does the following C++ code output? int a = 7, b = 2; cout << a / b << ' ' << a % b;
- 3.5 1
- 3 1 Correct answer.
- 3 0
- 3.5 0
Explanation
Both operands are int, so a / b performs integer division: 7 / 2 = 3. The % operator gives the remainder: 7 % 2 = 1. Output: '3 1'.
Question 38Programming and C++ foundations
In C++, what value is stored in r after: double r = 7 / 2;
- 3.5
- 4.0
- 3.0 Correct answer.
- A compilation error occurs
Explanation
The expression 7 / 2 is evaluated first using integer division, giving 3; only then is it converted to double, so r = 3.0. To get 3.5 you must write 7.0 / 2 or 7 / 2.0.
Question 39Programming and C++ foundations
What does the following C++ code print? int x = 10; if (x > 5) x = x - 3; else x = x + 3; cout << x;
- 13
- 10
- 3
- 7 Correct answer.
Explanation
Since 10 > 5 is true, the if-branch executes: x = 10 - 3 = 7. The else-branch is skipped.
Question 40Programming and C++ foundations
What is the value of s after this C++ loop? int s = 0; for (int i = 1; i <= 4; i++) s += i * i;
- 24
- 30 Correct answer.
- 10
- 100
Explanation
The loop adds the squares 1 + 4 + 9 + 16 = 30. Note the condition i <= 4 includes the iteration i = 4.
Question 41Programming and C++ foundations
What is the final value of i after this C++ code? int i = 10; while (i > 0) { i -= 3; }
- 0
- -2 Correct answer.
- 1
- -1
Explanation
The values are 10, 7, 4, 1, -2. When i = 1 the condition still holds, so the body runs once more giving -2; then the test fails. Loop variables need not land exactly on the boundary.
Question 42Programming and C++ foundations
What is the key difference between a do...while loop and a while loop in C++?
- A do...while loop always executes its body at least once, because the condition is checked after the body Correct answer.
- A do...while loop cannot contain if statements
- A while loop always executes at least once, but a do...while loop may not execute at all
- There is no difference; they are interchangeable in all cases
Explanation
In do...while the condition is evaluated after the body (post-test), guaranteeing one execution. In a while loop the condition is tested first, so the body may run zero times.
Question 43Programming and C++ foundations
What is the value of the C++ expression 2 + 3 * 4?
- 20
- 14 Correct answer.
- 24
- 9
Explanation
Multiplication has higher precedence than addition, so the expression is 2 + (3 x 4) = 2 + 12 = 14, not (2 + 3) x 4.
Question 44Programming and C++ foundations
Given int x = 5, y = 10; what is the value of the C++ expression (x > 3 && y < 5) || !(x == 5)?
- true
- false Correct answer.
- A compilation error occurs
- 5
Explanation
x > 3 is true but y < 5 is false, so the && gives false. !(x == 5) is !(true) = false. false || false = false.
Question 45Programming and C++ foundations
Which C++ data type is the appropriate choice for storing the value 3.14159?
- int
- double Correct answer.
- char
- bool
Explanation
double stores floating-point numbers with fractional parts. int would truncate 3.14159 to 3, char stores a single character, and bool stores only true/false.
Question 46Programming and C++ foundations
Given the declaration int a[5]; in C++, which of the following accesses is out of bounds?
- a[0]
- a[4]
- a[5] Correct answer.
- a[2 + 1]
Explanation
Array indices in C++ start at 0, so a[5] has valid indices 0 to 4. Accessing a[5] reads/writes memory outside the array and causes undefined behaviour.
Question 47Programming and C++ foundations
Given int a[5] = {2, 4, 6, 8, 10}; what does cout << a[1] + a[3]; print?
- 14
- 12 Correct answer.
- 10
- 8
Explanation
a[1] is the second element (4) and a[3] is the fourth element (8), so the sum is 12. Zero-based indexing is the key detail here.
Question 48Programming and C++ foundations
What does this C++ code print? int a[6] = {4, 9, 1, 7, 7, 2}; int best = 0; for (int i = 1; i < 6; i++) if (a[i] > a[best]) best = i; cout << best;
- 1 Correct answer.
- 9
- 3
- 4
Explanation
The loop finds the index of the maximum element. The maximum value is 9 at index 1, and since the comparison is strict (>), ties are not updated. It prints the index 1, not the value 9.
Question 49Programming and C++ foundations
In C++, what is the effect of declaring a function parameter by reference, e.g. void f(int &x)?
- The function receives a copy, so the caller's variable cannot change
- The function works on the caller's original variable, so assignments to x modify it Correct answer.
- The parameter becomes a constant that cannot be assigned
- The variable is deleted from memory when the function returns
Explanation
A reference parameter is an alias for the caller's variable, not a copy. Any modification inside the function directly affects the original, which is how swap functions are written.
Question 50Programming and C++ foundations
What does f(4) return? int f(int n) { if (n == 0) return 1; return n * f(n - 1); }
- 10
- 24 Correct answer.
- 16
- 4
Explanation
This recursive function computes factorial: f(4) = 4 x f(3) = 4 x 3 x f(2) = 4 x 3 x 2 x f(1) = 4 x 3 x 2 x 1 x f(0) = 24. The base case n == 0 stops the recursion.