VCE Algorithmics (HESS) study materials
VCE Algorithmics (HESS) study resources

VCE Algorithmics (HESS) practice questions

One question at a time. Build your VCE Algorithmics (HESS) understanding.

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 1Unit 3

In pseudocode, which control structure repeats a block of statements while a condition remains true and tests the condition before each iteration?

  1. A for loop
  2. A procedure call
  3. An if statement
  4. A while loop Correct answer.

Explanation

A while loop evaluates its condition at the start of each pass and continues executing the body only while that condition evaluates to true, so the body may run zero times. A for loop is typically used for a known number of iterations, an if statement branches once, and a procedure call transfers control to a named subroutine.

Question 2Unit 3

A student writes a function that calls itself on a smaller version of the same input, stopping when the input reaches a base case. Which technique is being used?

  1. Recursion Correct answer.
  2. Parallelism
  3. Iteration
  4. Memoisation

Explanation

Recursion is a technique where a function solves a problem by calling itself on a reduced instance, with one or more base cases that terminate the chain of calls. Iteration instead uses loops, parallelism runs tasks concurrently, and memoisation caches results of earlier calls.

Question 3Unit 3

Which data structure removes elements in last-in, first-out order?

  1. A linked list
  2. A binary search tree
  3. A stack Correct answer.
  4. A queue

Explanation

A stack supports push and pop at one end, so the most recently added element is the first removed, giving last-in first-out behaviour. A queue is first-in first-out, while linked lists and binary search trees are general structures with no mandated removal order.

Question 4Unit 3

A linear search is performed on a list of n elements and the target is not present. How many comparisons does the algorithm make?

  1. 1
  2. log base 2 of n
  3. n squared
  4. n Correct answer.

Explanation

Linear search examines each element in turn, so when the target is absent every one of the n elements is compared once, giving n comparisons. Searching stops early only when the target is found, which cannot happen here.

Question 5Unit 3

Which statement best describes the purpose of an algorithm?

  1. A finite sequence of unambiguous steps that transforms input into output Correct answer.
  2. A programming language used to express computations
  3. A hardware device that executes instructions
  4. A collection of test cases for software

Explanation

An algorithm is an abstract, finite procedure: a well-ordered set of unambiguous steps that, given valid input, produces a result in finite time. It is independent of any particular programming language, machine, or testing framework.

Question 6Unit 3

A trace table is used while testing an algorithm. What is its main purpose?

  1. Recording the values of variables after each step to check the logic Correct answer.
  2. Measuring the speed of the processor during execution
  3. Converting pseudocode into machine code
  4. Storing the final output of the program permanently

Explanation

A trace table records variable values and outputs step by step as an algorithm is hand-executed, letting a programmer verify that the logic produces expected intermediate results. It is a desk-checking tool, not a performance measurement or compilation mechanism.

Question 7Unit 3

In a graph, what does a directed edge represent?

  1. A one-way relationship from one vertex to another Correct answer.
  2. A vertex with no incident edges
  3. A path that visits every vertex exactly once
  4. A connection that can be traversed in either direction

Explanation

A directed edge, or arc, has an ordered pair of endpoints, so it can be followed only from its source vertex to its destination vertex. Undirected edges allow travel both ways, an isolated vertex has no edges, and a path visiting every vertex once is a Hamiltonian path.

Question 8Unit 3

Which of the following is a characteristic of a well-designed algorithm rather than of a specific implementation?

  1. It relies on the fastest available processor
  2. It produces output only when run by its original author
  3. It uses the fewest possible lines of source code
  4. It terminates after a finite number of steps for all valid inputs Correct answer.

Explanation

Termination for all valid inputs is a fundamental correctness property of an algorithm, alongside definiteness, effectiveness, and finiteness. Line count, processor speed, and authorship are implementation or environment matters that do not define algorithmic quality.

Question 9Unit 3

