🎓LearnByTeaching.aiTry Free
Practice Questions

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.

Q1Easysorting-algorithms

What is the worst-case time complexity of quicksort?

Q2Mediumsorting-algorithms

Which sorting algorithm is stable, in-place, and has O(n^2) worst-case time?

Q3Easysearching-algorithms

Binary search requires that the input array is:

Q4Mediumsorting-algorithms

What is the best-case time complexity of merge sort?

Q5Mediumsorting-algorithms

Counting sort has time complexity O(n + k) where k is:

Q6Mediumsearching-algorithms

In a sorted array of n elements, how many comparisons does binary search make in the worst case?

Q7Hardsorting-algorithms

Which sorting algorithm would you use to sort 10 million 32-bit integers with limited extra memory?

Q8Hardsorting-algorithms

What is the lower bound for comparison-based sorting?

Q9Hardsearching-algorithms

What happens when you apply binary search to find the leftmost occurrence of a duplicate element?

Q10Easysorting-algorithms

Which sorting algorithm performs best on nearly-sorted data?

Dynamic Programming

Covers identifying DP problems, state transitions, memoization vs. tabulation, and classic DP problems.

Q11Easydynamic-programming

What two properties must a problem have to be solvable by dynamic programming?

Q12Mediumdynamic-programming

What is the time complexity of the standard dynamic programming solution for the 0/1 knapsack problem with n items and capacity W?

Q13Easydynamic-programming

In the Fibonacci sequence computed recursively without memoization, what is the time complexity?

Q14Mediumdynamic-programming

What is the key difference between memoization (top-down) and tabulation (bottom-up)?

Q15Mediumdynamic-programming

The longest common subsequence (LCS) of 'ABCBDAB' and 'BDCAB' has length:

Q16Mediumdynamic-programming

For the coin change problem (minimum coins to make amount n with denominations d1, d2, ..., dk), what is the recurrence?

Q17Harddynamic-programming

In the edit distance problem between two strings of length m and n, the DP table size is:

Q18Hardgreedy-algorithms

Which of the following problems can be solved with a greedy approach rather than DP?

Q19Harddynamic-programming

What is the time complexity of the matrix chain multiplication DP solution for n matrices?

Q20Harddynamic-programming

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.

Q21Easygraph-algorithms

BFS (Breadth-First Search) uses which data structure?

Q22Mediumgraph-algorithms

Dijkstra's algorithm does NOT work correctly when:

Q23Easygraph-algorithms

The time complexity of BFS on a graph with V vertices and E edges is:

Q24Mediumgraph-algorithms

Which algorithm finds the shortest path between ALL pairs of vertices?

Q25Mediumgraph-algorithms

Topological sorting is possible only on:

Q26Mediumgraph-algorithms

Which algorithm uses a priority queue and can find the minimum spanning tree?

Q27Hardgraph-algorithms

What is the time complexity of Dijkstra's algorithm with a binary heap?

Q28Easygraph-algorithms

In DFS, a back edge indicates the presence of:

Q29Hardgraph-algorithms

Kruskal's algorithm for MST uses which data structure to efficiently detect cycles?

Q30Hardgraph-algorithms

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.

Q31Easycomplexity-analysis

What is the time complexity of the following code: for i in range(n): for j in range(n): print(i, j)?

Q32Mediumcomplexity-analysis

Apply the Master Theorem to T(n) = 2T(n/2) + n. The solution is:

Q33Mediumnp-completeness

Which complexity class contains problems that can be verified in polynomial time?

Q34Easycomplexity-analysis

What is the time complexity of T(n) = T(n/2) + O(1)?

Q35Hardnp-completeness

Reducing problem A to problem B in polynomial time means:

Q36Mediumcomplexity-analysis

The amortized time complexity of appending to a dynamic array (with doubling strategy) is:

Q37Mediumnp-completeness

Which of the following problems is NOT NP-complete?

Q38Hardcomplexity-analysis

What is the solution to T(n) = 4T(n/2) + n using the Master Theorem?

Q39Hardcomplexity-analysis

What is the space complexity of an iterative BFS on a graph with V vertices?

Q40Hardnp-completeness

If a problem is NP-hard but NOT in NP, then:

Scoring Guide

Total possible: 40

Excellent36-40: Excellent — you have strong mastery of algorithm design and analysis
Good28-35: Good — solid foundation with some gaps to address
Needs WorkBelow 28: Needs work — review the topics you missed

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.)
0 of 40 answered0%

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