Quick answer: Below are 100 data structures and algorithms (DSA) MCQ questions with answers, grouped into 10 topics: complexity analysis, arrays and strings, linked lists, stacks and queues, trees and BSTs, heaps and hashing, graphs, searching and sorting, recursion and dynamic programming, and DSA in Python. Tap an option to answer – you see right or wrong at once, with a short explanation.
All questions are written by Engineers R World for B.Tech CSE, IT, BCA and MCA exams, GATE CS, campus placement tests and coding interviews. Want to apply these concepts? See our dsa project ideas in python.
Try it as a quiz: tap an option to answer. You will see right or wrong at once, and your score is shown at the bottom-left of the screen.
Contents
- Complexity Analysis
- Arrays and Strings
- Linked Lists
- Stacks and Queues
- Trees and Binary Search Trees
- Heaps and Hashing
- Graphs
- Searching and Sorting
- Recursion and Dynamic Programming
- DSA in Python
1. Complexity Analysis MCQs
Q1. The time complexity of binary search on a sorted array of n elements is:
- O(log n)
- O(n)
- O(n log n)
- O(1)
Show answer
A. O(log n) Each step halves the search range, so about log₂ n steps are needed.
Q2. Big-O notation describes the:
- Exact running time
- Upper bound on growth rate
- Lower bound only
- Average memory used
Show answer
B. Upper bound on growth rate O(f(n)) bounds the growth from above; Ω gives a lower bound and Θ a tight bound.
Q3. Which growth rate is the fastest for large n?
- O(n²)
- O(n log n)
- O(2ⁿ)
- O(n³)
Show answer
C. O(2ⁿ) Exponential growth overtakes every polynomial.
Q4. Two nested loops, each running n times, give a time complexity of:
- O(n)
- O(2n)
- O(log n)
- O(n²)
Show answer
D. O(n²) The inner body runs n × n times.
Q5. The time complexity of the recurrence T(n) = 2T(n/2) + n is:
- O(n log n)
- O(n)
- O(n²)
- O(log n)
Show answer
A. O(n log n) By the master theorem (case 2), this is the merge sort recurrence.
Q6. The recurrence T(n) = T(n − 1) + 1 solves to:
- O(log n)
- O(n)
- O(n²)
- O(2ⁿ)
Show answer
B. O(n) It adds a constant n times.
Q7. Space complexity of an algorithm that uses a fixed number of variables regardless of input size is:
- O(n)
- O(log n)
- O(1)
- O(n²)
Show answer
C. O(1) Constant extra space is O(1).
Q8. Amortised analysis is used to find the:
- Worst case of a single operation
- Best case only
- Memory leak
- Average cost per operation over a sequence
Show answer
D. Average cost per operation over a sequence Example: appending to a dynamic array is O(1) amortised even though resizing is O(n).
Q9. Which notation gives a tight bound (both upper and lower)?
- Big-Theta
- Big-O
- Big-Omega
- Little-o
Show answer
A. Big-Theta Θ(f(n)) means the growth is bounded above and below by f(n).
Q10. A loop where i doubles each time (i = 1, 2, 4, … < n) runs:
- n times
- log n times
- n/2 times
- √n times
Show answer
B. log n times i takes values 2⁰, 2¹, …, so about log₂ n iterations.
2. Arrays and Strings MCQs
Q11. Accessing an element by index in an array takes:
- O(n)
- O(log n)
- O(1)
- O(n²)
Show answer
C. O(1) The address is computed directly from the base address and index.
Q12. Inserting an element at the beginning of an array of n elements takes:
- O(1)
- O(log n)
- O(n log n)
- O(n)
Show answer
D. O(n) All existing elements must be shifted by one place.
Q13. The address of A[i] in a 1-D array with base address B and element size w is:
- B + i × w
- B + i
- B × i + w
- B − i × w
Show answer
A. B + i × w Assuming 0-based indexing.
Q14. In row-major order, element A[i][j] of an m × n array is stored at offset:
- j × m + i
- i × n + j
- i + j
- i × j
Show answer
B. i × n + j Rows are stored one after another; multiply by element size for the byte offset.
Q15. Kadane's algorithm is used to find the:
- Longest common subsequence
- Shortest path
- Maximum sum contiguous subarray
- Minimum spanning tree
Show answer
C. Maximum sum contiguous subarray It scans once and keeps the best sum ending at each position – O(n).
Q16. The two-pointer technique is commonly used to:
- Sort a linked list
- Build a heap
- Traverse a tree
- Find a pair with a given sum in a sorted array
Show answer
D. Find a pair with a given sum in a sorted array One pointer starts at each end and they move towards each other.
Q17. The sliding window technique is efficient for:
- Problems on contiguous subarrays or substrings
- Tree traversal
- Graph colouring
- Matrix multiplication
Show answer
A. Problems on contiguous subarrays or substrings The window expands and shrinks instead of restarting, often giving O(n).
Q18. A dynamic array (such as a Python list) doubles its capacity when full so that appends are:
- O(n) each
- O(1) amortised
- O(log n)
- Impossible
Show answer
B. O(1) amortised Occasional O(n) copies are spread over many cheap appends.
Q19. A prefix-sum array lets you find the sum of any subarray in:
- O(n)
- O(log n)
- O(1) after O(n) preprocessing
- O(n²)
Show answer
C. O(1) after O(n) preprocessing sum(l..r) = P[r] − P[l − 1].
Q20. Checking whether two strings are anagrams using character counts takes:
- O(n²)
- O(n log n) always
- O(2ⁿ)
- O(n)
Show answer
D. O(n) Count characters of both strings and compare; sorting would take O(n log n).
3. Linked Lists MCQs
Q21. Compared with arrays, linked lists are better for:
- Frequent insertions and deletions in the middle
- Random access by index
- Cache performance
- Binary search
Show answer
A. Frequent insertions and deletions in the middle Only pointers change; no shifting is needed once the position is known.
Q22. Accessing the k-th element of a singly linked list takes:
- O(1)
- O(k)
- O(log k)
- O(k²)
Show answer
B. O(k) You must follow k links from the head.
Q23. In a doubly linked list, each node contains:
- Data only
- Data and one pointer
- Data and two pointers (next and previous)
- Two data fields
Show answer
C. Data and two pointers (next and previous) The extra pointer allows traversal in both directions.
Q24. In a circular linked list, the last node points to:
- NULL
- Itself
- The middle node
- The first node
Show answer
D. The first node There is no NULL at the end.
Q25. Floyd's cycle detection algorithm uses:
- A slow pointer and a fast pointer
- One pointer
- A stack
- A hash table only
Show answer
A. A slow pointer and a fast pointer If the fast pointer (two steps) meets the slow pointer (one step), there is a cycle.
Q26. The middle of a singly linked list can be found in one pass using:
- Binary search
- Two pointers moving at different speeds
- Sorting
- A queue
Show answer
B. Two pointers moving at different speeds When the fast pointer reaches the end, the slow one is at the middle.
Q27. Reversing a singly linked list iteratively takes:
- O(n²) time
- O(log n) time
- O(n) time and O(1) extra space
- O(n) extra space always
Show answer
C. O(n) time and O(1) extra space Change each node's next pointer as you walk the list.
Q28. Deleting the head node of a singly linked list takes:
- O(n)
- O(log n)
- O(n²)
- O(1)
Show answer
D. O(1) Just move the head pointer to the next node.
Q29. Which data structure is best for implementing an LRU cache?
- Hash map plus doubly linked list
- Array only
- Stack only
- Binary heap
Show answer
A. Hash map plus doubly linked list The hash map finds nodes in O(1); the list keeps the usage order.
Q30. Merging two sorted linked lists of sizes m and n takes:
- O(m × n)
- O(m + n)
- O(log(m + n))
- O(1)
Show answer
B. O(m + n) Compare heads and attach the smaller one each step.
4. Stacks and Queues MCQs
Q31. A stack follows the principle:
- FIFO
- Priority-based
- LIFO
- Random access
Show answer
C. LIFO Last In, First Out – the last element pushed is popped first.
Q32. A queue follows the principle:
- LIFO
- LILO only for priority queues
- Random
- FIFO
Show answer
D. FIFO First In, First Out.
Q33. Which data structure is used to evaluate a postfix expression?
- Stack
- Queue
- Heap
- Graph
Show answer
A. Stack Operands are pushed; an operator pops two, applies, and pushes the result.
Q34. The postfix form of the infix expression A + B × C is:
- AB+C×
- ABC×+
- A+BC×
- ×+ABC
Show answer
B. ABC×+ × has higher precedence, so B and C are combined first.
Q35. Function calls and recursion are managed using the:
- Heap
- Queue
- Call stack
- Hash table
Show answer
C. Call stack Each call pushes a frame; returning pops it.
Q36. Breadth-first search (BFS) uses a:
- Stack
- Priority queue only
- Deque only
- Queue
Show answer
D. Queue Nodes are visited level by level in FIFO order.
Q37. In a circular queue of size n implemented with an array, the queue is full when:
- (rear + 1) % n == front
- front == rear
- rear == n
- front == 0
Show answer
A. (rear + 1) % n == front One slot is kept empty to tell full from empty.
Q38. A deque allows insertion and deletion at:
- Front only
- Both front and rear
- Rear only
- The middle only
Show answer
B. Both front and rear Double-ended queue.
Q39. Checking balanced parentheses in an expression is best done with a:
- Queue
- Tree
- Stack
- Graph
Show answer
C. Stack Push on opening brackets, pop and match on closing ones.
Q40. The 'next greater element' problem is solved in O(n) using a:
- Binary search tree
- Min-heap
- Hash set
- Monotonic stack
Show answer
D. Monotonic stack The stack keeps elements in decreasing order while scanning.
5. Trees and Binary Search Trees MCQs
Q41. The maximum number of nodes in a binary tree of height h (root at height 0) is:
- 2ʰ⁺¹ − 1
- 2ʰ
- h²
- 2h
Show answer
A. 2ʰ⁺¹ − 1 Each level k has up to 2ᵏ nodes.
Q42. Inorder traversal of a binary search tree gives the keys in:
- Random order
- Sorted (ascending) order
- Level order
- Reverse insertion order
Show answer
B. Sorted (ascending) order Left subtree, root, right subtree.
Q43. Preorder traversal visits nodes in the order:
- Left, Root, Right
- Left, Right, Root
- Root, Left, Right
- Level by level
Show answer
C. Root, Left, Right Root first, then left, then right subtrees.
Q44. Search in a balanced BST takes:
- O(n)
- O(1)
- O(n log n)
- O(log n)
Show answer
D. O(log n) Height is O(log n) when the tree is balanced.
Q45. The worst-case search time in an unbalanced BST is:
- O(n)
- O(log n)
- O(1)
- O(n²)
Show answer
A. O(n) Inserting sorted keys creates a skewed tree like a linked list.
Q46. In an AVL tree, the balance factor of every node must be:
- 0 only
- −1, 0 or +1
- Between −2 and +2
- Any value
Show answer
B. −1, 0 or +1 Rotations restore balance after insertions and deletions.
Q47. A full binary tree with n internal nodes has how many leaves?
- n
- 2n
- n + 1
- n − 1
Show answer
C. n + 1 Every internal node has exactly two children.
Q48. Level-order traversal of a tree uses a:
- Stack
- Heap
- Hash map
- Queue
Show answer
D. Queue It is BFS applied to a tree.
Q49. When deleting a node with two children from a BST, it is replaced by its:
- Inorder successor (or predecessor)
- Parent
- Left child always
- Root
Show answer
A. Inorder successor (or predecessor) This keeps the BST ordering property.
Q50. A trie is mainly used for:
- Sorting numbers
- Prefix searches on strings
- Shortest paths
- Matrix storage
Show answer
B. Prefix searches on strings Used in autocomplete and dictionaries; search takes O(length of the word).
6. Heaps and Hashing MCQs
Q51. In a max-heap, the largest element is at the:
- Last leaf
- Leftmost leaf
- Root
- Middle
Show answer
C. Root Every parent is greater than or equal to its children.
Q52. Inserting an element into a binary heap takes:
- O(1)
- O(n)
- O(n log n)
- O(log n)
Show answer
D. O(log n) The new element sifts up at most the height of the heap.
Q53. Building a heap from an unsorted array of n elements (bottom-up heapify) takes:
- O(n)
- O(n log n)
- O(log n)
- O(n²)
Show answer
A. O(n) Most nodes are near the bottom and move only a little.
Q54. For a heap stored in an array with 0-based indexing, the children of node i are at:
- i + 1 and i + 2
- 2i + 1 and 2i + 2
- 2i and 2i + 1
- i/2 and i/2 + 1
Show answer
B. 2i + 1 and 2i + 2 The parent of node i is at (i − 1) // 2.
Q55. A priority queue is most efficiently implemented using a:
- Linked list
- Stack
- Binary heap
- Array without ordering
Show answer
C. Binary heap Insert and extract-min/max both take O(log n).
Q56. Average time for search in a hash table with a good hash function is:
- O(n)
- O(log n)
- O(n log n)
- O(1)
Show answer
D. O(1) Collisions can make the worst case O(n).
Q57. Separate chaining handles collisions by:
- Storing colliding keys in a list at the same index
- Probing the next slot
- Rehashing every key
- Ignoring the new key
Show answer
A. Storing colliding keys in a list at the same index Open addressing uses probing instead.
Q58. Linear probing tends to suffer from:
- Stack overflow
- Primary clustering
- Underflow
- Deadlock
Show answer
B. Primary clustering Runs of occupied slots grow and slow down searches.
Q59. Load factor of a hash table is:
- Table size / number of keys
- Number of collisions
- Number of keys / table size
- Hash value range
Show answer
C. Number of keys / table size When it grows too large, the table is resized and rehashed.
Q60. Finding the k largest elements in a stream efficiently uses a:
- Max-heap of all elements
- Stack
- Queue
- Min-heap of size k
Show answer
D. Min-heap of size k Keep the k largest seen so far; the root is the smallest of them – O(n log k).
7. Graphs MCQs
Q61. An adjacency matrix for a graph with V vertices uses space:
- O(V²)
- O(V)
- O(V + E)
- O(E)
Show answer
A. O(V²) Adjacency lists use O(V + E), better for sparse graphs.
Q62. BFS and DFS on a graph using adjacency lists take:
- O(V²)
- O(V + E)
- O(E log V)
- O(V × E)
Show answer
B. O(V + E) Each vertex and edge is processed a constant number of times.
Q63. Which algorithm finds the shortest path in an unweighted graph?
- DFS
- Prim's
- BFS
- Kruskal's
Show answer
C. BFS BFS explores in order of distance (number of edges).
Q64. Dijkstra's algorithm does NOT work correctly with:
- Positive weights
- Directed graphs
- Sparse graphs
- Negative edge weights
Show answer
D. Negative edge weights Bellman–Ford handles negative weights and detects negative cycles.
Q65. Dijkstra's algorithm with a binary heap runs in:
- O((V + E) log V)
- O(V²)
- O(V × E)
- O(E)
Show answer
A. O((V + E) log V) Each edge relaxation may cause a heap update.
Q66. Kruskal's algorithm builds a minimum spanning tree using:
- BFS
- Sorting edges and a union–find structure
- A stack
- Topological sort
Show answer
B. Sorting edges and a union–find structure It adds the cheapest edge that does not form a cycle.
Q67. A minimum spanning tree of a connected graph with V vertices has:
- V edges
- E edges
- V − 1 edges
- V + 1 edges
Show answer
C. V − 1 edges Any spanning tree has exactly V − 1 edges.
Q68. Topological sorting is possible only for a:
- Graph with cycles
- Undirected graph
- Complete graph
- Directed acyclic graph (DAG)
Show answer
D. Directed acyclic graph (DAG) Used for task scheduling and build order.
Q69. The Floyd–Warshall algorithm finds:
- All-pairs shortest paths
- Single-source shortest paths only
- Minimum spanning tree
- Strongly connected components
Show answer
A. All-pairs shortest paths It runs in O(V³) using dynamic programming.
Q70. A cycle in an undirected graph can be detected using:
- Binary search
- DFS with a parent check, or union–find
- Heap sort
- Only BFS on trees
Show answer
B. DFS with a parent check, or union–find Visiting an already-visited vertex that is not the parent means a cycle.
8. Searching and Sorting MCQs
Q71. Which sorting algorithm has O(n log n) worst-case time?
- Quick sort
- Bubble sort
- Merge sort
- Insertion sort
Show answer
C. Merge sort Heap sort also guarantees O(n log n); quick sort's worst case is O(n²).
Q72. The worst case of quick sort occurs when:
- The array is random
- All elements are distinct
- The array size is even
- The pivot is always the smallest or largest element
Show answer
D. The pivot is always the smallest or largest element Partitions become very unbalanced, giving O(n²).
Q73. Which sorting algorithm is stable?
- Merge sort
- Quick sort
- Heap sort
- Selection sort
Show answer
A. Merge sort Stable sorts keep equal keys in their original order.
Q74. Insertion sort is efficient when the input is:
- Reverse sorted
- Nearly sorted
- Random and very large
- Contains only duplicates
Show answer
B. Nearly sorted Its best case is O(n) for an already sorted array.
Q75. Merge sort needs extra space of:
- O(1)
- O(log n)
- O(n)
- O(n²)
Show answer
C. O(n) Merging requires a temporary array.
Q76. Counting sort runs in:
- O(n log n)
- O(n²)
- O(log n)
- O(n + k), where k is the key range
Show answer
D. O(n + k), where k is the key range It is not comparison-based, so it can beat O(n log n) for small key ranges.
Q77. The minimum number of comparisons needed by any comparison-based sort in the worst case is:
- Ω(n log n)
- Ω(n)
- Ω(n²)
- Ω(log n)
Show answer
A. Ω(n log n) A decision tree with n! leaves has height at least log₂(n!).
Q78. Binary search requires the array to be:
- Unsorted
- Sorted
- Stored as a linked list
- Of even length
Show answer
B. Sorted Otherwise discarding half of the range is not valid.
Q79. Python's built-in sort (Timsort) is a hybrid of:
- Quick sort and heap sort
- Bubble sort and selection sort
- Merge sort and insertion sort
- Radix sort and counting sort
Show answer
C. Merge sort and insertion sort It finds natural runs and merges them; it is stable with O(n log n) worst case.
Q80. The number of swaps made by selection sort on n elements is at most:
- n²
- n log n
- 2ⁿ
- n − 1
Show answer
D. n − 1 One swap per pass, so it suits cases where writes are costly.
9. Recursion and Dynamic Programming MCQs
Q81. Every recursive function must have a:
- Base case
- Loop
- Global variable
- Queue
Show answer
A. Base case Without a base case, recursion never ends and the stack overflows.
Q82. The naive recursive Fibonacci function has time complexity:
- O(n)
- O(2ⁿ)
- O(log n)
- O(n²)
Show answer
B. O(2ⁿ) It recomputes the same subproblems many times.
Q83. Dynamic programming is useful when a problem has:
- No subproblems
- Only one solution
- Overlapping subproblems and optimal substructure
- Random input
Show answer
C. Overlapping subproblems and optimal substructure Results of subproblems are stored and reused.
Q84. Memoisation is a:
- Bottom-up DP technique
- Sorting method
- Graph algorithm
- Top-down DP technique that caches recursive results
Show answer
D. Top-down DP technique that caches recursive results Tabulation is the bottom-up approach.
Q85. The 0/1 knapsack problem with n items and capacity W is solved by DP in:
- O(n × W)
- O(n + W)
- O(2ⁿ) always
- O(log W)
Show answer
A. O(n × W) This is pseudo-polynomial because it depends on the value of W.
Q86. The longest common subsequence of strings of lengths m and n takes, using DP:
- O(m + n)
- O(m × n)
- O(2^(m+n))
- O(log mn)
Show answer
B. O(m × n) Fill an (m + 1) × (n + 1) table.
Q87. Which problem is typically solved with a greedy algorithm?
- 0/1 knapsack
- Longest common subsequence
- Activity selection
- Matrix chain multiplication
Show answer
C. Activity selection Choosing the activity that finishes earliest is always safe.
Q88. Backtracking is commonly used to solve:
- Binary search
- Heap sort
- Shortest path in DAG
- N-Queens and Sudoku
Show answer
D. N-Queens and Sudoku It builds solutions step by step and undoes choices that fail.
Q89. Tail recursion is a recursion in which:
- The recursive call is the last operation
- There are two recursive calls
- No base case exists
- The function never returns
Show answer
A. The recursive call is the last operation Some languages optimise it into a loop; Python does not.
Q90. The default maximum recursion depth in CPython is about:
- 100
- 1000
- 100,000
- Unlimited
Show answer
B. 1000 sys.getrecursionlimit() returns 1000 by default; deep recursion raises RecursionError.
10. DSA in Python MCQs
Q91. In Python, list.append(x) runs in:
- O(n)
- O(log n)
- O(1) amortised
- O(n²)
Show answer
C. O(1) amortised Lists are dynamic arrays.
Q92. Removing the first element of a Python list with pop(0) takes:
- O(1)
- O(log n)
- O(1) amortised
- O(n)
Show answer
D. O(n) All other elements shift left; use collections.deque for O(1) popleft.
Q93. Which Python module provides a binary heap?
- heapq
- collections
- bisect
- itertools
Show answer
A. heapq heapq implements a min-heap on a regular list.
Q94. The bisect module in Python is used for:
- Hashing
- Binary search on sorted lists
- Graph traversal
- Random numbers
Show answer
B. Binary search on sorted lists bisect_left and bisect_right find insertion points in O(log n).
Q95. Average time for 'x in s' where s is a Python set is:
- O(n)
- O(log n)
- O(1)
- O(n log n)
Show answer
C. O(1) Sets are hash tables; for a list it would be O(n).
Q96. collections.deque is preferred over list for a queue because:
- It uses less memory always
- It is sorted
- It allows random access in O(1) at any index
- It supports O(1) append and pop at both ends
Show answer
D. It supports O(1) append and pop at both ends Indexing in the middle of a deque is O(n).
Q97. A Python dict maintains:
- Insertion order (Python 3.7+)
- Random order
- Sorted order
- Reverse order
Show answer
A. Insertion order (Python 3.7+) Order preservation became a language guarantee in Python 3.7.
Q98. Which Python structure is best for counting frequencies of items?
- tuple
- collections.Counter
- frozenset
- range
Show answer
B. collections.Counter Counter is a dict subclass for counting hashable objects.
Q99. Slicing a Python list a[i:j] takes:
- O(1)
- O(log n)
- O(j − i)
- O(n²)
Show answer
C. O(j − i) A new list is created by copying the elements.
Q100. sorted() in Python returns:
- The same list sorted in place
- None
- A generator
- A new sorted list
Show answer
D. A new sorted list list.sort() sorts in place and returns None.
How to Score Well in DSA MCQs
- Learn the time complexity of every operation for each structure – placement MCQs test this more than anything else.
- Practise tracing small examples by hand: push and pop on a stack, inorder traversal of a BST, one pass of quick sort.
- Remember the standard results: binary search O(log n), heap build O(n), comparison sort lower bound Ω(n log n), MST has V − 1 edges.
- Know which algorithm fails where – Dijkstra with negative weights, binary search on unsorted data, quick sort with bad pivots.
Related Notes and Question Banks
- DSA project ideas in Python
- Python interview questions
- Python MCQs
- Final year projects for CSE
- Python roadmap for beginners
- All MCQ quizzes
Need Help With Your Project or Exam Preparation?
We guide B.Tech, diploma and M.Tech students in design, analysis and thesis work through live online classes arranged around your free time. Message us on WhatsApp, email engineersrworld@gmail.com, or see M.Tech project guidance for working professionals.
Next: read our DSA interview questions with Python code and plan your study with the DSA roadmap.