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
In computational thinking, what is meant by decomposition?
- Ordering the steps of an algorithm so it always terminates
- Recognising similarities between problems so one solution can be reused
- Removing unnecessary details from a problem so that only key features remain
- Breaking a complex problem into smaller sub-problems that can be solved separately Correct answer.
Explanation
Decomposition is the process of splitting a large, complex problem into smaller parts, each of which is easier to understand, solve and test. The sub-solutions are then combined to solve the original problem.
Question 2Computational thinking
A programmer ignores the colour of a car when designing a traffic simulation but keeps its speed and position. Which computational thinking technique is being applied?
- Abstraction Correct answer.
- Validation
- Iteration
- Decomposition
Explanation
Abstraction means removing detail that is not relevant to the problem so the model contains only the features needed. Colour is irrelevant to the simulation, while speed and position affect behaviour, so they are retained.
Question 3Computational thinking
Which statement best describes pattern recognition in computational thinking?
- Converting a design into a working program using a compiler
- Writing code in a modular style using procedures and functions
- Identifying features shared by problems so a common solution can be reused Correct answer.
- Testing an algorithm with several sets of data to find errors
Explanation
Pattern recognition is spotting similarities or recurring features across problems or within data. Once a pattern is identified, the same solution or rule can be applied again, which saves effort and supports generalisation.
Question 4Computational thinking
Which of these is a defining property of an algorithm rather than of a program?
- It must contain at least one loop structure
- It must be stored in secondary storage before it runs
- It must be written in a high-level language
- It must be finite, terminating after a limited number of steps Correct answer.
Explanation
An algorithm is a sequence of unambiguous steps that must terminate after a finite number of operations. It is a logical solution and does not depend on any particular language, storage medium or specific construct.
Question 5Computational thinking
A student writes pseudocode using indentation to show which statements belong inside a loop. Which feature of algorithm design does the indentation represent?
- The data types of the variables used
- The order in which procedures are declared
- The efficiency of the algorithm
- The structure and nesting of control constructs Correct answer.
Explanation
Indentation is used in pseudocode to make the nesting of sequence, selection and iteration visible. It shows which statements are controlled by a loop or conditional, improving readability of the algorithm's structure.
Question 6Computational thinking
Which pair correctly matches a standard flowchart symbol with its meaning?
- Rectangle - decision
- Diamond - process
- Ellipse - connector
- Parallelogram - input or output Correct answer.
Explanation
In standard flowchart notation a parallelogram represents input or output operations. The other symbols have fixed meanings: rectangle for process, diamond for decision and circle for connector.
Question 7Computational thinking
Which situation is best modelled using a linear search rather than a binary search?
- Finding a word in a sorted dictionary
- Locating a value in a sorted array of integers
- Checking whether a number exists in an ordered list of exam marks
- Finding a name in an unordered list of student records Correct answer.
Explanation
A binary search requires the data to be sorted so that half the list can be discarded at each step. An unordered list cannot be halved meaningfully, so a linear search that examines items one by one is the appropriate choice.
Question 8Computational thinking
What is the main purpose of a trace table when developing an algorithm?
- To store the final output of the program for the user
- To record the values of variables after each step so the logic can be checked Correct answer.
- To list the syntax errors reported by the compiler
- To measure the execution time of the compiled program
Explanation
A trace table is a manual dry-run tool that records variable values and outputs step by step. Comparing the traced values with expected values reveals logic errors in the algorithm before or after coding.
Question 9Computational thinking
An algorithm processes a list of n items and, for each item, scans the whole list once. Which statement about its time complexity is correct?
- It grows logarithmically, so it is O(log n)
- It grows linearly, so it is O(n)
- It grows quadratically, so it is O(n^2) Correct answer.
- It is constant, so it is O(1)
Explanation
The outer loop runs n times and the inner scan also performs about n operations, giving roughly n × n steps. The dominant term is n^2, so the algorithm is quadratic and written O(n^2).
Question 10Computational thinking
A binary search is performed on a sorted array of 1 000 elements. Approximately how many comparisons are needed in the worst case?
- 1 000
- 100
- 10 Correct answer.
- 500
Explanation
Binary search halves the remaining search space at each comparison, so the worst case is about log2(n) comparisons. Since 2^10 = 1024, roughly ten comparisons are needed for 1 000 elements.
Question 11Computational thinking
A bubble sort is applied to the list [5, 1, 4, 2]. What does the list look like after the first complete pass?
- [1, 2, 4, 5]
- [1, 4, 2, 5] Correct answer.
- [1, 5, 4, 2]
- [5, 4, 2, 1]
Explanation
A pass compares adjacent pairs and swaps when they are out of order: 5 and 1 swap, then 5 and 4 swap, then 5 and 2 swap, moving 5 to the end. The result after one pass is [1, 4, 2, 5].
Question 12Computational thinking
Which statement correctly distinguishes a procedure from a function?
- A function cannot take parameters, whereas a procedure must take parameters
- A procedure must be recursive, whereas a function must be iterative
- A procedure returns a value, whereas a function never returns one
- A function returns a value, whereas a procedure may perform an action without returning one Correct answer.
Explanation
In Cambridge IAL terminology a function is a subroutine that returns a value to the calling statement, while a procedure is a subroutine that performs a task and need not return a value. Both can accept parameters.
Question 13Computational thinking
What does it mean to say that an algorithm is generalisable?
- It solves a class of problems, not just one specific instance Correct answer.
- It always runs in the minimum possible number of steps
- It produces output without requiring any input data
- It can be written in more than one programming language
Explanation
A generalisable solution works for a range of inputs or instances of a problem rather than being hard-coded for one case. This is achieved by using parameters and by recognising patterns that apply to the whole class of problems.
Question 14Computational thinking
A programmer uses a divide-and-conquer approach to sort data. Which description matches this approach?
- Insert each item into its correct place within an already sorted section
- Repeatedly scan the whole list to find the smallest remaining item
- Split the data into smaller parts, sort each part, then combine the sorted parts Correct answer.
- Compare each pair of adjacent items and swap them until no swaps occur
Explanation
Divide and conquer decomposes the problem into smaller sub-problems of the same type, solves them, often recursively, and then combines the results. Merge sort is the classic example of this strategy.
Question 15Computational thinking
A recursive function has no base case. What is the most likely consequence when it is executed?
- It recurses until the call stack overflows and the program fails Correct answer.
- It returns the correct result but more slowly than an iterative version
- It returns zero because no terminating condition is defined
- It automatically converts itself into an iterative loop
Explanation
Every recursive algorithm needs a base case that stops further calls. Without one, calls continue to be pushed onto the call stack until memory for the stack is exhausted, producing a stack overflow.
Question 16Computational thinking
Which statement about the relationship between a stack and a recursive algorithm is correct?
- Recursion uses a queue so calls are returned in the order they were made
- A recursive algorithm cannot use a stack because stacks require iteration
- The stack stores only the final return value of the recursion
- Each recursive call is stored on the call stack and removed when that call returns Correct answer.
Explanation
When a subroutine calls itself, the system pushes a stack frame holding parameters and local variables. As each call finishes, its frame is popped, which is why the most recent call returns first (LIFO order).
Question 17Computational thinking
In a trace table for an algorithm containing a WHILE loop, which column is essential to show that the loop will terminate?
- The variable tested in the loop condition Correct answer.
- The final output of the algorithm
- The name of the procedure containing the loop
- The number of variables declared
Explanation
A WHILE loop continues while its condition is true, so termination depends on the tested variable changing. Tracing that variable shows whether the condition eventually becomes false or the loop runs forever.
Question 18Computational thinking
Which task is least suited to a binary search?
- Finding a target value in a sorted array of 10 000 records
- Finding the maximum value in an unsorted array Correct answer.
- Checking whether a word appears in an alphabetically ordered word list
- Locating a specific ID in a sorted list of student IDs
Explanation
Binary search requires sorted data and a comparison that eliminates half the remaining items. Finding a maximum in an unsorted array requires examining every element, so a linear scan is needed.
Question 19Computational thinking
Two algorithms solve the same problem: algorithm A is O(n^2) and algorithm B is O(n log n). For a very large input, which conclusion is justified?
- Both will take exactly the same time because they solve the same problem
- B will be slower because logarithmic terms grow faster than quadratic terms
- B will take fewer operations than A as n grows, though constant factors may matter for small n Correct answer.
- A will always be faster because quadratic algorithms use simpler instructions
Explanation
Big-O describes how the number of operations grows with input size, and n log n grows far more slowly than n^2. For large n, B therefore performs fewer operations, although constants and implementation details can dominate for small inputs.
Question 20Computational thinking
A recursive binary search is written so that it calls itself on the left half when the target is smaller than the middle element. Which change makes the algorithm terminate correctly?
- Return immediately when the lower bound exceeds the upper bound Correct answer.
- Remove the comparison with the middle element
- Always call the function on both halves before returning
- Increase the size of the array before each call
Explanation
A recursive search needs a base case for the situation where the search space becomes empty. When the lower bound passes the upper bound, the target is absent and the function must stop and report failure.
Question 21Computational thinking
A merge sort and an insertion sort are both applied to a large, randomly ordered data set. Which statement best explains why merge sort is usually preferred despite its extra memory use?
- Merge sort uses fewer comparisons on already sorted data than insertion sort does
- Merge sort sorts in place, so it needs less memory than insertion sort
- Insertion sort cannot be implemented iteratively and so requires recursion
- Merge sort guarantees O(n log n) comparisons, while insertion sort degrades to O(n^2) on random data Correct answer.
Explanation
Insertion sort is efficient on nearly sorted data but performs about n^2/2 comparisons on random data. Merge sort divides the data and merges sorted halves, giving O(n log n) in all cases, which dominates for large inputs despite needing auxiliary storage.
Question 22Computational thinking
A simulation of a queue at a ticket office is being designed. Which abstraction decision is most appropriate?
- Model each customer as an arrival time and a service duration, ignoring their names Correct answer.
- Ignore arrival times and assume customers appear at regular intervals
- Model the queue as a stack so the last customer is served first
- Model every personal detail of each customer to maximise realism
Explanation
Effective abstraction keeps only the attributes that affect the behaviour being studied. Arrival time and service duration determine waiting times, whereas names do not, so omitting them simplifies the model without losing relevant accuracy.
Question 23Computational thinking
An algorithm is required to decide whether two large collections of records contain any common record. Which approach best reflects decomposition combined with efficient searching?
- Compare every record in the first collection with every record in the second
- Sort both collections and then compare them element by element in order
- Sort one collection, then binary search it once for each record in the other collection Correct answer.
- Concatenate the collections and apply a linear search for each record
Explanation
The problem decomposes into preparing a searchable structure and then performing repeated lookups. Sorting once costs O(n log n) and each binary search costs O(log n), giving O(n log n) overall instead of the O(n^2) cost of comparing all pairs.
Question 24Computational thinking
A programmer claims that because an algorithm is expressed in pseudocode it must be correct. Which evaluation of this claim is valid?
- The claim is false, because pseudocode can contain logic errors that only testing or tracing reveals Correct answer.
- The claim is true, provided the pseudocode uses indentation consistently
- The claim is true, because pseudocode cannot express invalid operations
- The claim is false, because pseudocode cannot represent selection or iteration
Explanation
Pseudocode is a design notation and does not guarantee logical correctness. Errors such as incorrect conditions or missing initialisation remain, and these are found by dry runs, trace tables and testing against expected outputs.
Question 25Computational thinking
A programmer breaks a large problem into smaller sub-problems that are each solved independently, then combines the results. Which computational-thinking term best describes this strategy?
- Abstraction
- Serialisation
- Decomposition Correct answer.
- Validation
Explanation
Decomposition is the process of splitting a complex problem into smaller, more manageable parts that can be solved separately and then recombined. Abstraction instead removes unnecessary detail, and validation only checks that data or results are acceptable.
Question 26Computational thinking
When designing an algorithm, a developer decides to ignore the colour of a car and record only its registration and speed. Which computational-thinking technique is being applied?
- Recursion
- Abstraction Correct answer.
- Sorting
- Iteration
Explanation
Abstraction means removing or hiding detail that is not relevant to the problem so that only essential features are modelled. Ignoring car colour keeps the model focused on the data actually needed.
Question 27Computational thinking
A solution is developed by repeatedly refining a rough outline into more detailed steps until each step is a single unambiguous instruction. Which term describes this process?
- Pattern recognition
- Dry running
- Data validation
- Stepwise refinement Correct answer.
Explanation
Stepwise refinement (top-down design) takes a high-level outline and successively breaks each step into finer detail until the instructions are concrete. The result is a fully specified algorithm that can be implemented directly.
Question 28Computational thinking
A programmer writes an algorithm that uses a named block of code which can be called with different arguments to perform the same task on different data. Which benefit of this approach is most directly obtained?
- Guaranteed constant running time
- Automatic removal of logic errors
- Reusability of the code without duplication Correct answer.
- Elimination of the need for testing
Explanation
Encapsulating a task in a parameterised subroutine allows the same code to be reused with different inputs, avoiding duplicated logic. It does not by itself improve asymptotic complexity, fix logic errors, or remove the need to test.
Question 29Computational thinking
Which statement best describes the difference between a variable and a constant in an algorithm?
- A variable can only be assigned once, whereas a constant can be reassigned freely.
- A variable is stored in memory, whereas a constant is not stored at all.
- A variable must be numeric, whereas a constant may be of any data type.
- A variable's value may change during execution, whereas a constant's value is fixed once assigned. Correct answer.
Explanation
A variable is a named storage location whose value can be changed while the algorithm runs. A constant is assigned a value that must not change during execution, which helps prevent accidental modification.
Question 30Computational thinking
A student designs a program to decide whether a given word is a palindrome. Which sequence of computational-thinking stages is most appropriate?
- Perform pattern recognition on the keyboard layout before considering the word.
- Decompose the task into input, reversal, comparison and output, then abstract away irrelevant details before coding. Correct answer.
- Start with abstraction of the hardware, then decompose the operating system.
- Write the final code immediately, then decompose it afterwards if it fails.
Explanation
Good design decomposes the problem into identifiable sub-tasks (input, reversal, comparison, output), abstracts away anything irrelevant, and only then implements and tests. Coding before analysis tends to produce unstructured, error-prone solutions.
Question 31Computational thinking
A programmer needs to store a list of student marks where the number of students is not known in advance and marks will be added one at a time. Which data structure is most appropriate?
- A dynamic (resizable) array or list Correct answer.
- A single integer variable
- A fixed-size array declared with one element
- A Boolean flag
Explanation
A dynamic array or list can grow as new marks arrive, so it suits an unknown, changing number of items. A single variable or one-element array cannot hold a collection of unknown size, and a Boolean stores only true or false.
Question 32Computational thinking
An algorithm must find the largest value in an unsorted list of n numbers. Which approach is correct and efficient for this specific task?
- Compare every pair of elements and count how many times each is larger.
- Perform a binary search for the maximum value.
- Initialise a variable to the first element, then compare each remaining element once and update when a larger value is found. Correct answer.
- Sort the whole list with a bubble sort, then read the last element.
Explanation
A single linear pass that tracks the running maximum finds the largest value in O(n) time, which is optimal because every element must be examined at least once. Sorting does more work than necessary, and binary search requires sorted data.
Question 33Computational thinking
A validation routine checks that an entered date has a day between 1 and 31, a month between 1 and 12, and a year between 1900 and 2100. Which limitation does this routine have?
- It rejects all valid dates because the ranges are too narrow.
- It cannot be implemented in pseudocode.
- It incorrectly rejects 29 February in a leap year only.
- It accepts impossible dates such as 31 April because it checks each field independently. Correct answer.
Explanation
Range checks applied separately to each field do not test combinations, so a date such as 31 April passes even though it does not exist. A complete check needs cross-field logic such as month lengths and leap-year rules.
Question 34Computational thinking
A program must process a queue of print jobs so that jobs are handled in the order they arrive. Which pair of operations correctly implements this behaviour?
- Enqueue at the front and dequeue from the front
- Enqueue at the rear and dequeue from the front Correct answer.
- Push onto the top and pop from the top
- Insert at the front and remove from the rear
Explanation
A queue is a first-in-first-out structure: new items are added at the rear and removed from the front. This preserves arrival order, unlike a stack, which adds and removes at the same end.
Question 35Computational thinking
A programmer writes a loop that should add the numbers 1 to 10 inclusive, but initialises the total to 1 instead of 0. What type of error is this and what is the effect?
- A logic error; the final total is 1 too large. Correct answer.
- A runtime error; the program will crash.
- A data error; the input values are invalid.
- A syntax error; the program will not compile.
Explanation
The code is syntactically valid and will run, but the initial value is wrong, so the result is incorrect by one. This is a logic error, detected by comparing the output with a hand-calculated expected value.
Question 36Computational thinking
Two candidate algorithms solve the same problem. Algorithm P always examines every element once; algorithm Q sometimes stops early but in the worst case examines every element twice. Which statement is best supported?
- Both are O(n), but P has a smaller constant factor in the worst case. Correct answer.
- Q is asymptotically faster because it can stop early.
- Q is O(1) because it may finish after one comparison.
- P is O(n) and Q is O(n^2).
Explanation
Both algorithms grow linearly with n, so both are O(n). Big-O ignores constant factors, but in practice P performs fewer operations in the worst case, so it is preferable when worst-case behaviour matters.
Question 37Computational thinking
A simulation of traffic flow models each vehicle as an object with a position and speed, ignoring the make and colour of each car. Which statement best justifies this abstraction?
- Abstraction guarantees that the simulation matches reality exactly.
- Removing attributes always increases the accuracy of a simulation.
- Only the attributes that affect traffic movement are needed, so other detail can be omitted. Correct answer.
- Every real-world attribute must be modelled for the simulation to be valid.
Explanation
A simulation is built for a purpose, and abstraction keeps only the features relevant to that purpose. Make and colour do not influence traffic movement, so omitting them simplifies the model without reducing its usefulness.
Question 38Computational thinking
A recursive routine processes a list by removing one element per call. Which change is required to guarantee that the recursion terminates?
- A base case that is reached when the list becomes empty Correct answer.
- Storing the list in a global variable
- An additional loop inside each recursive call
- A larger initial list so that fewer calls are needed
Explanation
Recursion terminates only when a base case is reached that returns without making a further call. If each call removes one element, the base case must handle the empty list so the chain of calls eventually stops.
Question 39Computational thinking
A programmer needs to search a large, sorted database of records repeatedly for many different keys. Which combination of choices is most appropriate?
- Store the records in a sorted array and use a binary search for each key. Correct answer.
- Store the records in a stack and pop until the key is found.
- Store the records in a queue and dequeue until the key is found.
- Store the records in an unsorted list and use a linear search for each key.
Explanation
Binary search on sorted data finds a key in O(log n) comparisons, which is far better than linear search for a large database queried many times. The one-off cost of keeping the data sorted is repaid across repeated searches.
Question 40Computational thinking
A team must decide whether a proposed algorithm is fit for purpose before implementation. Which evaluation is the strongest evidence that the algorithm is correct and efficient?
- It is written in pseudocode using meaningful identifier names.
- It contains no comments and so is shorter than alternatives.
- It produces the expected output for boundary and typical test data, and its operation count grows proportionally to n log n. Correct answer.
- It was produced quickly by an experienced programmer.
Explanation
Correctness is evidenced by testing typical and boundary cases against expected results, and efficiency by analysing how the number of operations grows with input size. Presentation, authorship and code length are not evidence of either property.
Question 41Programming paradigms
In a purely functional language such as Haskell, which statement best describes the role of a function?
- A function always modifies at least one global variable to record its result
- A function returns a value only when it is given a pointer argument
- A function must be declared inside a class before it can be called
- A function maps input values to output values and produces no side effects Correct answer.
Explanation
Purely functional programming treats a function as a mathematical mapping from arguments to a result. Because evaluation has no side effects, calling the same function with the same arguments always yields the same value, which is what makes referential transparency possible.
Question 42Programming paradigms
A programmer writes a subroutine that takes another subroutine as an argument so it can be applied to every element of a list. Which paradigm feature does this illustrate?
- Higher-order functions Correct answer.
- Strong typing
- Dynamic binding
- Exception handling
Explanation
A higher-order function either accepts functions as parameters or returns a function as its result. Passing a subroutine into another subroutine so it can be applied across a list is the textbook example of this functional feature.
Question 43Programming paradigms
Which statement correctly distinguishes a class from an object in object-oriented programming?
- A class is created by copying an object, while an object is created by the compiler
- A class may contain methods, while an object may contain only attributes
- A class exists only at run time, while an object exists only in the source code
- A class is a template defining attributes and methods, while an object is an instance created from it Correct answer.
Explanation
A class acts as a blueprint that specifies the data members and methods shared by its instances. An object is a concrete instance of that blueprint, allocated with its own copy of the instance attributes.
Question 44Programming paradigms
In a procedural program, a large main routine is split into several smaller named subroutines that each perform one task. What is the main benefit of this change?
- The code becomes easier to read, test and reuse because each routine has a single clear purpose Correct answer.
- The program will always execute faster because subroutines run in parallel
- The need for parameter passing is removed entirely
- The program no longer needs any variables
Explanation
Decomposition into small subroutines improves readability and makes each unit independently testable and reusable. It supports the procedural principle of modular, top-down design rather than affecting execution speed or removing the need for data.
Question 45Programming paradigms
Which feature is characteristic of a declarative programming language?
- The programmer must manage memory addresses manually for each variable
- The programmer must write a loop for every repetition in the algorithm
- The programmer must specify the exact order of every machine instruction
- The programmer states what result is required and the language decides how to compute it Correct answer.
Explanation
Declarative languages describe the desired result or the logical relationships rather than an explicit sequence of steps. The language implementation determines the control flow needed to satisfy the declaration.
Question 46Programming paradigms
What does the term inheritance mean in an object-oriented language?
- A subclass acquires the attributes and methods of a superclass and may extend or override them Correct answer.
- A method calls itself repeatedly until a base case is reached
- An object keeps a private copy of every variable declared anywhere in the program
- Two classes exchange their method definitions at run time
Explanation
Inheritance establishes an is-a relationship in which a derived class reuses the members of a base class. The subclass can add new members and override inherited behaviour to specialise it.
Question 47Programming paradigms
A language allows a variable to hold an integer at one point and a string later in the same program. Which classification fits this language?
- Assembly language
- Statically typed
- Dynamically typed Correct answer.
- Strongly typed with mandatory declarations
Explanation
When the type of a variable is associated with its current value rather than fixed by a declaration, the language is dynamically typed. Type checking therefore happens at run time as values are assigned.
Question 48Programming paradigms
Which of these is a defining property of a logic programming language such as Prolog?
- Programs consist of classes and objects that exchange messages
- Programs consist of HTML tags rendered by a browser
- Programs consist of assignments executed in strict sequence
- Programs consist of facts and rules, and the system searches for solutions by resolution Correct answer.
Explanation
Logic programming expresses knowledge as facts and Horn-clause rules over a set of predicates. Execution is a query-driven search using resolution and unification rather than a fixed sequence of assignments.
Question 49Programming paradigms
A function is defined as f(x) = x + 1, and the expression f(3) + f(3) is evaluated. Assuming the function is pure, what is the result and why?
- 8, because the function stores a counter that increments on each call
- 8, because each call independently returns 4 and purity guarantees the same result for the same argument Correct answer.
- 6, because a pure function can be called only once per expression
- 7, because the second call reuses the first call's argument without adding 1
Explanation
A pure function returns the same output for the same input every time, so both calls return 4. Adding the two results gives 8, and no hidden state can alter either call.
Question 50Programming paradigms
A class Vehicle has a method describe() returning "vehicle". Class Car extends Vehicle and overrides describe() to return "car". Given the declaration Vehicle v = new Car(); which result does v.describe() produce in a typical object-oriented language?
- "vehiclecar", because both method bodies are concatenated
- "vehicle", because the variable's declared type always selects the method
- "car", because the object's actual type determines which overridden method runs Correct answer.
- A compile error, because a Car cannot be assigned to a Vehicle variable
Explanation
With dynamic dispatch, the method invoked depends on the run-time type of the object, which is Car. The overridden version therefore executes even though the reference variable is declared as Vehicle.