1.Easy
How does selection sort work?
- AIt inserts each element into a growing sorted part by shifting
- BIt splits the array in halves and merges them
- CIt repeatedly swaps neighbouring elements that are in the wrong order
- DIt repeatedly finds the minimum of the unsorted part and swaps it to the front
2.Easy
What is the time complexity of depth-first search on a graph stored as adjacency lists?
- AO(V + E)
- BO(V × E)
- CO(E log V)
- DO(V²)
3.Easy
A loop starts with i = 1 and doubles i each iteration until i > n. How many iterations does it run?
- AAbout log₂ n
- BAbout n
- CAbout n / 2
- DAbout n²
4.Medium
In a sorted array, you look for two elements that sum to a target by moving one pointer from each end inwards. What is the time complexity?
- AO(log n)
- BO(n log n)
- CO(n²)
- DO(n)
5.Medium
Dynamic programming is useful when a problem has:
- AA single loop
- BOverlapping subproblems and optimal substructure
- COnly random inputs
- DNo subproblems at all, so it can be solved in one step
6.Medium
What is the time complexity of the standard dynamic programming algorithm for the longest common subsequence of strings of lengths m and n?
- AO(mn log n)
- BO(mn)
- CO(m + n)
- DO(2m+n)
7.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)
8.Hard
Why is the average lookup in a hash table O(1) but the worst case O(n)?
- AHash functions are slow
- BArrays have O(n) access
- CKeys must be sorted first
- DMany keys may collide into the same bucket
Answer key
- 1. D · It repeatedly finds the minimum of the unsorted part and swaps it to the front
- 2. A · O(V + E)
- 3. A · About log₂ n
- 4. D · O(n)
- 5. B · Overlapping subproblems and optimal substructure
- 6. B · O(mn)
- 7. B · It is NP-hard
- 8. D · Many keys may collide into the same bucket
Full step-by-step solutions: practise this topic on examproblems.com.