DSA Interview Questions
10 questions with detailed answers
Q1. What is time complexity of binary search?
Answer: O(log n) — halves the search space each iteration.
Q2. Difference between stack and queue?
Answer: Stack is LIFO (Last In First Out); Queue is FIFO (First In First Out).
Q3. What is a hash table?
Answer: Data structure mapping keys to values using a hash function for O(1) average lookup.
Q4. Explain BFS vs DFS.
Answer: BFS explores level by level using a queue; DFS explores depth-first using a stack/recursion.
Q5. What is dynamic programming?
Answer: Solving complex problems by breaking into overlapping subproblems and storing results to avoid recomputation.
Q6. When would you use a heap?
Answer: A heap is useful when repeatedly retrieving the minimum or maximum element, such as in priority queues, top-k problems, scheduling, and Dijkstra's algorithm. Insert and removal are O(log n).
Q7. What is the difference between a tree and a graph?
Answer: A tree is a connected acyclic graph with one path between any two nodes. A general graph may contain cycles, disconnected components, and multiple paths.
Q8. What is a stable sorting algorithm?
Answer: A stable sort preserves the original relative order of elements with equal keys. This matters when sorting records by multiple fields in successive passes.
Q9. How does memoization differ from tabulation?
Answer: Memoization is top-down recursion that caches only visited subproblems. Tabulation is bottom-up iteration that fills a table in dependency order, often with less call overhead.
Q10. What is the two-pointer technique?
Answer: Two pointers traverse a sequence from related positions to avoid nested loops. It is common in sorted-array pair searches, partitioning, linked-list cycle detection, and sliding-window problems.