Data Structures and Algorithms Interview Questions (DSA MCQs)

Core data structures and algorithms questions asked by product and service companies, with a one-line explanation for each answer.

  1. Q1. Which data structure follows Last In, First Out (LIFO)?

    • A. Heap
    • B. Queue
    • C. Stack
    • D. Linked list
    Show answer

    Answer: C. Stack
    The last item pushed onto a stack is the first one popped.

  2. Q2. Which data structure follows First In, First Out (FIFO)?

    • A. Tree
    • B. Graph
    • C. Stack
    • D. Queue
    Show answer

    Answer: D. Queue
    A queue serves items in the order they arrive.

  3. Q3. What is the time complexity of binary search on a sorted array?

    • A. O(log n)
    • B. O(n log n)
    • C. O(1)
    • D. O(n)
    Show answer

    Answer: A. O(log n)
    Each step halves the search range.

  4. Q4. What is the worst-case time complexity of quicksort?

    • A. O(log n)
    • B. O(n)
    • C. O(n²)
    • D. O(n log n)
    Show answer

    Answer: C. O(n²)
    With bad pivots (e.g. already sorted input and first-element pivot) it degrades to O(n²). Average is O(n log n).

  5. Q5. Which sorting algorithm is guaranteed O(n log n) in the worst case?

    • A. Insertion sort
    • B. Quick sort
    • C. Merge sort
    • D. Bubble sort
    Show answer

    Answer: C. Merge sort
    Merge sort always splits in half and merges in linear time.

  6. Q6. Which traversal of a binary search tree gives the values in sorted order?

    • A. In-order
    • B. Post-order
    • C. Pre-order
    • D. Level-order
    Show answer

    Answer: A. In-order
    In-order visits left subtree, node, right subtree.

  7. Q7. What is the average time to look up a key in a hash table?

    • A. O(1)
    • B. O(n²)
    • C. O(log n)
    • D. O(n)
    Show answer

    Answer: A. O(1)
    Hashing jumps straight to the bucket; collisions make the worst case O(n).

  8. Q8. Which algorithm finds the shortest path in a graph with non-negative edge weights?

    • A. Dijkstra's algorithm
    • B. Kruskal's algorithm
    • C. Bubble sort
    • D. Depth-first search
    Show answer

    Answer: A. Dijkstra's algorithm
    Dijkstra greedily expands the closest unvisited vertex. Kruskal finds a minimum spanning tree, not shortest paths.

  9. Q9. Breadth-first search (BFS) typically uses which data structure?

    • A. Stack
    • B. Heap
    • C. Hash set only
    • D. Queue
    Show answer

    Answer: D. Queue
    BFS explores level by level, processing vertices in the order they were discovered.

  10. Q10. Depth-first search (DFS) can be implemented with recursion or which data structure?

    • A. Array of size 1
    • B. Queue
    • C. Stack
    • D. Priority queue
    Show answer

    Answer: C. Stack
    Recursion uses the call stack; an explicit stack works the same way.

  11. Q11. What is the maximum number of nodes in a binary tree of height h (root at height 0)?

    • A. 2^h
    • B. 2^(h+1) − 1
    • C. h²
    • D. 2h + 1
    Show answer

    Answer: B. 2^(h+1) − 1
    Each level doubles: 1 + 2 + 4 + … + 2^h = 2^(h+1) − 1.

  12. Q12. Inserting at the beginning of a singly linked list takes:

    • A. O(n)
    • B. O(log n)
    • C. O(1)
    • D. O(n²)
    Show answer

    Answer: C. O(1)
    Just point the new node at the old head.

  13. Q13. Accessing the i-th element of an array takes:

    • A. O(i²)
    • B. O(log n)
    • C. O(n)
    • D. O(1)
    Show answer

    Answer: D. O(1)
    Arrays use contiguous memory, so the address is computed directly.

  14. Q14. Which data structure is best for implementing a priority queue?

    • A. Linked list
    • B. Stack
    • C. Heap
    • D. Array sorted after every insert
    Show answer

    Answer: C. Heap
    A binary heap gives O(log n) insert and extract-min/max.

  15. Q15. What does dynamic programming rely on?

    • A. Random choices
    • B. Greedy choices only
    • C. Sorting the input first
    • D. Overlapping subproblems and optimal substructure
    Show answer

    Answer: D. Overlapping subproblems and optimal substructure
    DP stores answers to repeated subproblems instead of recomputing them.

  16. Q16. Which technique is used in the 'two-sum on a sorted array' O(n) solution?

    • A. Bit manipulation
    • B. Backtracking
    • C. Divide and conquer
    • D. Two pointers
    Show answer

    Answer: D. Two pointers
    Move the left pointer up when the sum is too small and the right pointer down when too big.

  17. Q17. What is the space complexity of merge sort on an array?

    • A. O(n)
    • B. O(log n)
    • C. O(1)
    • D. O(n²)
    Show answer

    Answer: A. O(n)
    Merging needs a temporary array of size n.

  18. Q18. A graph with V vertices stored as an adjacency matrix needs how much space?

    • A. O(V²)
    • B. O(V + E)
    • C. O(V)
    • D. O(E)
    Show answer

    Answer: A. O(V²)
    A V × V matrix. Adjacency lists need O(V + E).

  19. Q19. Which problem is typically solved with backtracking?

    • A. Computing an average
    • B. Binary search
    • C. N-Queens
    • D. Finding the maximum of an array
    Show answer

    Answer: C. N-Queens
    Backtracking tries choices and undoes them when they lead to a dead end.

  20. Q20. Detecting a cycle in a linked list in O(1) extra space uses:

    • A. A hash set
    • B. Sorting
    • C. Floyd's slow and fast pointers
    • D. Recursion
    Show answer

    Answer: C. Floyd's slow and fast pointers
    If there's a cycle, the fast pointer eventually meets the slow one. A hash set works but uses O(n) space.

  21. Q21. What is the time complexity of building a heap from n elements (heapify)?

    • A. O(n log n)
    • B. O(log n)
    • C. O(n²)
    • D. O(n)
    Show answer

    Answer: D. O(n)
    Bottom-up heapify is O(n) because most nodes are near the leaves.

  22. Q22. Which of these is a stable sorting algorithm?

    • A. Quick sort (typical)
    • B. Merge sort
    • C. Selection sort
    • D. Heap sort
    Show answer

    Answer: B. Merge sort
    Stable sorts keep equal elements in their original order.

  23. Q23. A balanced binary search tree (like AVL) guarantees search in:

    • A. O(n)
    • B. O(log n)
    • C. O(n log n)
    • D. O(1)
    Show answer

    Answer: B. O(log n)
    Balancing keeps the height about log n.

  24. Q24. Which data structure is used to check balanced parentheses?

    • A. Graph
    • B. Stack
    • C. Queue
    • D. Heap
    Show answer

    Answer: B. Stack
    Push openers, pop and compare on closers.

  25. Q25. Kadane's algorithm solves which problem?

    • A. Shortest path
    • B. Sorting
    • C. Maximum subarray sum
    • D. Minimum spanning tree
    Show answer

    Answer: C. Maximum subarray sum
    It tracks the best sum ending at each position in O(n).

  26. Q26. What is a 'trie' mainly used for?

    • A. Shortest paths
    • B. Prefix searches on strings
    • C. Sorting numbers
    • D. Matrix multiplication
    Show answer

    Answer: B. Prefix searches on strings
    Tries store strings character by character, making prefix lookups fast (autocomplete).

  27. Q27. Topological sort applies to which kind of graph?

    • A. Graphs with cycles
    • B. Complete graphs only
    • C. Any undirected graph
    • D. Directed acyclic graph (DAG)
    Show answer

    Answer: D. Directed acyclic graph (DAG)
    It orders tasks so every dependency comes before the task that needs it.

  28. Q28. Which algorithm builds a minimum spanning tree?

    • A. Dijkstra's algorithm
    • B. Kruskal's algorithm
    • C. KMP
    • D. Binary search
    Show answer

    Answer: B. Kruskal's algorithm
    Kruskal (and Prim) find the cheapest set of edges connecting all vertices.

  29. Q29. The 'sliding window' technique is most useful for:

    • A. Graph colouring
    • B. Tree traversal
    • C. Problems on contiguous subarrays or substrings
    • D. Sorting linked lists
    Show answer

    Answer: C. Problems on contiguous subarrays or substrings
    Expand and shrink a window instead of re-checking every subarray.

  30. Q30. What is the time complexity of inserting into a Python list at index 0?

    • A. O(log n)
    • B. O(n)
    • C. O(1)
    • D. O(n²)
    Show answer

    Answer: B. O(n)
    Every existing element shifts right. Use collections.deque for O(1) appends on both ends.

  31. Q31. Memoization means:

    • A. Sorting results
    • B. Writing code comments
    • C. Caching function results for inputs already computed
    • D. Using less memory
    Show answer

    Answer: C. Caching function results for inputs already computed
    It turns exponential recursion like naive Fibonacci into linear time.

  32. Q32. In a min-heap, the smallest element is always:

    • A. Anywhere
    • B. At the last leaf
    • C. At the root
    • D. In the middle
    Show answer

    Answer: C. At the root
    Every parent is ≤ its children, so the minimum sits at the top.

  33. Q33. How many edges does a tree with n nodes have?

    • A. 2n
    • B. n − 1
    • C. n + 1
    • D. n
    Show answer

    Answer: B. n − 1
    A tree is connected with no cycles, which needs exactly n − 1 edges.

  34. Q34. Which search works on unsorted data?

    • A. Linear search
    • B. Exponential search
    • C. Binary search
    • D. Interpolation search
    Show answer

    Answer: A. Linear search
    Without order, you have to check elements one by one.

  35. Q35. A recursive function without a base case will cause:

    • A. Faster execution
    • B. A syntax error
    • C. Stack overflow (RecursionError in Python)
    • D. It to return None
    Show answer

    Answer: C. Stack overflow (RecursionError in Python)
    Each call adds a stack frame until memory runs out.

  36. Q36. Which data structure follows Last In, First Out (LIFO)?

    • A. Heap
    • B. Queue
    • C. Stack
    • D. Linked list
    Show answer

    Answer: C. Stack
    The last item pushed is the first one popped.

  37. Q37. Which data structure follows First In, First Out (FIFO)?

    • A. Queue
    • B. Binary search tree
    • C. Hash table
    • D. Stack
    Show answer

    Answer: A. Queue
    Items leave in the order they arrived, like a ticket counter line.

  38. Q38. Which data structure is best for checking balanced brackets?

    • A. Stack
    • B. Graph
    • C. Queue
    • D. Array
    Show answer

    Answer: A. Stack
    Push opening brackets and pop on closing ones.

  39. Q39. What is a circular queue used for?

    • A. Reusing empty slots at the front of a fixed array
    • B. Storing a tree
    • C. Sorting elements
    • D. Searching faster
    Show answer

    Answer: A. Reusing empty slots at the front of a fixed array
    The rear wraps around to index 0 when space is free.

  40. Q40. In a singly linked list, what does each node store?

    • A. Data and a pointer to the next node
    • B. An index into an array
    • C. Data only
    • D. Pointers to the next and previous nodes
    Show answer

    Answer: A. Data and a pointer to the next node
    A doubly linked list also stores a pointer to the previous node.

  41. Q41. What is the main advantage of a linked list over an array?

    • A. Fast insertion and deletion without shifting elements
    • B. Fast random access by index
    • C. Better cache performance
    • D. Less memory per element
    Show answer

    Answer: A. Fast insertion and deletion without shifting elements
    Arrays give O(1) indexing; linked lists give O(1) insert/delete once you have the node.

  42. Q42. Which technique detects a cycle in a linked list using O(1) extra space?

    • A. Sorting the list
    • B. Hashing every node
    • C. Floyd's slow and fast pointers
    • D. Binary search
    Show answer

    Answer: C. Floyd's slow and fast pointers
    If the fast pointer ever meets the slow one, there is a cycle.

  43. Q43. How do you find the middle of a linked list in one pass?

    • A. Count nodes twice
    • B. Move one pointer by 1 and another by 2; when the fast one ends, the slow one is in the middle
    • C. Reverse the list first
    • D. Use binary search
    Show answer

    Answer: B. Move one pointer by 1 and another by 2; when the fast one ends, the slow one is in the middle
    The slow/fast pointer technique.

  44. Q44. In a binary search tree, where are values smaller than the root stored?

    • A. In the right subtree
    • B. In the left subtree
    • C. Anywhere
    • D. In the root only
    Show answer

    Answer: B. In the left subtree
    Left subtree < node < right subtree.

  45. Q45. Which traversal of a binary search tree gives the values in sorted order?

    • A. Inorder
    • B. Postorder
    • C. Level order
    • D. Preorder
    Show answer

    Answer: A. Inorder
    Inorder visits left, node, right.

  46. Q46. Which traversal visits a tree level by level?

    • A. Postorder
    • B. Preorder
    • C. Inorder
    • D. Breadth-first (level order)
    Show answer

    Answer: D. Breadth-first (level order)
    It uses a queue.

  47. Q47. What is the maximum number of nodes in a binary tree of height h (root at height 1)?

    • A. h²
    • B. 2^h − 1
    • C. 2h
    • D. 2^(h+1)
    Show answer

    Answer: B. 2^h − 1
    A full tree has 1 + 2 + 4 + … + 2^(h−1) nodes.

  48. Q48. What is the height of a balanced binary tree with n nodes?

    • A. About log₂ n
    • B. About √n
    • C. About n/2
    • D. About n
    Show answer

    Answer: A. About log₂ n
    Each level doubles the number of nodes.

  49. Q49. What happens to BST search time if the tree becomes a straight line (skewed)?

    • A. It stays O(log n)
    • B. It becomes O(1)
    • C. It becomes O(n)
    • D. It becomes O(n²)
    Show answer

    Answer: C. It becomes O(n)
    Self-balancing trees like AVL and red-black trees prevent this.

  50. Q50. Which property does every node satisfy in a max-heap?

    • A. Left child < parent < right child
    • B. Each parent is greater than or equal to its children
    • C. All leaves are at the same level
    • D. Children are sorted
    Show answer

    Answer: B. Each parent is greater than or equal to its children
    So the maximum is always at the root.

  51. Q51. What is the time to insert into a binary heap of n elements?

    • A. O(n log n)
    • B. O(log n)
    • C. O(1)
    • D. O(n)
    Show answer

    Answer: B. O(log n)
    The new element sifts up at most the height of the heap.

  52. Q52. Which data structure is used to implement a priority queue efficiently?

    • A. Hash table
    • B. Linked list
    • C. Heap
    • D. Stack
    Show answer

    Answer: C. Heap
    Heaps give O(log n) insert and remove-top.

  53. Q53. What is a hash collision?

    • A. A key that can't be hashed
    • B. Two keys mapping to the same bucket
    • C. Deleting a key twice
    • D. A full hash table
    Show answer

    Answer: B. Two keys mapping to the same bucket
    Handled with chaining (lists in buckets) or open addressing (probing).

  54. Q54. Which collision-handling method stores colliding keys in a list per bucket?

    • A. Linear probing
    • B. Double hashing
    • C. Separate chaining
    • D. Rehashing
    Show answer

    Answer: C. Separate chaining
    Probing methods look for another empty slot instead.

  55. Q55. What is the load factor of a hash table?

    • A. Time to compute a hash
    • B. Number of entries divided by number of buckets
    • C. Number of collisions
    • D. Size of the largest bucket
    Show answer

    Answer: B. Number of entries divided by number of buckets
    When it gets too high, tables resize (rehash) to stay fast.

  56. Q56. Which graph traversal uses a queue?

    • A. Inorder traversal
    • B. Dijkstra's with a stack
    • C. Breadth-first search (BFS)
    • D. Depth-first search (DFS)
    Show answer

    Answer: C. Breadth-first search (BFS)
    BFS explores neighbours level by level.

  57. Q57. Which graph traversal is naturally written with recursion or a stack?

    • A. Depth-first search (DFS)
    • B. Level-order traversal
    • C. Breadth-first search (BFS)
    • D. Kruskal's algorithm
    Show answer

    Answer: A. Depth-first search (DFS)
    DFS goes as deep as possible before backtracking.

  58. Q58. Which algorithm finds the shortest path in an unweighted graph?

    • A. Topological sort
    • B. Prim's algorithm
    • C. DFS
    • D. BFS
    Show answer

    Answer: D. BFS
    BFS reaches nodes in order of distance (number of edges).

  59. Q59. Which algorithm finds shortest paths from one source when edge weights are non-negative?

    • A. DFS
    • B. Kruskal's algorithm
    • C. Bubble sort
    • D. Dijkstra's algorithm
    Show answer

    Answer: D. Dijkstra's algorithm
    Bellman-Ford handles negative weights.

  60. Q60. Which algorithm can handle negative edge weights and detect negative cycles?

    • A. Prim
    • B. Bellman-Ford
    • C. Dijkstra
    • D. BFS
    Show answer

    Answer: B. Bellman-Ford
    It relaxes all edges V − 1 times.

  61. Q61. What does a minimum spanning tree connect?

    • A. All vertices with the smallest total edge weight and no cycles
    • B. Vertices in sorted order
    • C. Every pair of vertices directly
    • D. Only the two farthest vertices
    Show answer

    Answer: A. All vertices with the smallest total edge weight and no cycles
    Prim's and Kruskal's algorithms build MSTs.

  62. Q62. Kruskal's algorithm picks edges in which order?

    • A. Random order
    • B. Increasing order of weight
    • C. Order of vertex numbers
    • D. Decreasing order of weight
    Show answer

    Answer: B. Increasing order of weight
    It skips edges that would form a cycle (using union-find).

  63. Q63. Topological sort is possible only for which graphs?

    • A. Directed acyclic graphs (DAGs)
    • B. Undirected graphs
    • C. Graphs with cycles
    • D. Complete graphs
    Show answer

    Answer: A. Directed acyclic graphs (DAGs)
    Used for task scheduling and course prerequisites.

  64. Q64. How is a graph with V vertices stored in an adjacency matrix?

    • A. A V × V table where cell [i][j] marks an edge
    • B. A list of V linked lists
    • C. A binary tree
    • D. A single array of edges
    Show answer

    Answer: A. A V × V table where cell [i][j] marks an edge
    Matrices use O(V²) space; adjacency lists use O(V + E).

  65. Q65. Which is better for a sparse graph with few edges?

    • A. Adjacency list
    • B. Adjacency matrix
    • C. Neither can store it
    • D. Both use the same memory
    Show answer

    Answer: A. Adjacency list
    Lists only store the edges that exist.

  66. Q66. Which sorting algorithm is stable and always O(n log n)?

    • A. Selection sort
    • B. Heap sort
    • C. Merge sort
    • D. Quick sort
    Show answer

    Answer: C. Merge sort
    Merge sort keeps equal elements in their original order.

  67. Q67. What is the worst-case time of quick sort?

    • A. O(n log n)
    • B. O(n)
    • C. O(log n)
    • D. O(n²)
    Show answer

    Answer: D. O(n²)
    It happens with bad pivots, e.g. an already sorted array with the first element as pivot.

  68. Q68. Which sorting algorithm works best on an almost-sorted array?

    • A. Quick sort with the first element as pivot
    • B. Heap sort
    • C. Insertion sort
    • D. Selection sort
    Show answer

    Answer: C. Insertion sort
    Insertion sort is close to O(n) when few elements are out of place.

  69. Q69. Which sort repeatedly selects the minimum element and swaps it to the front?

    • A. Bubble sort
    • B. Selection sort
    • C. Merge sort
    • D. Insertion sort
    Show answer

    Answer: B. Selection sort
    It does at most n − 1 swaps.

  70. Q70. Counting sort is efficient when:

    • A. The values are strings
    • B. The values are integers in a small range
    • C. The array is huge with any values
    • D. Memory is very limited
    Show answer

    Answer: B. The values are integers in a small range
    It runs in O(n + k) where k is the range of values.

  71. Q71. What does 'in-place' sorting mean?

    • A. It never swaps elements
    • B. It uses only O(1) or very little extra memory
    • C. It sorts in O(1) time
    • D. It keeps equal elements in order
    Show answer

    Answer: B. It uses only O(1) or very little extra memory
    Quick sort and heap sort are in-place; merge sort needs O(n) extra space.

  72. Q72. Binary search requires the array to be:

    • A. Stored in a linked list
    • B. Of even length
    • C. Without negative numbers
    • D. Sorted
    Show answer

    Answer: D. Sorted
    It decides which half to discard by comparing with the middle element.

  73. Q73. What is dynamic programming?

    • A. Solving problems with random choices
    • B. Writing programs that change at run time
    • C. Solving overlapping subproblems once and reusing their answers
    • D. Allocating memory dynamically
    Show answer

    Answer: C. Solving overlapping subproblems once and reusing their answers
    Memoization (top-down) or tabulation (bottom-up).

  74. Q74. Which problem is a classic example of dynamic programming?

    • A. Linear search
    • B. Reversing a string
    • C. 0/1 knapsack
    • D. Binary search
    Show answer

    Answer: C. 0/1 knapsack
    Each item is either taken or not, and subproblems overlap.

  75. Q75. What is a greedy algorithm?

    • A. One that makes the best local choice at each step
    • B. One that always uses recursion
    • C. One that tries every possibility
    • D. One that sorts first
    Show answer

    Answer: A. One that makes the best local choice at each step
    Works when local choices lead to a global optimum, as in activity selection.

  76. Q76. Which problem is solved correctly by a greedy approach?

    • A. Travelling salesman
    • B. 0/1 knapsack
    • C. Longest common subsequence
    • D. Activity selection (maximum non-overlapping intervals)
    Show answer

    Answer: D. Activity selection (maximum non-overlapping intervals)
    Pick the activity that finishes earliest, repeatedly.

  77. Q77. What is backtracking?

    • A. Trying a choice, and undoing it when it leads to a dead end
    • B. Sorting in reverse
    • C. Traversing a list from the tail
    • D. Running a loop backwards
    Show answer

    Answer: A. Trying a choice, and undoing it when it leads to a dead end
    Used for N-Queens, Sudoku and generating permutations.

  78. Q78. What does the sliding window technique help with?

    • A. Problems on contiguous subarrays or substrings
    • B. Sorting linked lists
    • C. Tree traversal
    • D. Graph colouring
    Show answer

    Answer: A. Problems on contiguous subarrays or substrings
    Move the window's ends instead of recomputing from scratch.

  79. Q79. Which technique solves 'pair with given sum' in a sorted array in O(n)?

    • A. Recursion
    • B. Nested loops
    • C. Binary search for every pair
    • D. Two pointers from both ends
    Show answer

    Answer: D. Two pointers from both ends
    Move the left pointer up if the sum is small, the right one down if it is big.

  80. Q80. What does Kadane's algorithm find?

    • A. The median
    • B. The longest increasing subsequence
    • C. The maximum sum of a contiguous subarray
    • D. The shortest path
    Show answer

    Answer: C. The maximum sum of a contiguous subarray
    Keep the best sum ending here and the best overall.

  81. Q81. Which data structure supports finding the minimum in O(1) along with push and pop?

    • A. A plain queue
    • B. A stack that also keeps a stack of minimums
    • C. A sorted array
    • D. A hash set
    Show answer

    Answer: B. A stack that also keeps a stack of minimums
    The 'min stack' interview question.

  82. Q82. What is a trie used for?

    • A. Finding shortest paths
    • B. Balancing trees
    • C. Sorting numbers
    • D. Storing strings for fast prefix search
    Show answer

    Answer: D. Storing strings for fast prefix search
    Autocomplete and dictionaries use tries.

  83. Q83. What is the union-find (disjoint set) data structure used for?

    • A. Tracking which elements belong to the same group
    • B. Sorting strings
    • C. Finding the maximum
    • D. Reversing a list
    Show answer

    Answer: A. Tracking which elements belong to the same group
    With path compression it is nearly O(1) per operation; Kruskal's uses it.

  84. Q84. Which data structure is used for an LRU cache?

    • A. Hash map + doubly linked list
    • B. Stack only
    • C. Binary search tree only
    • D. Array only
    Show answer

    Answer: A. Hash map + doubly linked list
    The map finds entries in O(1); the list keeps them in order of use.

  85. Q85. What is a deque?

    • A. A sorted queue
    • B. A queue with only one end
    • C. A queue of queues
    • D. A double-ended queue that allows insert and remove at both ends
    Show answer

    Answer: D. A double-ended queue that allows insert and remove at both ends
    Used in the sliding-window maximum problem.

  86. Q86. How many edges does a tree with n vertices have?

    • A. n + 1
    • B. n
    • C. 2n
    • D. n − 1
    Show answer

    Answer: D. n − 1
    Every vertex except the root has exactly one parent edge.

  87. Q87. Which data structure is the natural choice for an 'undo' feature in a text editor?

    • A. Stack
    • B. Hash table
    • C. Queue
    • D. Binary search tree
    Show answer

    Answer: A. Stack
    Each action is pushed; undo pops the most recent one.

  88. Q88. Which algorithm finds strongly connected components in a directed graph?

    • A. Dijkstra's algorithm
    • B. Kosaraju's or Tarjan's algorithm
    • C. Prim's algorithm
    • D. Binary search
    Show answer

    Answer: B. Kosaraju's or Tarjan's algorithm
    Both run in O(V + E).

  89. Q89. What is memoization?

    • A. Storing variables in registers
    • B. Writing memos in code comments
    • C. Allocating memory for arrays
    • D. Caching results of function calls to avoid recomputation
    Show answer

    Answer: D. Caching results of function calls to avoid recomputation
    Turns exponential Fibonacci into linear time.

  90. Q90. What is a self-balancing BST?

    • A. A tree with only one child per node
    • B. A BST that keeps its height O(log n) after inserts and deletes
    • C. A BST stored in an array
    • D. A BST with equal values on both sides
    Show answer

    Answer: B. A BST that keeps its height O(log n) after inserts and deletes
    Examples: AVL trees and red-black trees.

  91. Q91. Which data structure would you use to check if a word exists among a million words fastest on average?

    • A. Linked list
    • B. Unsorted array
    • C. Stack
    • D. Hash set
    Show answer

    Answer: D. Hash set
    Average O(1) lookup.

  92. Q92. Which problem asks for the length of the longest subsequence common to two strings?

    • A. Longest palindromic substring
    • B. Longest common subsequence (LCS)
    • C. Knapsack
    • D. Edit distance
    Show answer

    Answer: B. Longest common subsequence (LCS)
    A classic 2D dynamic-programming problem.

  93. Q93. What does the edit distance between two strings measure?

    • A. The difference in their lengths
    • B. Their alphabetical order
    • C. The number of common letters
    • D. The minimum inserts, deletes and replacements to turn one into the other
    Show answer

    Answer: D. The minimum inserts, deletes and replacements to turn one into the other
    Also called Levenshtein distance; solved with dynamic programming.

  94. Q94. What is the time to access the k-th element of a linked list?

    • A. O(log k)
    • B. O(k²)
    • C. O(k)
    • D. O(1)
    Show answer

    Answer: C. O(k)
    You must walk from the head.

  95. Q95. Which data structure is used for function calls in a program?

    • A. A heap
    • B. The call stack
    • C. A queue
    • D. A hash table
    Show answer

    Answer: B. The call stack
    Each call pushes a frame; returning pops it. Too deep recursion overflows it.

Practised these? Now prove it.

Take a timed mock test with new questions every attempt, earn a verified certificate at 70%+, and get noticed by employers.

Start a mock test