1.Easy
What is an algorithm?
- AAny computer program that has a graphical interface
- BA finite sequence of well-defined steps that solves a problem
- CA data structure that stores numbers
- DA programming language designed for writing mathematical formulas
2.Easy
What does the worst-case running time of an algorithm describe?
- AThe expected time it takes on a random input of size n
- BThe maximum time it takes over all inputs of size n
- CThe time it takes on a slow computer
- DThe time it takes on the smallest input
3.Easy
What is the base case of a recursive function?
- AThe call that uses the most memory
- BThe case with the largest input, which is handled before any recursive calls
- CA case that is answered directly without making another recursive call
- DThe first line of the function
4.Medium
Breadth-first search on an unweighted graph finds:
- AShortest paths in number of edges from the start node
- BThe minimum spanning tree
- CA topological order in all graphs
- DShortest paths in graphs that contain negative edge weights
5.Medium
How does Prim's algorithm build a minimum spanning tree?
- AIt runs breadth-first search and keeps the BFS tree
- BIt sorts all edges by weight and adds each one unless it would form a cycle in the forest
- CIt removes the most expensive edge until no cycles remain
- DIt grows one tree from a start vertex, adding the cheapest edge that leaves the tree
6.Medium
What is the time complexity of: for i = 1 to n: (j = 1; while j < n: j = j × 2)?
- AO(log n)
- BO(n)
- CO(n log n)
- DO(n²)
7.Hard
The 0/1 knapsack problem solved with dynamic programming takes O(nW) time. Why is this called pseudo-polynomial?
- ABecause n is always small
- BBecause it only works for W = 0
- CBecause the algorithm is randomised and its running time varies with each input
- DW is a number, so the time is exponential in the number of bits used to write W
8.Hard
Using the master theorem, T(n) = 8T(n/2) + O(n²) solves to:
- AΘ(n² log n)
- BΘ(n²)
- CΘ(n³)
- DΘ(n log n)
Answer key
- 1. B · A finite sequence of well-defined steps that solves a problem
- 2. B · The maximum time it takes over all inputs of size n
- 3. C · A case that is answered directly without making another recursive call
- 4. A · Shortest paths in number of edges from the start node
- 5. D · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- 6. C · O(n log n)
- 7. D · W is a number, so the time is exponential in the number of bits used to write W
- 8. C · Θ(n³)
Full step-by-step solutions: practise this topic on examproblems.com.