1.Easy
An O(n²) algorithm takes 1 second for n = 1000. About how long does it take for n = 2000?
- A8 seconds
- B2 seconds
- C4 seconds
- D1 second
2.Easy
What is the Big O of 3n² + 5n + 2?
- AO(3n²)
- BO(5n)
- CO(n³)
- DO(n²)
3.Easy
An algorithm's running time is O(n). What is this growth called?
- ALinear
- BQuadratic
- CLogarithmic
- DConstant
4.Medium
Why is the base of a logarithm usually left out in Big O, as in O(log n)?
- ALogarithms with different bases differ only by a constant factor
- BAll logarithms in computer science have base 10, so it is implied
- CThe base only matters for small n
- DLogarithms are always rounded to integers
5.Medium
Which statement about a recursive function without a reachable base case is correct?
- AThe compiler always turns it into a loop that ends safely
- BIt keeps calling itself until the call stack overflows
- CIt runs in O(1) time
- DIt returns 0 automatically
6.Medium
Quicksort always uses the first element as pivot. On which input does it show its worst-case behaviour?
- AAn array in random order
- BAn array of length 2
- CAn array that is already sorted
- DAn array whose elements are all different
7.Hard
Which technique gives an expected O(n log n) running time for quicksort on any input?
- ASorting the input before running quicksort
- BAlways choosing the first element
- CChoosing the pivot uniformly at random
- DUsing recursion only on the left side
8.Hard
Topological sorting is possible only for:
- ADirected acyclic graphs
- BGraphs with negative weights
- CComplete graphs
- DUndirected graphs
Answer key
- 1. C · 4 seconds
- 2. D · O(n²)
- 3. A · Linear
- 4. A · Logarithms with different bases differ only by a constant factor
- 5. B · It keeps calling itself until the call stack overflows
- 6. C · An array that is already sorted
- 7. C · Choosing the pivot uniformly at random
- 8. A · Directed acyclic graphs
Full step-by-step solutions: practise this topic on examproblems.com.