1.Easy
What is the time complexity of finding the largest value in an unsorted array of n numbers?
- AO(n)
- BO(log n)
- CO(1)
- DO(n log n)
2.Easy
What does the average-case running time describe?
- AThe middle value between the best-case and worst-case running times
- BThe time on the most common computer
- CThe time for an input of average length
- DThe expected time over a given distribution of inputs of size n
3.Easy
An algorithm's running time is O(n). What is this growth called?
- AConstant
- BQuadratic
- CLogarithmic
- DLinear
4.Medium
A greedy algorithm:
- ATries every possible solution
- BAlways gives the optimal solution
- CMakes the locally best choice at each step
- DUses only recursion
5.Medium
Why do many library sorting routines switch to insertion sort for very small subarrays?
- AInsertion sort uses less memory than any other sorting algorithm on large inputs
- BInsertion sort has little overhead and is fast on small or nearly sorted inputs
- CRecursive algorithms cannot handle arrays below 10 elements
- DInsertion sort is O(n log n) in the worst case
6.Medium
The time complexity of naive recursive Fibonacci (fib(n) = fib(n−1) + fib(n−2)) is:
- AConstant
- BLogarithmic
- CLinear
- DExponential
7.Hard
Why can Dijkstra's algorithm give wrong results when some edge weights are negative?
- AIt only works on undirected graphs
- BIt goes into an infinite loop on every negative edge
- CNegative numbers cannot be stored in a priority queue
- DA vertex is finalised when extracted, but a later negative edge could still give it a shorter path
8.Hard
What is the time complexity of: for i = 1 to n: for (j = i; j ≤ n; j = j + i) do O(1) work?
- AO(n √n)
- BO(n)
- CO(n²)
- DO(n log n)
Answer key
- 1. A · O(n)
- 2. D · The expected time over a given distribution of inputs of size n
- 3. D · Linear
- 4. C · Makes the locally best choice at each step
- 5. B · Insertion sort has little overhead and is fast on small or nearly sorted inputs
- 6. D · Exponential
- 7. D · A vertex is finalised when extracted, but a later negative edge could still give it a shorter path
- 8. D · O(n log n)
Full step-by-step solutions: practise this topic on examproblems.com.