1.Easy
Space complexity measures:
- AThe physical size of the computer
- BThe amount of memory an algorithm needs as input grows
- CThe number of lines of code
- DThe disk space of the program file once it is compiled
2.Easy
An algorithm's running time is O(n). What is this growth called?
- ALinear
- BQuadratic
- CConstant
- DLogarithmic
3.Easy
What is memoisation?
- AConverting recursion into an equivalent loop automatically so no call stack is needed
- BStoring the results of function calls so repeated calls are answered from memory
- CFreeing memory after a function returns
- DWriting comments next to each line of code
4.Medium
A function runs one loop of n iterations and then, separately, another loop of n iterations. What is its time complexity?
- AO(log n)
- BO(2ⁿ)
- CO(n²)
- DO(n)
5.Medium
About how many comparisons does binary search need in the worst case on a sorted array of 1,000,000 elements?
- AAbout 1,000
- BAbout 100
- CAbout 20
- DAbout 500,000
6.Medium
Why does dynamic programming give no real speed-up for merge sort?
- AMerge sort has no recursive structure
- BMerge sort is already O(n)
- CDynamic programming only works on graph problems, not on arrays
- DIts subproblems do not overlap, so there is nothing to reuse
7.Hard
How is the travelling salesman problem classified?
- AThe decision version is NP-complete and the optimisation version is NP-hard
- BIt is undecidable
- CIt is in P because Dijkstra's algorithm solves it by visiting every city once
- DThe decision version is in P but the optimisation version is NP-complete
8.Hard
Shortest simple paths can be found in polynomial time. What is known about finding the longest simple path between two vertices in a general graph?
- AIt is undecidable
- BIt is NP-hard
- CIt can be solved by Dijkstra's algorithm with negated weights
- DIt is always solvable in O(V + E)
Answer key
- 1. B · The amount of memory an algorithm needs as input grows
- 2. A · Linear
- 3. B · Storing the results of function calls so repeated calls are answered from memory
- 4. D · O(n)
- 5. C · About 20
- 6. D · Its subproblems do not overlap, so there is nothing to reuse
- 7. A · The decision version is NP-complete and the optimisation version is NP-hard
- 8. B · It is NP-hard
Full step-by-step solutions: practise this topic on examproblems.com.