How to use these practice questions

These questions cover common data structures and algorithms topics: complexity, stacks, hash tables, linked lists, sorting, graph traversal and dynamic programming. They are written as single-best-answer questions, but the useful part is the reasoning: identify what the question asks, select the relevant rule, then check why the nearest alternative does not fit.

In MySummaries, a question can be marked in the browser with its answer and explanation alongside it. Try each question as it appears, then read the explanation before moving to the next one. Pay particular attention to assumptions such as whether a graph has negative edge weights or whether a linked-list node is already available; those details often determine the answer.

Ten practice questions

1. Binary search

This checks whether you can distinguish worst-case search complexity from the cost of scanning every element. Question 1 is presented like this:

Question 11 mark

A sorted array contains n elements. What is the worst-case time complexity of finding a target using binary search?

Binary search halves the remaining search interval at each comparison, so the number of comparisons grows logarithmically with n. O(n) is the strongest distractor because it is the worst-case cost of a linear scan, not binary search on sorted data.

The sorted order is essential: it lets each comparison rule out half the remaining values. If the array is unsorted, binary search cannot safely discard half the elements this way.

2. A stack for bracket matching

This tests how a data structure can track the most recent unmatched symbol. Question 2:

Question 21 mark

Which data structure is the most suitable for checking whether brackets in an expression are correctly nested?

A stack uses last-in, first-out order. When a closing bracket appears, the most recently opened bracket is the one that must match it. A queue is the strongest distractor, but its first-in, first-out order does not track nested pairs correctly.

For an opening bracket, push its type. For a closing bracket, check that the stack is non-empty and its top has the matching type, then pop. A valid expression must finish with an empty stack.

3. Hash-table lookup

This question checks the difference between expected performance and a worst-case bound. Question 3:

Question 31 mark

With a well-distributed hash function and a controlled load factor, what is the expected time complexity of looking up a key in a hash table?

Under the stated assumptions, a lookup takes constant expected time because keys are spread across the table and collision chains remain manageable. O(n) is the strongest distractor: it can occur in a poor worst case when many keys collide, but it is not the expected bound given here.

Do not turn “expected O(1)” into “always O(1)”. A hash table can have linear worst-case lookup when collisions concentrate, and its performance depends on the hash function and table management.

4. Inserting into a linked list

This checks whether you notice that the location of the insertion point is already known. Question 4:

Question 41 mark

In a singly linked list, a pointer to node p is already available. What is the time complexity of inserting a new node immediately after p?

Only a constant number of pointer updates are required: link the new node to p's former successor, then link p to the new node. O(n) is the strongest distractor because finding a position by traversing the list takes linear time; that search is excluded by the given pointer.

The operation is constant time because it does not require searching for p. If the question instead asked you to find the node at a particular index first, traversal would generally take O(n).

5. Merge sort

This tests recognition of both a sorting algorithm’s worst-case time and its usual auxiliary-space requirement. Question 5:

Question 51 mark

Which statement describes standard merge sort on an array of n elements?

Merge sort divides the input into logarithmically many levels and does O(n) merging work per level, giving O(n log n) time. Standard array implementations use O(n) auxiliary space for merging. O(1) auxiliary space is the strongest distractor, but it does not describe the standard implementation.

A useful way to remember the time bound is to count the work by recursion level: each level processes all n elements, and there are O(log n) levels. In-place variants are a separate implementation detail, not the standard array version described here.

6. Dijkstra’s algorithm

This checks the condition that makes a familiar shortest-path algorithm appropriate. Question 6:

Question 61 mark

Which condition is required for Dijkstra's algorithm to correctly find shortest paths from a source in a weighted graph?

Dijkstra's algorithm relies on the fact that once the currently closest unvisited vertex is selected, a later path cannot improve it. Negative edge weights break that reasoning. Requiring a tree is the strongest distractor, but Dijkstra also applies to general graphs with non-negative weights.

The essential restriction is non-negative edge weights; the graph can be directed or undirected. When negative weights are present, use an algorithm designed to handle them, such as Bellman–Ford, subject to that algorithm’s own limitations.

7. Shortest paths in an unweighted graph

This tests which traversal finds a minimum-edge path when every edge has equal cost. Question 7:

Question 71 mark

In an unweighted graph, which algorithm finds the shortest path in number of edges from a source vertex to every reachable vertex?

Breadth-first search visits vertices in layers of increasing distance from the source, so the first discovery of a vertex gives a path with the fewest edges. Depth-first search is the strongest distractor, but it may follow a long path before finding a shorter one.

BFS uses a queue to process each layer in turn. For a weighted graph with unequal edge costs, counting edges is not enough; choose a shortest-path method that accounts for the weights.

8. Binary search tree traversal

This checks the ordering property of a binary search tree. Question 8:

Question 81 mark

For a valid binary search tree, which traversal visits the keys in ascending order?

Inorder traversal visits the left subtree, then the node, then the right subtree. The binary search tree ordering places smaller keys to the left and larger keys to the right, producing ascending order. Level order is the strongest distractor, but it visits by depth rather than key value.

This result depends on the tree satisfying the binary search tree ordering rule. A generic binary tree does not guarantee sorted output from inorder traversal.

9. Building a heap

This tests a common distinction between inserting items one by one and building a heap from an array. Question 9:

Question 91 mark

What is the time complexity of building a binary heap from an array using the bottom-up build-heap procedure?

Bottom-up build-heap runs sift-down from internal nodes. Although an individual sift-down can take O(log n), most nodes are close to the leaves and require less work, so the total is O(n). O(n log n) is the strongest distractor and is the bound for inserting n items one at a time.

When comparing heap construction methods, keep the method in the question in view. Repeated insertion costs O(n log n) in the usual analysis, while bottom-up construction takes O(n).

10. Longest common subsequence

This checks whether you can apply the dynamic-programming recurrence when the final characters match. Question 10:

Question 101 mark

What is the length of a longest common subsequence of ABCBDAB and BDCAB?

The length is 4; for example, BCAB appears in order in both strings. A common subsequence need not use consecutive characters. The strongest distractor is 5, which can come from treating the task like finding a common substring or overlooking the order constraint; no length-5 subsequence is shared.

A subsequence preserves the original order but may skip characters. A substring must be contiguous. That distinction is often the key to choosing the right dynamic-programming formulation.

Turn mistakes into a revision list

After checking your answers, group misses by topic rather than rereading the whole set. If you chose the right option for the wrong reason, treat that as a weak point too: a changed assumption could make the same guess fail. A useful next step is to write a one-sentence rule for each miss, then test whether you can apply it to a new example.

A practice dashboard might rank topics by your recent results and how often they have appeared in your practice set:

Where marks go missing
50%Graph algorithms8×
67%Complexity analysis9×
83%Linear data structures6×

Use the lowest-scoring area to choose your next question or revision session. The “times” value here refers to appearances in the practice set, not a prediction about any particular course or assessment.

If the same concept costs you marks twice, turn the correction into a short prompt that tests the exact distinction you missed:

Remediation tray

You lost this mark twice: why is bottom-up build-heap O(n), while inserting n items one at a time is O(n log n)?

Add cardDismiss

Answer it in your own words, including the reason rather than only the complexity. That makes the prompt useful for retrieval practice, not just recognition.

How MySummaries helps

Build a revision board from your own notes, slides or course material, then use its questions, flashcards and marked practice to identify specific gaps. For this task, start with the concepts you missed here and add the relevant explanations from your material to the board. Open MySummaries.