A sorted list contains 15 elements. A binary search is used. What is the maximum number of comparisons needed to determine whether a target is present?

  1. 15
  2. 2
  3. 8
  4. 4 Correct answer.

Explanation

Binary search halves the remaining search space each time, so the maximum number of comparisons is the ceiling of log base 2 of 15, which is 4, since 2 to the power 3 is 8 and 2 to the power 4 is 16. The list must be sorted for this halving to be valid.

Question 10Unit 3

An algorithm contains two consecutive loops, the first performing n steps and the second performing n steps. What is its time complexity in big-O notation?

  1. O(n squared)
  2. O(log n)
  3. O(2 to the power n)
  4. O(n) Correct answer.

Explanation

Sequential loops add their costs, so n plus n equals 2n, and constant factors are discarded in big-O notation, leaving O(n). Quadratic complexity would require the loops to be nested, and exponential or logarithmic growth does not match a simple double scan.

Question 11Unit 3

What is the essential requirement for binary search to work correctly?

  1. The elements must be unique
  2. The elements must be stored in a linked list
  3. The elements must be in sorted order Correct answer.
  4. The number of elements must be a power of two

Explanation

Binary search compares the target with the middle element and then discards one half, which is only valid if the data is ordered so that all smaller values lie on one side. List length, storage structure, and duplicate values do not invalidate the method as long as ordering is maintained.

Question 12Unit 3

A recursive function computes values without a base case. What is the most likely consequence when it is executed?

  1. It sorts its input before returning
  2. It automatically converts into an iterative loop
  3. It recurses until the call stack overflows Correct answer.
  4. It returns the correct answer faster

Explanation

Without a base case the recursive calls never reach a terminating condition, so frames accumulate on the call stack until memory is exhausted and a stack overflow occurs. Compilers do not generally convert such non-terminating recursion into loops, and no correct result is produced.

Question 13Unit 3

A queue is used to manage print jobs. Jobs arrive in the order J1, J2, J3 and are processed one at a time. Which job is processed first?

  1. A randomly selected job
  2. J2
  3. J3
  4. J1 Correct answer.

Explanation

A queue is first-in first-out, so the earliest enqueued item, J1, is dequeued and processed first. This ordering preserves fairness by handling jobs in arrival sequence rather than by size or random choice.

Question 14Unit 3

Which pair of traversal methods is used to explore all vertices reachable from a start vertex in a graph?

  1. Depth-first search and breadth-first search Correct answer.
  2. Push and pop
  3. Binary search and linear search
  4. Bubble sort and insertion sort

Explanation

Depth-first search and breadth-first search are the two standard systematic graph traversals, differing in whether they explore as far as possible along a branch or level by level. The other pairs are searching, sorting, and stack operations respectively.

Question 15Unit 3

An adjacency matrix is used to represent an undirected graph with n vertices. What does the entry in row i, column j record?

  1. The order in which vertex i was visited
  2. The shortest path length between vertex i and vertex j
  3. Whether an edge exists between vertex i and vertex j Correct answer.
  4. The degree of vertex i only

Explanation

An adjacency matrix stores a value in cell (i, j) indicating whether an edge connects vertex i and vertex j, and for an undirected graph the matrix is symmetric. Shortest path lengths and traversal orders require separate computation and are not stored directly.

Question 16Unit 3

A programmer needs to check whether a value appears in an unordered list of 1000 items exactly once. Which approach is most appropriate?

  1. Use a stack to pop elements until the value appears
  2. Build a balanced tree and then traverse it
  3. Perform a linear search over the list Correct answer.
  4. Sort the list and then perform a binary search

Explanation

For a single membership check on unordered data, a linear search needs at most 1000 comparisons and requires no preprocessing. Sorting first costs far more than a single scan, and building a tree or using a stack adds structure without benefit for one query.

Question 17Unit 3

