Algorithms Practice Questions: Test Your Knowledge | LearnByTeaching.ai
These 40 practice questions cover sorting and searching, dynamic programming, graph algorithms, and complexity analysis. They are designed for CS students preparing for exams and developers sharpening their interview skills.
40 questions total
Sorting and Searching Algorithms
Covers comparison-based sorts, non-comparison sorts, binary search variants, and their time/space complexities.
What is the worst-case time complexity of quicksort?
Which sorting algorithm is stable, in-place, and has O(n^2) worst-case time?
Binary search requires that the input array is:
What is the best-case time complexity of merge sort?
Counting sort has time complexity O(n + k) where k is:
In a sorted array of n elements, how many comparisons does binary search make in the worst case?
Which sorting algorithm would you use to sort 10 million 32-bit integers with limited extra memory?
What is the lower bound for comparison-based sorting?
What happens when you apply binary search to find the leftmost occurrence of a duplicate element?
Which sorting algorithm performs best on nearly-sorted data?
Dynamic Programming
Covers identifying DP problems, state transitions, memoization vs. tabulation, and classic DP problems.
What two properties must a problem have to be solvable by dynamic programming?
What is the time complexity of the standard dynamic programming solution for the 0/1 knapsack problem with n items and capacity W?
In the Fibonacci sequence computed recursively without memoization, what is the time complexity?
What is the key difference between memoization (top-down) and tabulation (bottom-up)?
The longest common subsequence (LCS) of 'ABCBDAB' and 'BDCAB' has length:
For the coin change problem (minimum coins to make amount n with denominations d1, d2, ..., dk), what is the recurrence?
In the edit distance problem between two strings of length m and n, the DP table size is:
Which of the following problems can be solved with a greedy approach rather than DP?
What is the time complexity of the matrix chain multiplication DP solution for n matrices?
When can the space complexity of a 2D DP table be reduced to O(n)?
Graph Algorithms
Covers BFS, DFS, shortest path algorithms, minimum spanning trees, and topological sorting.
BFS (Breadth-First Search) uses which data structure?
Dijkstra's algorithm does NOT work correctly when:
The time complexity of BFS on a graph with V vertices and E edges is:
Which algorithm finds the shortest path between ALL pairs of vertices?
Topological sorting is possible only on:
Which algorithm uses a priority queue and can find the minimum spanning tree?
What is the time complexity of Dijkstra's algorithm with a binary heap?
In DFS, a back edge indicates the presence of:
Kruskal's algorithm for MST uses which data structure to efficiently detect cycles?
Which problem is solved by the Bellman-Ford algorithm that Dijkstra's cannot handle?
Complexity Analysis and Advanced Topics
Covers Big-O notation, recurrence relations, the Master Theorem, NP-completeness, and amortized analysis.
What is the time complexity of the following code: for i in range(n): for j in range(n): print(i, j)?
Apply the Master Theorem to T(n) = 2T(n/2) + n. The solution is:
Which complexity class contains problems that can be verified in polynomial time?
What is the time complexity of T(n) = T(n/2) + O(1)?
Reducing problem A to problem B in polynomial time means:
The amortized time complexity of appending to a dynamic array (with doubling strategy) is:
Which of the following problems is NOT NP-complete?
What is the solution to T(n) = 4T(n/2) + n using the Master Theorem?
What is the space complexity of an iterative BFS on a graph with V vertices?
If a problem is NP-hard but NOT in NP, then:
Scoring Guide
Total possible: 40
Study Recommendations
- Solve DP problems by first writing the recurrence relation before coding — the state transition is the hardest part
- Practice classifying graph problems: know when to use BFS vs. DFS vs. Dijkstra vs. Bellman-Ford
- Master the Master Theorem by working through many examples until pattern recognition is automatic
- Implement sorting algorithms from scratch to understand their invariants and edge cases
- Study NP-completeness reductions by working through the classic reduction chain (SAT -> 3-SAT -> Clique -> Vertex Cover -> etc.)
More Algorithms Resources
Want more algorithms practice?
Upload your notes and LearnByTeaching.ai generates unlimited practice questions tailored to your course. Then teach the concepts to AI students who challenge your understanding.
Try LearnByTeaching.ai — It's Free