Complexity Analysis and Recursion Interview Questions for Data Structures and Algorithms
25 Complexity Analysis and Recursion questions with answers for data structures and algorithms roles — 9 easy, 12 medium, 4 hard.
About Complexity Analysis and Recursion
Learn to measure algorithms with Big-O, Big-Omega and Big-Theta, analyse time and space, and estimate whether a solution fits the constraints. Then master recursion, the call stack, base cases, the Master Theorem and amortised analysis, which form the foundation for divide and conquer, backtracking and dynamic programming.
What is the difference between Big-O, Big-Omega and Big-Theta?
Show answer
What is space complexity and how is auxiliary space different?
Show answer
List common complexity classes from fastest to slowest with examples.
Show answer
What is recursion and why is a base case essential?
Show answer
Write recursive Fibonacci and then optimise it with memoisation.
Show answer
Solve the Tower of Hanoi problem recursively.
Show answer
Find the GCD of two numbers using the Euclidean algorithm.
Show answer
How do you approach a coding problem you have never seen before in an interview?
Show answer
What is amortised analysis? Explain it with dynamic array append.
Show answer
What are the trade-offs between recursion and iteration?
Show answer
What is tail recursion and do Java and Python optimise it?
Show answer
Why is naive recursive Fibonacci exponential, and how do you fix it?
Show answer
Explain best, average and worst case complexity using quicksort.
Show answer
A problem has n up to 100000. Which time complexities are acceptable for a 1-second limit?
Show answer
A recursive DFS in Python crashes with RecursionError on a deep input. How do you fix it?
Show answer
An interviewer asks you to reduce your solution's extra space from O(n) to O(1). How do you approach it?
Show answer
Implement fast exponentiation to compute x to the power n in O(log n).
Show answer
Generate all subsets of a list of distinct numbers.
Show answer
What is the time complexity of an outer loop from 0 to n with an inner loop where j starts at 1 and doubles until it reaches n?
Show answer
How did you prepare for data structures and algorithms rounds?
Show answer
What is the Master Theorem and how do you apply it?
Show answer
Your solution passes the sample tests but gets Time Limit Exceeded on large inputs. How do you analyse and fix it?
Show answer
You can use an O(n log n) algorithm with high constant factors or a simple O(n squared) one. For what inputs might the O(n squared) choice be better?
Show answer
A report generation function loops over all users and, for each user, scans all orders. It was fine at launch but is now very slow. How do you explain and fix it?
Show answer
Frequently asked questions
How important is Complexity Analysis and Recursion in Data Structures and Algorithms interviews?
Learn to measure algorithms with Big-O, Big-Omega and Big-Theta, analyse time and space, and estimate whether a solution fits the constraints. Then master recursion, the call stack, base cases, the Master Theorem and amortised analysis, which form the foundation for divide and conquer, backtracking and dynamic programming.
How should I use the Complexity Analysis and Recursion sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.