First 50 of 200 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 1Computational thinking
A student writes an algorithm as a numbered list of unambiguous steps that always finish after a finite number of operations. Which property of an algorithm does the finite number of steps describe?
- Termination Correct answer.
- Abstraction
- Decomposition
- Modularity
Explanation
An algorithm must halt after a finite number of steps, and this property is called termination. Abstraction, decomposition and modularity are design strategies for structuring solutions rather than guarantees that a procedure ends. A set of steps that can loop forever fails the termination requirement.
Question 2Computational thinking
A vending machine program stores the price of each snack in a list and the snack names in a parallel list at the same indexes. Which data structure concept does this arrangement rely on?
- Parallel arrays linked by index position Correct answer.
- A stack that removes the most recent item
- A tree that orders items by key value
- A queue that processes items in arrival order
Explanation
Two arrays of equal length that store related values at matching index positions are parallel arrays. The index acts as the link between a snack name and its price. Stacks, queues and trees organise access order or hierarchy, which is not what is described here.
Question 3Computational thinking
Which statement best describes the purpose of decomposition when solving a complex problem?
- It breaks the problem into smaller parts that can be solved and tested separately Correct answer.
- It converts every problem into a single loop structure
- It removes all detail from the problem until nothing remains
- It guarantees the fastest possible running time
Explanation
Decomposition divides a large problem into smaller sub-problems that are easier to design, implement and test independently. It does not remove all detail, nor does it prescribe a particular control structure. Dividing work does not by itself guarantee optimal performance.
Question 4Computational thinking
A function accepts a list of scores and returns the highest score. Which term describes the list passed into the function?
- An argument Correct answer.
- A constant
- A return value
- A loop counter
Explanation
A value supplied to a function when it is called is an argument, which is bound to a parameter inside the function. A return value is what the function sends back to the caller. Constants and loop counters are unrelated roles in this description.
Question 5Computational thinking
A programmer writes a condition that checks whether a value is greater than 10 and less than 20. Which logical operator combines the two comparisons?
- AND Correct answer.
- NOT
- OR
- XOR
Explanation
Both comparisons must be true at the same time for the value to lie strictly between 10 and 20, so the AND operator is required. OR would accept a value satisfying only one comparison. NOT inverts a single condition, and XOR accepts exactly one true operand, which would reject valid values.
Question 6Computational thinking
A loop is written to repeat while a counter is less than 5, starting at 0 and increasing by 1 each pass. How many times does the loop body execute?
- 6
- 0
- 4
- 5 Correct answer.
Explanation
The counter takes the values 0, 1, 2, 3 and 4 before reaching 5, at which point the condition fails. That is five executions of the loop body. Starting at zero and using a strict less-than comparison gives exactly five passes.
Question 7Computational thinking
A programmer replaces a repeated block of code with a single named function called in several places. Which benefit does this change most directly provide?
- The program uses no memory for variables
- The program runs without any conditions
- Changes to the logic need to be made in only one place Correct answer.
- The program no longer needs any input
Explanation
Encapsulating repeated logic in one function means a fix or change is applied once and affects every call site. It does not eliminate memory use, input handling or conditional logic. Reuse improves maintainability rather than removing those features.
Question 8Computational thinking
Which of the following is an example of abstraction in a model of a school timetable?
- Saving the timetable as a PDF file
- Printing the timetable in colour
- Storing every student's full name and address
- Recording only class, room and time while ignoring seating arrangements Correct answer.
Explanation
Abstraction means keeping only the details relevant to the purpose and discarding the rest. A timetable model needs class, room and time, so seating arrangements are unnecessary detail. Storing extra personal data, colour printing and file format are presentation or storage choices, not abstraction.
Question 9Computational thinking
A list of 1000 unsorted names is searched one item at a time from the start. In the worst case, how many comparisons are needed?
- 500
- 1000 Correct answer.
- 1
- 10
Explanation
A linear search checks each item in turn, so the worst case is when the target is last or absent, requiring a comparison with every one of the 1000 items. Ten comparisons would suit a binary search on about 1024 sorted items. The other values do not match the worst case for linear search.
Question 10Computational thinking
A binary search is performed on a sorted array of 64 elements. What is the maximum number of comparisons needed to determine whether a value is present?
- 64
- 6 Correct answer.
- 32
- 8
Explanation
Each comparison halves the remaining search space, so the number of steps is about log base 2 of 64, which equals 6. Checking all 64 elements describes a linear search. Thirty-two is only the size after one halving, and 8 exceeds the halving count.
Question 11Computational thinking
A sorting algorithm compares each adjacent pair and swaps them if they are out of order, repeating passes until no swaps occur. Which algorithm is described?
- Bubble sort Correct answer.
- Selection sort
- Insertion sort
- Merge sort
Explanation
Repeatedly comparing and swapping adjacent out-of-order pairs across passes is the defining behaviour of bubble sort. Insertion sort places each item into a growing sorted section, selection sort repeatedly selects the minimum, and merge sort divides and merges. None of those rely on adjacent swaps across whole passes.
Question 12Computational thinking
A recursive function that calculates the sum of the numbers from 1 to n calls itself with n minus 1. Which component stops the recursion?
- A base case that returns a fixed value when n reaches 1 Correct answer.
- A loop inside the function
- A global variable that counts calls
- A second function that sorts the input
Explanation
Every recursive function needs a base case, a condition under which it returns a value without calling itself again. Here the base case is reached when n equals 1. Without it the function would call itself indefinitely until a stack overflow occurs.
Question 13Computational thinking
The expression (a > b) OR (c = d) is evaluated with a = 3, b = 7, c = 4 and d = 4. What is the result?
- An error
- Undefined
- True Correct answer.
- False
Explanation
The first comparison 3 > 7 is false, but the second comparison 4 = 4 is true. An OR expression is true when at least one operand is true, so the whole expression evaluates to true. The result is fully defined and no error occurs.
Question 14Computational thinking
A program stores the results of a survey in a two-dimensional array where rows are respondents and columns are questions. Which expression most likely gives the answer to question 3 for respondent 5, assuming zero-based indexing?
- survey[2][4]
- survey[3][5]
- survey[5][3]
- survey[4][2] Correct answer.
Explanation
With zero-based indexing, respondent 5 is at row index 4 and question 3 is at column index 2. The row index is written first in a two-dimensional array access. The other expressions either use one-based values or swap the row and column roles.
Question 15Computational thinking
A procedure receives a number and returns true if the number is even and greater than 10. Which input causes the procedure to return true?
- 7
- 11
- 14 Correct answer.
- 8
Explanation
The value must satisfy both conditions: divisible by two with no remainder and strictly greater than ten. Fourteen is even and greater than ten, so it passes. Eight is even but too small, while eleven and seven are not even.
Question 16Computational thinking
A programmer traces a loop and records the values of a running total after each pass. Which computational thinking practice does this best illustrate?
- Refactoring the code for style
- Encrypting the stored data
- Dry running the algorithm with test data Correct answer.
- Compiling the program for release
Explanation
Manually stepping through an algorithm and tracking variable values is called a dry run or desk check, and it is used to verify logic before or without execution. Compiling, refactoring and encrypting are separate activities. Dry running helps reveal off-by-one and logic errors early.
Question 17Computational thinking
An algorithm processes n items with a single loop that contains no nested loops. Which time complexity class best describes it?
- O(1)
- O(n) Correct answer.
- O(n squared)
- O(log n)
Explanation
A single loop that performs a constant amount of work per item grows linearly with the input size, giving O(n). Nested loops over the same input typically produce O(n squared). Logarithmic and constant growth describe halving searches and fixed-work operations respectively.
Question 18Computational thinking
A function is defined to call itself with the same argument every time and has no base case. What is the most likely result when it runs?
- It runs in constant time
- It recurses until the call stack overflows Correct answer.
- It converts into an iterative loop automatically
- It returns the correct answer immediately
Explanation
Without a base case, and with an unchanged argument, the recursive calls never reach a stopping condition. Each call adds a frame to the call stack until memory for the stack is exhausted, producing a stack overflow. Nothing in the definition converts it into a loop or bounds the work.
Question 19Computational thinking
A student models a queue of customers using an array where new customers join at the rear and are served from the front. Which access rule does this model follow?
- Random access by key
- Last in, first out
- First in, first out Correct answer.
- Highest priority first
Explanation
A queue serves the item that has waited longest, which is first in, first out. Last in, first out describes a stack. Random access by key describes a dictionary or hash table, and priority ordering describes a priority queue.
Question 20Computational thinking
An algorithm splits a list in half, recursively sorts each half, then merges the sorted halves. Which statement about its behaviour is accurate?
- It compares only adjacent elements in the original list
- It requires the input to be already sorted
- It divides the problem into smaller sub-problems of the same type Correct answer.
- It selects the smallest remaining element on each pass
Explanation
This describes a divide-and-conquer approach such as merge sort, where the problem is repeatedly split into smaller instances of the same sorting problem. Adjacent comparisons describe bubble sort, and repeated minimum selection describes selection sort. The input need not be sorted beforehand.
Question 21Computational thinking
A program validates a password by checking length, presence of a digit and presence of a symbol, and only accepts the password if all three checks pass. Which Boolean structure does this require?
- A conjunction of three conditions Correct answer.
- A negation of all three conditions
- A disjunction of three conditions
- An exclusive disjunction of three conditions
Explanation
All three checks must succeed, which is a conjunction joined by AND. A disjunction joined by OR would accept a password meeting only one requirement. Exclusive disjunction would accept exactly one true condition, and negating all three would accept only passwords failing every check.
Question 22Computational thinking
A linear search and a binary search are both applied to the same sorted array of 1024 elements. Which statement correctly compares their worst-case performance?
- Both need exactly one comparison because the array is sorted
- Binary search needs about 10 comparisons while linear search needs up to 1024 Correct answer.
- Both need about 512 comparisons
- Binary search needs about 1024 comparisons while linear search needs about 10
Explanation
Binary search halves the search space each step, so about log base 2 of 1024, which is 10, comparisons are needed. Linear search may examine every element, giving up to 1024 comparisons. Sorting the array helps binary search but does not change the linear search worst case.
Question 23Computational thinking
A nested loop structure iterates an outer loop n times and an inner loop n times for each outer pass. Which complexity class describes the total number of inner-loop iterations?
- O(n)
- O(2 to the power n)
- O(n squared) Correct answer.
- O(log n)
Explanation
The inner loop runs n times for each of the n outer passes, giving n multiplied by n, which is n squared. Linear growth would require only one loop, and logarithmic growth arises from halving. Exponential growth comes from branching recursion, not a doubly nested loop.
Question 24Computational thinking
A recursive function computes Fibonacci numbers by calling itself twice, once with n minus 1 and once with n minus 2, without storing earlier results. Why does this approach become slow for larger n?
- Recursion cannot compute integer sequences
- Each call sorts the input again
- The base case is never reached for large n
- The same sub-problems are recomputed many times, causing exponential growth in calls Correct answer.
Explanation
The naive recursive definition recomputes identical sub-problems repeatedly, so the number of calls grows exponentially, roughly proportional to the golden ratio raised to n. The base cases are still reached, and recursion is perfectly capable of computing integer sequences. Memoisation or iteration removes the repeated work.
Question 25Computational thinking
A problem requires finding whether a value exists in a collection that is unsorted and changes frequently, with many insertions and lookups. Which data structure choice is most appropriate?
- A stack, giving last-in first-out access
- A sorted array searched with binary search
- A queue, giving first-in first-out access
- A hash table, giving average constant-time lookup Correct answer.
Explanation
A hash table supports average constant-time insertion and lookup without needing sorted order, which suits frequent changes and lookups. Binary search requires a sorted array, and maintaining sorted order under frequent insertions is costly. Stacks and queues restrict access order and do not support arbitrary key lookup efficiently.
Question 26Computational thinking
A program uses a variable called total to accumulate the sum of a list of scores. Which term best describes the role of this variable?
- An accumulator that builds a running result across iterations Correct answer.
- A constant whose value cannot change during execution
- A counter that stores how many scores were processed
- A flag that records whether a condition was met
Explanation
An accumulator is a variable that repeatedly combines new values into an existing running result, such as adding each score to a running sum. A counter also changes each pass but counts iterations rather than combining data values. Flags store true/false state and constants are not reassigned.
Question 27Computational thinking
A developer writes pseudocode using indentation to show which statements belong inside a conditional block. Which purpose does this indentation mainly serve?
- It shows the logical grouping of statements for human readers Correct answer.
- It prevents the conditional from being evaluated more than once
- It makes the algorithm run faster at execution time
- It declares the data types of the variables used
Explanation
Indentation in pseudocode is a readability device that visually communicates block structure, that is, which statements are controlled by a conditional or loop. It has no effect on execution speed or type declaration. The algorithm's logic would be identical without the indentation, only harder to read.
Question 28Computational thinking
A team breaks a large inventory system into modules for stock, orders and reporting, each with a clear interface. Which computational thinking concept does this best illustrate?
- Algorithm design
- Abstraction
- Decomposition Correct answer.
- Pattern recognition
Explanation
Decomposition is the practice of breaking a complex problem into smaller, more manageable parts that can be solved separately. Each module here is a distinct sub-problem with its own defined interface. Abstraction and pattern recognition may support the design, but the split into parts is the defining feature.
Question 29Computational thinking
Which data structure follows a last-in, first-out order when items are added and removed?
- Stack Correct answer.
- Linked list
- Array
- Queue
Explanation
A stack adds and removes items at the same end, so the most recently added item is the first removed, which is last-in, first-out. A queue removes from the opposite end, giving first-in, first-out. Arrays and linked lists are general containers whose access order depends on how they are used.
Question 30Computational thinking
A student writes the condition age >= 13 AND age <= 19 to test whether a person is a teenager. Which pair of values makes this condition true?
- 13 and 12
- 12 and 20
- 11 and 15
- 15 and 18 Correct answer.
Explanation
The AND operator requires both comparisons to be true, so the age must be at least 13 and at most 19. Only the pair 15 and 18 satisfies both bounds. Pairs containing a value outside the range fail at least one comparison.
Question 31Computational thinking
A variable named itemCount is used to store the number of items in a shopping cart. Which name would be a poorer choice for this variable?
- numItems
- cartQuantity
- totalItems
- x Correct answer.
Explanation
Meaningful identifiers describe the data they hold, which improves readability and maintenance. A single letter such as x gives no indication of content or purpose. The other options all communicate that the value relates to a count of items.
Question 32Computational thinking
A program stores a student's marks in a one-dimensional array and later needs to find the highest mark. Which approach correctly finds the maximum value?
- Set the maximum to the first mark and compare each remaining mark, keeping the larger Correct answer.
- Compare only the first and last marks in the array
- Add all marks together and divide by the number of marks
- Set the maximum to zero and compare each mark to it, keeping the larger
Explanation
Initialising the maximum with an actual element ensures correctness even when all values are negative. Each subsequent element is compared and replaces the maximum only if it is larger. Summing and dividing computes an average, and comparing only two elements can miss the true maximum.
Question 33Computational thinking
Which statement best describes the purpose of a test case in program development?
- It measures how many lines of code were written
- It documents the programmer's opinion of the code quality
- It specifies an input and the expected output used to check behaviour Correct answer.
- It lists the variables declared in a program
Explanation
A test case pairs a specific input with the output the program should produce, allowing behaviour to be verified against requirements. Running test cases reveals defects and confirms correctness. Variable lists and line counts are unrelated measures that do not test behaviour.
Question 34Computational thinking
An algorithm reads a list of temperatures and must report the number of days above 30 degrees. Which structure is most appropriate for this task?
- A nested loop that compares every pair of temperatures
- A single conditional with no loop
- A recursive function with no base case
- A loop that examines each temperature and increments a count when the condition holds Correct answer.
Explanation
Counting qualifying items requires visiting every element once, so a loop with a conditional inside is the natural structure. The count increases only when a temperature exceeds 30. Comparing every pair is unnecessary, and a recursion without a base case would not terminate.
Question 35Computational thinking
A program contains the loop: FOR i FROM 1 TO 4, then FOR j FROM 1 TO 3, printing i and j. How many lines are printed in total?
- 7
- 3
- 12 Correct answer.
- 4
Explanation
For each of the 4 outer iterations, the inner loop runs 3 times, so the total number of printed pairs is 4 multiplied by 3, which is 12. Adding the loop bounds would incorrectly treat the loops as sequential rather than nested. Nested loops multiply their iteration counts.
Question 36Computational thinking
A function is meant to swap two values held in variables a and b. Which sequence of steps correctly performs the swap?
- Set b to a, then set a to b
- Store a in a temporary variable, set a to b, then set b to the temporary value Correct answer.
- Set both a and b to the same value
- Set a to b, then set b to a
Explanation
A temporary variable preserves the original value of a before a is overwritten, so b can later receive it. Directly assigning one variable to the other destroys the original value. Assigning both variables the same value loses one of the two data items.
Question 37Computational thinking
A program must decide whether a year is a leap year. A leap year is divisible by 4, except century years, which are leap years only if divisible by 400. Which condition correctly expresses this rule?
- (year MOD 4 = 0 AND year MOD 100 <> 0) OR (year MOD 400 = 0) Correct answer.
- year MOD 100 = 0 OR year MOD 400 = 0
- year MOD 4 = 0 AND year MOD 400 = 0
- year MOD 4 = 0
Explanation
The rule has two qualifying cases joined by OR: ordinary years divisible by 4 but not by 100, and century years divisible by 400. Combining these with AND and OR captures both branches exactly. Simpler divisibility tests misclassify century years such as 1900.
Question 38Computational thinking
A program stores a queue of print jobs in a list. New jobs are appended to the end and the next job is taken from the start. Which operation removes the correct job?
- Remove the element with the largest value
- Remove the element at the last index
- Remove the element at index zero Correct answer.
- Remove a randomly chosen element
Explanation
A queue serves items in first-in, first-out order, and appending new jobs to the end means the oldest job sits at index zero. Removing index zero therefore serves the next job correctly. Removing from the end would reverse the order, behaving like a stack.
Question 39Computational thinking
A program must repeatedly prompt a user until a valid menu choice is entered. Which loop structure is most appropriate?
- A definite loop that runs exactly ten times
- A nested loop that iterates a fixed number of times for each choice
- A loop that never rechecks the input after the first read
- An indefinite loop that continues while the input is invalid Correct answer.
Explanation
The number of prompts is unknown in advance because it depends on user behaviour, so an indefinite loop controlled by a condition is appropriate. The loop reads input, tests validity and repeats only while the input fails the test. A definite loop would either stop too early or prompt unnecessarily.
Question 40Computational thinking
Two algorithms solve the same problem. Algorithm P performs n squared comparisons; algorithm Q performs n log n comparisons. For very large n, which statement is correct?
- Both will always require exactly the same number of comparisons
- The comparison counts cannot be compared for large n
- P will generally require fewer comparisons than Q
- Q will generally require fewer comparisons than P Correct answer.
Explanation
Growth rates determine behaviour as n becomes large, and n log n grows more slowly than n squared. Therefore Q generally performs fewer comparisons for large inputs. The gap widens as n increases, even though both may be similar for tiny inputs.
Question 41Computational thinking
A function receives a list and must return a new list containing only the even numbers, without changing the original list. Which approach satisfies this requirement?
- Loop over the input and remove odd values from the original list
- Create an empty result list, loop over the input and append each even value Correct answer.
- Return the original list unchanged
- Sort the original list and return it
Explanation
Building a separate result list preserves the original data while collecting only the values that meet the condition. Modifying the original list in place violates the requirement to leave it unchanged. Sorting or returning the input does not filter the values at all.
Question 42Computational thinking
A program records whether a search has found the target using a boolean variable called found, initially false. Which update correctly records a successful find?
- Set found to true inside the loop when a match occurs Correct answer.
- Increment found by one for each comparison
- Set found to the target value
- Set found to false inside the loop when a match occurs
Explanation
A boolean flag should be set to true when the searched condition is satisfied so later code can test it. Setting it to false on a match would record the opposite of the intended state. Incrementing or assigning the target value destroys the boolean meaning of the variable.
Question 43Computational thinking
A student writes a function that searches a list and returns the index of the first matching item, or minus one if no match exists. Which test input specifically checks the no-match path?
- An empty list of numbers with a target of zero
- A list whose first element matches the target
- A list in which no element matches the target Correct answer.
- A list whose last element matches the target
Explanation
To exercise the no-match path, the input must contain at least one element while none of them equals the target, forcing the function to return minus one. A first or last element match exercises the early and late success paths. The empty list with target zero is a boundary case rather than a clear no-match test.
Question 44Computational thinking
A recursive function computes powers of two by returning 2 multiplied by the result of calling itself with the exponent minus one. Which base case makes the function terminate correctly?
- When the exponent equals zero, return 1 Correct answer.
- When the exponent is negative, return the exponent
- No base case is needed because the exponent decreases
- When the exponent equals zero, call itself again with zero
Explanation
A recursive function needs a base case that returns a value without further calls, and for powers of two the exponent-zero case equals one. Each recursive call reduces the exponent by one until this base case is reached. Calling itself with the same value or relying on decrease alone does not guarantee termination.
Question 45Computational thinking
A program must store a fixed set of seven weekday names and retrieve them by their position number. Which structure is the most natural choice?
- A one-dimensional array Correct answer.
- A queue
- A stack
- A binary search tree
Explanation
A fixed-size collection accessed by numeric position is naturally represented as an array, where index zero holds the first weekday and so on. Stacks and queues restrict access order and do not support direct positional lookup. A binary search tree is unnecessary overhead for a small fixed ordered set.
Question 46Computational thinking
A program validates a form by checking each field with a separate function and combining the results. A field is accepted only when every check returns true. Which logical operator combines the check results?
- NOT
- AND Correct answer.
- XOR
- OR
Explanation
The requirement that every check must succeed corresponds to logical conjunction, so AND is used to combine the results. OR would accept the field when only one check passes, and NOT inverts a single result. XOR would accept exactly one true result but reject cases where several checks pass.
Question 47Computational thinking
An algorithm processes a sorted list by repeatedly halving the search range until the target is found or the range is empty. Which statement about its worst-case behaviour is correct?
- The number of steps grows logarithmically with the list size Correct answer.
- The number of steps grows linearly with the list size
- The number of steps grows with the square of the list size
- The number of steps is constant regardless of list size
Explanation
Halving the remaining range on each step means the number of steps is proportional to the logarithm of the list size to base two. Doubling the list size adds only one extra step. Linear, constant and quadratic growth do not describe repeated halving.
Question 48Computational thinking
A recursive function computes the nth Fibonacci number by calling itself with n minus 1 and n minus 2. Which inefficiency arises from this design?
- The function sorts the input before computing
- The function cannot return a value when n equals zero
- The function uses no stack memory at all
- The same subproblems are recomputed many times, causing exponential growth in calls Correct answer.
Explanation
Because each call branches into two further calls, overlapping subproblems such as the value for a small n are recomputed repeatedly, producing exponential growth in the number of calls. This is why techniques such as memoisation are used. The function does use stack memory and does not sort anything.
Question 49Computational thinking
A program must repeatedly find whether values exist in a collection that is unsorted and changes frequently. Which choice is most appropriate, and why?
- Linear search, because it guarantees constant-time performance
- Binary search, because it always examines fewer elements
- Linear search, because it works on unsorted data and needs no reordering after changes Correct answer.
- Binary search, because it requires the data to be sorted first
Explanation
Binary search requires sorted data, so frequent insertions would force repeated re-sorting or rebalancing. Linear search works on any order and tolerates changes without maintenance, which suits a frequently modified unsorted collection. Its cost is linear, but that trade-off is appropriate here.
Question 50Computational thinking
A programmer writes a function that takes a list of records and a key, and returns a new list of records matching the key. Which design change most improves reuse without changing behaviour?
- Copying the function once for every possible key value
- Passing the matching condition as a parameter so callers supply different criteria Correct answer.
- Removing the return value and printing results instead
- Hard-coding the key inside the function so callers cannot change it
Explanation
Parameterising the matching condition lets the same function serve many criteria without duplication, which improves reuse while preserving behaviour. Hard-coding or copying the function locks behaviour to specific keys. Removing the return value changes how callers use the result.