An algorithm's running time is described as O(n log n). Which statement about this growth is correct?

  1. It grows faster than O(n) but slower than O(n squared) Correct answer.
  2. It grows faster than O(n squared)
  3. It grows at exactly the same rate as O(n)
  4. It grows slower than O(n) but faster than O(log n)

Explanation

The function n log n lies between linear and quadratic growth for large n, since log n increases without bound but more slowly than n. Efficient comparison sorts such as merge sort achieve this bound, which is why it is regarded as better than quadratic but worse than linear.

Question 18Unit 3

A recursive function to compute the nth Fibonacci number calls itself twice at each level without caching. Why does its running time grow exponentially?

  1. The base cases are evaluated more than once per call
  2. The same subproblems are recomputed many times, so the number of calls roughly doubles per level Correct answer.
  3. Each call performs n squared operations internally
  4. The function uses too much memory for its parameters

Explanation

Naive Fibonacci recursion solves overlapping subproblems repeatedly, so the recursion tree branches twice per level and the total number of calls grows approximately as the golden ratio raised to n. Memoisation removes this duplication by storing each computed value.

Question 19Unit 3

A binary search is applied to a list of 1000 sorted elements. Approximately how many comparisons are needed in the worst case?

  1. 10 Correct answer.
  2. 1000
  3. 100
  4. 500

Explanation

Binary search needs about log base 2 of n comparisons, and since 2 to the power 10 is 1024, roughly 10 comparisons suffice for 1000 elements. This logarithmic behaviour is what makes binary search dramatically faster than scanning the list.

Question 20Unit 3

A graph traversal uses a stack to decide which vertex to explore next. Which traversal does this implement?

  1. Depth-first search Correct answer.
  2. Breadth-first search
  3. Topological ordering
  4. Dijkstra's shortest path

Explanation

Depth-first search explores as far as possible along one branch before backtracking, which corresponds exactly to the last-in first-out behaviour of a stack. Breadth-first search instead uses a queue to explore vertices level by level.

Question 21Unit 3

An algorithm processes a list by, for each element, scanning the entire list once. What is its time complexity?

  1. O(1)
  2. O(n)
  3. O(n log n)
  4. O(n squared) Correct answer.

Explanation

When a full scan of n elements is nested inside a loop that itself runs n times, the total work is n multiplied by n, giving quadratic growth O(n squared). Sequential scans would instead add to give linear growth.

Question 22Unit 3

A recursive algorithm splits a problem of size n into two halves, solves each half recursively, and then combines the results in linear time. What is its time complexity?

  1. O(log n)
  2. O(2 to the power n)
  3. O(n log n) Correct answer.
  4. O(n squared)

Explanation

Two recursive calls on half-sized inputs plus linear combination work matches the recurrence T(n) equals 2T(n/2) plus O(n), which solves to O(n log n). This is the classic profile of merge sort and similar divide-and-conquer algorithms.

Question 23Unit 3

A programmer must repeatedly test membership in a large, unchanging collection of values. Which strategy gives the best expected performance for many queries?

  1. Sort the collection once and use binary search for each query Correct answer.
  2. Store the collection in a stack and pop until the value is found
  3. Re-sort the collection before every query
  4. Use linear search for every query

Explanation

Sorting once costs O(n log n), after which each binary search query costs only O(log n), which is far better than O(n) per query for a large number of lookups. Sorting repeatedly or scanning linearly multiplies cost unnecessarily.

Question 24Unit 3

A breadth-first search is run on an unweighted graph from a start vertex. What property do the distances it records have?

  1. They give the total edge weight of the cheapest path
  2. They give the order in which vertices were inserted into the stack
  3. They give the minimum number of edges from the start to each reachable vertex Correct answer.
  4. They give the number of vertices with the same label

Explanation

Breadth-first search visits vertices in order of increasing edge count from the start, so the level at which a vertex is first reached equals the shortest unweighted path length. Weighted shortest paths require algorithms such as Dijkstra's, and breadth-first search uses a queue rather than a stack.

Question 25Unit 3

