1.Easy
What is the best-case time complexity of insertion sort, on an already sorted array?
- AO(n log n)
- BO(n)
- CO(n²)
- DO(1)
2.Easy
What does the average-case running time describe?
- AThe expected time over a given distribution of inputs of size n
- BThe time for an input of average length
- CThe time on the most common computer
- DThe middle value between the best-case and worst-case running times
3.Easy
What is the time complexity of binary search on a sorted array?
- AO(log n)
- BO(1)
- CO(n)
- DO(n log n)
4.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
5.Medium
Why do many library sorting routines switch to insertion sort for very small subarrays?
- ARecursive algorithms cannot handle arrays below 10 elements
- BInsertion sort is O(n log n) in the worst case
- CInsertion sort uses less memory than any other sorting algorithm on large inputs
- DInsertion sort has little overhead and is fast on small or nearly sorted inputs
6.Medium
Why does dynamic programming give no real speed-up for merge sort?
- ADynamic programming only works on graph problems, not on arrays
- BMerge sort is already O(n)
- CMerge sort has no recursive structure
- DIts subproblems do not overlap, so there is nothing to reuse
7.Hard
A problem is NP-complete if it is:
- ASolvable in polynomial time
- BIn NP and every NP problem reduces to it in polynomial time
- CImpossible to solve
- DOutside NP but harder than all NP problems, such as the halting problem
8.Hard
What is the time complexity of building a binary heap from n unsorted elements with the bottom-up method?
- AO(n²)
- BO(n)
- CO(n log n)
- DO(log n)
Answer key
- 1. B · O(n)
- 2. A · The expected time over a given distribution of inputs of size n
- 3. A · O(log n)
- 4. D · It grows one tree from a start vertex, adding the cheapest edge that leaves the tree
- 5. D · Insertion sort has little overhead and is fast on small or nearly sorted inputs
- 6. D · Its subproblems do not overlap, so there is nothing to reuse
- 7. B · In NP and every NP problem reduces to it in polynomial time
- 8. B · O(n)
Full step-by-step solutions: practise this topic on examproblems.com.