Home »
MCQs
Data Structure and Algorithms (DSA) MCQs (Multiple-Choice Questions)
Data Structure & Algorithm, DSA are two major constituents of any programming language. Data Structures provide a specialized way of handling/storing data in most efficient ways. Algorithm is a set of step-by-step instructions which are to be executed in certain order to perform operations on data.
Data Structure and Algorithms (DSA) MCQs
This section contains DSA Multiple-Choice Questions with Answers. These DSA MCQs are written for beginners as well as advanced. Practice these MCQs to enhance and test the knowledge of DSA.
List of Data Structure and Algorithms (DSA) MCQs
The following are the popular MCQs on Data Structure and Algorithms (DSA):
1. What is the worst-case time complexity?
- Minimum time required for program execution
- Average time required for program execution
- Maximum time required for program execution
- None of the above
Answer: C) Maximum time required for program execution
Explanation:
Time complexity of a program represents the time required for a program to run to completion. Worst case time complexity is the maximum time required for program execution.
Discuss this question
2. What is the best-case time complexity?
- Minimum time required for program execution
- Average time required for program execution
- Maximum time required for program execution
- None of the above
Answer: A) Minimum time required for program execution
Explanation:
Time complexity of a program represents the time required for a program to run to completion. Best case time complexity is the minimum time required for program execution.
Discuss this question
3. Which of the following correctly defines the worst-case time complexity of Linear Search Algorithm?
- O(n)
- O(1)
- O(nlogn)
- O(n2)
Answer: A) O(n)
Explanation:
Linear Search, searches an element sequentially in a list. In the worst case, where an element is not present, the linear search algorithm has to scan all elements leading to O(n).
Discuss this question
4. Which of the following data structures is used for breadth first traversal of a graph?
- Stack
- Graph
- Queue
- Tree
Answer: C) Queue
Explanation:
For breadth first traversal of a graph, queue is used whereas for depth first traversal of a graph, stack is used.
Discuss this question
5. Which of the following data structures is used for depth first traversal of a graph?
- Stack
- Graph
- Queue
- Tree
Answer: A) Stack
Explanation:
For breadth first traversal of a graph, queue is used whereas for depth first traversal of a graph, stack is used.
Discuss this question
6. The below formula is used by which tree?
left_subtree (keys) ≤ node (key) ≤ right_subtree (keys)
- Red Black Tree
- AVL Tree
- Binary Search Tree
- B+ Tree
Answer: A) Red Black Tree
Explanation:
In Binary Search tree, nodes exhibit the following properties:
- Value of left tree node is less than the root node
- Value of root tree node is greater or more than the root node
Discuss this question
7. What is the minimum number of spanning tree(s) in a connected graph?
- 1
- n
- nxn
- 0
Answer: A) 1
Explanation:
Every connected graph must have at least one spanning tree.
Discuss this question
8. How to find if two vertices A and B of a graph have a path in between them?
- Using Breadth First Search, BFS
- Using Depth First Search, DFS
- Both of the above
- None of the above
Answer: C) Both of the above
Explanation:
Both BFS and DFS, we can find if two vertices A and B have a path in between them.
Discuss this question
9. What is the time required to merge two sorted lists of size m and n respectively?
- O(m)
- O(n)
- O(m + n)
- None of the above
Answer: C) O(m + n)
Explanation:
Time required to merge two sorted lists of size m and n is O(m+n).
Discuss this question
10. Queue can be used for?
- Parsing expression
- Recursion
- Resource Allocation
- None of the above
Answer: C) Resource Allocation
Explanation:
Queue is generally used for limited resources allocation. Stack is used for other operations.
Discuss this question
11. Stack can be used for?
- Parsing expression
- Recursion
- Function Calls Implementation
- All of the above
Answer: D) All of the above
Explanation:
Stack is an important data structure in computer science and it is used in multiple areas including
- Parsing regular expressions
- Memory management
- Recursive function calls
- Function calls management
- String reversal
- And many more
Discuss this question
12. Which of the following sorting algorithms is using pivot to partition unsorted lists?
- Insertion Sort
- Quick Sort
- Merge Sort
- Bubble Sort
Answer: B) Quick Sort
Explanation:
Quick Sort algorithm uses a pivot element to partition an array and then call itself recursively twice to sort the resultant sub-arrays.
Discuss this question
13. Which of the following conditions is required to be met for interpolation search to work?
- Collection should be in sorted form and equally distributed
- Collection should not be in sorted form but should be equally distributed
- Collection should not be equally distributed but should be sorted form
- None of the above
Answer: A) Collection should be in sorted form and equally distributed
Explanation:
Interpolation search is a variant of binary search. Data collection should be sorted and equally distributed for interpolation search to work correctly.
Discuss this question
14. Which of the following algorithmic approaches focuses on achieving a localized optimum solution?
- Divide and Conquer Approach
- Greedy Approach
- Dynamic Approach
- All of the above
Answer: B) Greedy Approach
Explanation:
Greedy approach focus is to achieve a local optimum solution.
Discuss this question
16. Tree traversal is generally easier than graph traversal, because?
- Tree have roots
- Trees are connected
- Graphs may have loops
- None of the above
Answer: A) Tree have roots
Explanation:
Tree traversal is easier as they have roots and don't have loops.
Discuss this question
17. Which of the following asymptotic notations is the worst among all?
- O(n)
- O(1)
- O(n^3)
- O(2n)
Answer: C) O(n^3)
Explanation:
- O(n3) being cubic is the worst one.
- O(n) is dependent on n.
- O(1) is constant.
- O(2n) is dependent on n but O(n) is better.
Discuss this question
18. Which of the following asymptotic notations is the best among all?
- O(n)
- O(1)
- O(n^3)
- O(2n)
Answer: B) O(1)
Explanation:
- O(n3) being cubic is the worst one.
- O(n) is dependent on n.
- O(1) is constant and is the best one.
- O(2n) is dependent on n but O(n) is better.
Discuss this question
19. Which of the following replaces the root in deletion operation of max heap?
- Next value of left subtree
- Next value of right subtree
- Any random value of tree
- Last element of last level
Answer: D) Last element of last level
Explanation:
Root level is always replaced by the last element of the last level regardless of max heap or min heap deletion operation.
Discuss this question
20. Which of the following replaces the root in deletion operation of min heap?
- Next value of left subtree
- Next value of right subtree
- Any random value of tree
- Last element of last level
Answer: D) Last element of last level
Explanation:
Root level is always replaced by the last element of the last level regardless of max heap or min heap deletion operation.
Discuss this question
21. Which of the following data structures can be used to check if an expression has matching parenthesis or not?
- Tree
- Queue
- Stack
- Linkedlist
Answer: C) Stack
Explanation:
Stack. As stack is using the LIFO (Last In First Out) approach, it is best suited to find matching parenthesis.
Discuss this question
22. How many edges are required to make a cyclic graph of n vertices?
- n-1
- 2n
- n
- n+1
Answer: C) n
Explanation:
To create a cycle graph, edges must be more or the same as the number of vertices.
Discuss this question
23. Which of the following exhibits the search efficiency of O(1)?
- Stack
- Queue
- Hashtable
- Heap
Answer: C) Hashtable
Explanation:
Hashtable has the capability of O(1) time complexity.
Discuss this question
24. How many moves are required as minimum to solve the Tower of Hanoi problem?
- n
- 2n
- 2n-1
- 2^n-1
Answer: D) 2^n-1
Explanation:
Considering n as the number of disks, 2n-1 are the minimum number of moves required to solve the Tower of Hanoi problem. For example, in the case of 3 disks, minimum 23-1 = 7 moves are required to solve the Tower of Hanoi problem.
Discuss this question
25. Which of the following correctly defines the Tower of Hanoi problem?
- Divide and Conquer
- Recursive
- Both of the above
- None of the above
Answer: C) Both of the above
Explanation:
Recursive approach solution of Tower of Hanoi uses divide and Conquer.
Discuss this question
26. Which of the following search algorithms does not require collection to be sorted first?
- Linear Search
- Interpolation Search
- Binary Search
- None of the above
Answer: A) Linear Search
Explanation:
Interpolation and Binary Search both require data to be sorted first. Linear search can work with unsorted data.
Discuss this question