Two algorithms solve the same problem: algorithm A runs in O(n squared) time and algorithm B runs in O(n log n) time. For very large inputs, which conclusion is justified?

  1. Both algorithms will take identical time for all inputs
  2. Algorithm B is incorrect because logarithmic algorithms cannot be general
  3. Algorithm A will always finish first because it has fewer lines of code
  4. Algorithm B will generally require fewer operations as input size grows Correct answer.

Explanation

Asymptotic complexity describes how work grows with input size, and n log n grows far more slowly than n squared, so algorithm B generally performs fewer operations on large inputs. Constant factors and implementation details can matter for small inputs but are dominated at scale.

Question 26Unit 3

Which data structure stores an unordered collection of unique values and supports very fast membership testing?

  1. A stack implemented with an array
  2. A priority queue implemented with a heap
  3. A queue implemented with a linked list
  4. A set implemented with a hash table Correct answer.

Explanation

A hash-based set maps each value to a bucket, so membership tests usually take constant time on average. Stacks, queues and heaps organise elements by order rather than by value, so they cannot test membership quickly.

Question 27Unit 3

An algorithm performs a constant number of operations regardless of input size n. Which complexity class describes it?

  1. O(log n)
  2. O(1) Correct answer.
  3. O(n log n)
  4. O(n)

Explanation

Constant time means the number of operations does not grow with the input size, which is written O(1). Logarithmic and linear classes both grow as n increases.

Question 28Unit 3

A stack is used to reverse a word. Characters are pushed one at a time and then popped until the stack is empty. Which property of the stack makes this work?

  1. Elements are removed in the same order they were inserted
  2. Elements are removed in sorted order
  3. Elements are removed in the reverse order they were inserted Correct answer.
  4. Elements are removed in random order

Explanation

A stack is last-in-first-out, so the final character pushed is the first one popped. Popping the whole stack therefore yields the characters in reverse order.

Question 29Unit 3

Which statement best describes the role of an invariant in proving an algorithm correct?

  1. It is a variable that never changes value during execution
  2. It is a measure of how many operations the algorithm performs
  3. It is a test case used to check the algorithm's output
  4. It is a condition that holds before and after every iteration of a loop Correct answer.

Explanation

A loop invariant is a property that is true before the loop begins and is preserved by each iteration, so it holds after the loop ends. Showing that the final invariant implies the desired result completes a correctness proof.

Question 30Unit 3

A graph has 6 vertices and is represented by an adjacency list. Which structure best describes the adjacency list representation?

  1. An array of 6 lists, one list per vertex holding its neighbours Correct answer.
  2. A single list containing all 6 vertices in order
  3. A 6 by 6 matrix of edge weights
  4. A 6 by 6 grid of booleans

Explanation

An adjacency list stores, for each vertex, a list of the vertices adjacent to it. This uses space proportional to the number of vertices plus edges rather than the square of the vertices.

Question 31Unit 3

A function calls itself with a smaller argument each time and stops when the argument reaches zero. What is the stopping condition called?

  1. The call stack
  2. The base case Correct answer.
  3. The recursive step
  4. The parameter list

Explanation

The base case is the condition under which the recursion stops and a value is returned directly. Without a base case the function would keep calling itself indefinitely.

Question 32Unit 3

A program must store pairs of a student identifier and a score, then look up scores by identifier. Which structure is most suitable?

  1. A dictionary mapping identifiers to scores Correct answer.
  2. A stack of scores
  3. A queue of identifiers
  4. A set of scores

Explanation

A dictionary stores key-value pairs and allows a value to be retrieved directly from its key. This matches looking up a score from a student identifier in near-constant time.

Question 33Unit 3

Which of the following is a formal specification of a computational problem?

  1. A diagram of the hardware on which the program runs
  2. A working program written in a specific language
  3. A list of test cases with expected results
  4. A description of the inputs, the required outputs and the relationship between them Correct answer.

Explanation

