Learn. Practice. Feel prepared.
Data Structures and Algorithms Objective Questions and Answers - Set 2
Test your data structures and algorithms skills with high-quality MCQs focused on problem-solving, complexity analysis, and real interview-level scenarios. Designed for developers and competitive programming practice. This is part 2 of the series.
Practice Data Structures and Algorithms MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
16 What is the worst-case time complexity of inserting into a hash table with chaining? Hard
Correct answer:
O(n)
In the worst case, all keys collide into a single chain, resulting in linear time.
17 Which traversal technique is used in topological sorting? Hard
Correct answer:
BFS or DFS
Topological sorting can be implemented using either DFS or BFS-based approaches.
18 What is the main advantage of using adjacency lists over adjacency matrices? Medium
Correct answer:
Lower space for sparse graphs
Adjacency lists use less space when the graph has relatively few edges.
19 Which algorithm finds a minimum spanning tree? Medium
Correct answer:
Prim’s
Prim’s algorithm constructs a minimum spanning tree by expanding the least costly edges.
20 What is the output of pushing 1, 2, 3 into a stack and popping once? Medium
Correct answer:
3
Stacks follow LIFO order, so the last pushed element is removed first.
21 Which data structure supports insert, delete, and search in O(log n) time? Hard
Correct answer:
AVL Tree
AVL trees are self-balancing BSTs ensuring logarithmic time operations.
22 What is the worst-case time complexity of BFS on a graph? Medium
Correct answer:
O(V + E)
BFS visits all vertices and edges once in the worst case.
23 Which algorithm technique is used in the Knapsack (0/1) problem? Hard
Correct answer:
Dynamic Programming
The 0/1 Knapsack problem involves overlapping subproblems and optimal substructure.
24 What is the worst-case time complexity of Binary Search? Medium
Correct answer:
O(log n)
Binary Search halves the search space on each step.
25 Which sorting algorithm is stable? Medium
Correct answer:
Merge Sort
Merge Sort preserves the relative order of equal elements.
26 What is the time complexity of building a heap from an array? Hard
Correct answer:
O(n)
Heap construction using bottom-up approach runs in linear time.
27 Which problem is an example of backtracking? Hard
Correct answer:
N-Queens
The N-Queens problem explores possibilities and backtracks when constraints fail.
28 Which data structure is used to detect cycles in a graph using DFS? Hard
Correct answer:
Recursion stack
A recursion stack helps track the current path to detect back edges.
29 What is the space complexity of DFS using recursion? Medium
Correct answer:
O(V)
DFS recursion stack can go as deep as the number of vertices.
30 Which algorithm finds all-pairs shortest paths? Hard
Correct answer:
Floyd-Warshall
Floyd-Warshall computes shortest paths between all vertex pairs.