A formal problem specification states what inputs are allowed, what outputs are required and how outputs relate to inputs. It deliberately avoids prescribing an implementation.

Question 34Unit 3

An algorithm makes a single pass over a list of n items, and inside the loop it performs a fixed number of operations. What is its time complexity?

  1. O(log n)
  2. O(n squared)
  3. O(1)
  4. O(n) Correct answer.

Explanation

A single pass visiting each of n items once performs a constant amount of work per item, giving a total proportional to n. Hence the complexity is linear, O(n).

Question 35Unit 3

A binary search is performed on a sorted array. After each comparison the algorithm discards half of the remaining elements. Why is the complexity logarithmic?

  1. Because the array contains unique values
  2. Because the number of remaining elements is halved at each step Correct answer.
  3. Because the array is stored in contiguous memory
  4. Because each comparison takes constant time

Explanation

Halving the search space means the number of steps k satisfies 2 to the power k approximately equals n, so k grows like log n. Contiguous storage and constant comparison cost do not by themselves produce logarithmic growth.

Question 36Unit 3

A recursive function solves a problem of size n by making one recursive call on size n minus 1 and doing constant work otherwise. How many calls are made in total for input n?

  1. A number proportional to n squared
  2. A constant number
  3. A number proportional to log n
  4. A number proportional to n Correct answer.

Explanation

Each call reduces the size by exactly one, so the chain of calls has length proportional to n before reaching the base case. The total work is therefore linear in n.

Question 37Unit 3

A depth-first search is run on a connected graph. Which data structure most directly models the order in which vertices are explored?

  1. A heap
  2. A queue
  3. A stack Correct answer.
  4. A hash set

Explanation

Depth-first search explores as far as possible along one path before backtracking, which corresponds to last-in-first-out behaviour. A stack, explicitly or through recursion, provides this order.

Question 38Unit 3

An algorithm sorts a list by repeatedly finding the minimum of the unsorted part and swapping it into place. What is its worst-case time complexity?

  1. O(log n)
  2. O(n log n)
  3. O(n squared) Correct answer.
  4. O(n)

Explanation

Finding the minimum of the remaining unsorted portion requires scanning it, and this scan is repeated for each position. The total number of comparisons is about n times n divided by two, which is quadratic.

Question 39Unit 3

Which statement correctly distinguishes a proof by induction from testing an algorithm on sample inputs?

  1. Testing guarantees correctness for all inputs
  2. Induction covers all valid inputs, while testing covers only the cases tried Correct answer.
  3. Induction is faster to perform than testing
  4. Induction only works for iterative algorithms

Explanation

An inductive proof establishes a base case and an inductive step, which together cover every valid input. Testing can only demonstrate correct behaviour on the particular cases examined.

Question 40Unit 3

A hash table stores n keys in a table with many more slots than n, and the hash function distributes keys evenly. What is the expected time for a lookup?

  1. Logarithmic in n
  2. Quadratic in n
  3. Constant on average Correct answer.
  4. Linear in n

Explanation

With a good hash function and low load factor, each key maps to a slot with few collisions, so lookups take constant time on average. Degradation toward linear time occurs only when many keys collide.

Question 41Unit 3

Two functions describe an algorithm's work: f(n) equals 3n squared plus 5n plus 7. Which simplified asymptotic bound is correct?

  1. O(n squared) Correct answer.
  2. O(7)
  3. O(n)
  4. O(5n)

Explanation

In asymptotic analysis the fastest-growing term dominates and constant factors are discarded, so 3n squared plus lower terms is O(n squared). The lower-order terms become negligible as n grows.

Question 42Unit 3

A breadth-first search records the distance from the start vertex to each reached vertex. Why are these distances guaranteed to be shortest in an unweighted graph?

  1. Because vertices are visited in order of increasing distance from the start Correct answer.
  2. Because the graph is connected
  3. Because each edge has a different weight
  4. Because the adjacency list is sorted

Explanation

Breadth-first search explores all vertices at distance k before any vertex at distance k plus one. Therefore the first time a vertex is reached, it is reached by a path with the fewest possible edges.

Question 43Unit 3

A programmer needs a data structure that always returns the smallest stored value first, with items inserted over time. Which structure is appropriate?

  1. A hash set
  2. A queue
  3. A min-heap Correct answer.
  4. A stack

Explanation

A min-heap keeps the smallest element at the root so it can be retrieved efficiently, while still supporting efficient insertion. Stacks and queues order by time of arrival rather than by value.

Question 44Unit 3

An algorithm's recurrence is T(n) equals 2 times T(n divided by 2) plus n, with T(1) equal to 1. What is the complexity of T(n)?

  1. O(log n)
  2. O(n log n) Correct answer.
  3. O(n)
  4. O(n squared)

Explanation

The recursion tree has log n levels, and the total work at each level is n, giving n log n overall. This matches the complexity of merge sort, which has the same recurrence.

Question 45Unit 3

A proof of a loop's correctness uses an invariant. Which combination of facts is sufficient to conclude the postcondition holds after the loop terminates?

  1. The invariant holds initially and is preserved by each iteration, and the loop terminates Correct answer.
  2. The loop terminates after a finite number of iterations
  3. The loop body performs a constant number of operations
  4. The invariant holds after the first iteration only

Explanation

Initialisation establishes the invariant, maintenance preserves it, and termination ensures the loop ends with the invariant true. Combining the final invariant with the exit condition then yields the postcondition.

Question 46Unit 3

An algorithm must decide whether two large sets of n integers share any common element. Which approach gives the best expected worst-case asymptotic performance?

  1. Insert one set into a hash set, then test each element of the other Correct answer.
  2. Concatenate both sets and scan the result once
  3. For each element of the first set, scan the entire second set
  4. Sort both sets, then compare every pair of elements

Explanation

Building a hash set from one collection takes expected linear time, and testing each element of the other takes constant expected time per element. The total is expected O(n), better than the quadratic pairwise comparisons.

Question 47Unit 3

A recursive algorithm makes three recursive calls on inputs of size n divided by 2 and does constant work to combine results. What is the resulting complexity?

  1. O(n log n)
  2. O(n to the power log base 2 of 3) Correct answer.
  3. O(n squared)
  4. O(n)

Explanation

For a recurrence T(n) equals a times T(n divided by b) plus constant work, the complexity is n to the power log base b of a. Here a is 3 and b is 2, so the exponent is log base 2 of 3, about 1.58.

Question 48Unit 3

A weighted graph has non-negative edge weights, and the shortest path from one source to all others is required. Why does breadth-first search fail for this task?

  1. Breadth-first search cannot visit all vertices of a weighted graph
  2. Breadth-first search cannot use an adjacency list
  3. Breadth-first search minimises the number of edges, not the total weight Correct answer.
  4. Breadth-first search requires the graph to be a tree

Explanation

Breadth-first search treats every edge as costing the same, so it finds paths with the fewest edges. When weights differ, a path with more edges may have a smaller total weight, so a weight-aware algorithm is needed.

Question 49Unit 3

A decision problem is shown to be solvable by verifying a proposed solution in polynomial time. To which class does this place the problem?

  1. NP Correct answer.
  2. Exponential only
  3. P
  4. Undecidable

Explanation

NP contains decision problems whose yes-instances have a certificate that can be verified in polynomial time. Membership in P is a stronger claim requiring a polynomial-time solving algorithm.

Question 50Unit 3

In pseudocode, a variable x is declared to hold a whole number. Which term describes the kind of value x may store?

  1. Recursion depth
  2. Loop invariant
  3. Edge weight
  4. Data type Correct answer.

Explanation

A data type specifies the set of values a variable can hold and the operations permitted on those values, such as integer or Boolean. Declaring x as an integer restricts it to whole numbers and allows arithmetic operations.