Mcqs on Data Structures and Algorithms
Mcqs on Data Structures and Algorithms
https://www.youtube.com/channel/UCY03nWShoNCDd29uHCbqyJw
2.https://examradar.com/mcqs/data-structure-mcqs/
3.https://engineeringinterviewquestions.com/data-structures-and-algorithms-multiple-choice-
questions-and-answers/
4.https://www.studocu.com/row/document/adama-science-and-technology-university/java-
programming/data-structures-and-algorithms-mcq-questions/20796651
1. Given the array 12 45 67 56 20 and a key of 45, how many comparisons will be made in
binary search?
A. 1
B. 3
C. 2
D. 4
2. What is the output of the following code? String name = "John";
System.out.println(name.length());
A. 3
B. 4
C. 5
D. Error
3. What is the first number in the Fibonacci sequence?
A. 0
B. 1
C. 2
D. -1
4. What is the default value assigned to an uninitialized variable of type int in Java?
A. 0
B. 1
C. -1
D. null
5. What is the time complexity of the quicksort algorithm in the average case?
A. O (1)
B. O (log n)
C. O (n)
D. O (n log n)
6. Which special pointer indicates the absence of a node’s successor?
A. null
B. void
C. dangling
D. wild
7. Which keyword is used to create an object in Java?
A. class
B. new
C. object
D. create
8. A mixture of natural language and programming language like – construct is called ___
A. code proper
B. pseudocode
C. program
D. domain-specific language
9. The time complexity of a divide and conquer algorithm can be expressed using the
following:
A. Big O notation
B. Theta notation
C. Omega notation
D. All of the above
10. A graph with numbers assigned to its edges is called __
A. weighted graph
B. directed graph.
C. path graph
D. numbered graph
11. What is the access modifier for a public member variable in a class?
A. public
B. private
C. protected
D. default
12. Which traversal order does the depth-first search follow?
The depth-first search (DFS) algorithm follows the order known as the depth-first traversal
order.
13. Algorithms that require an exponential number of operations are practical for solving
only problems of tiny size.
A. true
B. false
14. What is the output of the following code? int x = 5; System.out.println(x++);
A. 4
B. 5
C. 6
D. Error
15. Given that C(n) = 0.5n(n-1), how much longer will an algorithm run if we triple the input
size?
A. 9
B. 12
C. 6
D. 4
16. Big O is associated with ___
A. best case and upper bound
B. average case and upper bound
C. worst case and upper bound
D. lower bound and worst case
17. Which searching algorithm is commonly used to find the shortest path in a graph?
A. Linear search
B. Binary search
C. Breadth-first search
D. Depth-first search
18. Which algorithm is most suitable for searching an element in an array with non-
uniformly distributed values?
A. Linear search
B. Binary search
C. Interpolation search
D. Hashing
19. Which searching algorithm has the time complexity of O(log n)?
A. Linear search
B. Binary search
C. Quick sort
D. Bubble sort
20. Which sorting algorithm is known for its stability, i.e., it maintains the relative order of
elements with equal values?
A. Bubble sort
B. Insertion sort
C. Merge sort
D. Quick sort
21. Which sorting algorithm is known for its in-place sorting, i.e., it does not require
additional space for sorting?
A. Merge sort
B. Quick sort
C. Insertion sort
D. Radix sort
22. Which sorting algorithm is efficient for sorting extensive data collections with fixed-
length keys?
A. Bubble sort
B. Insertion sort
C. Heap sort
D. Radix sort
23. Which searching algorithm is efficient for finding an array's maximum or minimum
element?
A. Linear search
B. Binary search
C. Interpolation search
D. Hashing
24. Which search algorithm is commonly used to search in a binary search tree?
A. Linear search
B. Binary search
C. Interpolation search
D. Depth-first search
25. Which searching algorithm is most suitable for searching an element in an extensive
collection of data stored on Disk or secondary memory?
A. Linear search
B. Binary search
C. Interpolation search
D. External search
26. Which sorting algorithm is commonly used as a subroutine in other sorting algorithms,
such as quicksort?
A. Bubble sort
B. Merge sort
C. Insertion sort
27. Which searching algorithm is efficient for large data collections stored in a hash table?
A. Linear search
B. Binary search
C. Interpolation search
D. Hashing
28. Which sorting algorithm is known for its average-case time complexity of O(n log n)?
A. Bubble sort
B. Insertion sort
C. Merge sort
D. Radix sort
29. Which sorting algorithm uses a divide-and-conquer strategy?
A. Bubble sort
B. Insertion sort
C. Quick sort
D. Shell sort
30. Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the longest
possible runtime for linear search?
A. 120 µs
B. 200 µs
C. 20000 µs
D. 201 µs
31. The list is sorted into ascending order: (chopsticks, forks, knives, spork)
A. True
B. False
32. The list is sorted into ascending order: (3, 9, 44, 18, 76)
A. True
B. False
33. Given list: (4, 11, 17, 18, 25, 45, 63, 77, 89, 114). How many list elements will be
checked to find the value 17 using binary search?
A. 5
B. 8
C. 9
D. 3
34. A sort that relatively passes through a list to exchange the first element with any element
less than it and then repeats with a new first element is called______
A. quick sort
B. heap sort
C. insertion sort
D. bubble sort
35. What is the worst-case complexity of the breadth-first search algorithm? Assume n is the
number of nodes in the graph and m is the number of edges.
A. O(nm)
B. O(log n+m)
C. O(m log n)
D. O(n+m)
E. O(log n)
36. Run Time of Merge Sort is______
A. Theta of N log N
B. Gamma of N log N
C. Big O of N log N Incorrect
D. Omega of N log N
37. The list is sorted into ascending order: (great, greater, greatest)
A. True
B. False
38. Suppose a sorted list of 1024 elements is searched with binary search. How many distinct
list elements are compared against a search key that is less than all elements in the list?
A. 102 elements
B. 502 elements
C. 8 elements
D. 10 elements
39. Given a list of 10,000 elements, and if each comparison takes 2 µs, what is the fastest
possible runtime for linear search?
A. 8 µs
B. 2 µs
C. 5 µs
D. 6 µs
40. Assume selection sort's goal is to sort in ascending order. Given list (5, 9, 8, 7, 6) and i =
1, what will be the list after completing the second outer loop iteration?
Therefore, the correct answer is (5, 6, 8, 7, 9)
41. Suppose a list of 1024 elements is searched with a linear search. How many distinct list
elements are compared against a search key that is less than all elements in the list?
Therefore, the correct answer is 1024 elements.
42. Assume selection sort's goal is to sort in ascending order. Given list (9, 8, 7, 6, 5), how
many swaps will occur during the first pass of the outer loop (i = 0)?
Therefore, the correct answer is 4 swaps.
63. There are few data structures that have proved to be particularly important for
________________
A. network algorithm
B. algorithm
C. computer algorithm
D. data algorithm
64. Which of the following statements is true about brute force algorithms?
A. They are always the most efficient solution.
B. They always require exponential time to execute.
C. They are only applicable to problems with small input sizes.
D. They are helpful when no efficient algorithm exists for a problem.
65. The list is sorted into descending order: (F, D, C, B, A)
A. True
B. False
66. Suppose the selectionSort() method is executed with the array (3, 12, 7, 2, 9, 14, 8). What
is the final value for the variable i inside the inner loop?
A. 5
B. 7
C. 6
67. When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of
_____ times.
A. 19
B. 50
C. 0
D. 49
68. Suppose a list of 1024 elements is searched with a linear search. How many distinct list
elements are compared against a search key that is less than all elements in the list?
A. 402 elements
B. 1024 elements
C. 502 elements
D. 1000 elements
69. The list is sorted into descending order: (20, 15, 10, 5, 0)
A. True
B. False
70. A sort that relatively passes through a list to exchange the first element with any element
less than it and then repeats with a new first element is called______________
A. heap sort
B. bubble sort
C. insertion sort
D. quick sort
71. Which searching algorithm uses a priority queue to explore nodes and is commonly used
for pathfinding in computer games?
A. Linear search
B. Binary search
C. Breadth-first search
D. Depth-first search
72. Which sorting algorithm is based on repeatedly dividing the array into two halves and
then merging them in a sorted manner?
A. Bubble sort
B. Merge sort
C. Selection sort
D. Quick sort
73. Which sorting algorithm is suitable for sorting a linked list?
A. Bubble sort
B. Merge sort
C. Selection sort
D. Quick sort
74. Which sorting algorithm has a best-case time complexity of O(n) and a worst-case time
complexity of O(n^2)?
A. Merge sort
B. Quick sort
C. Insertion sort
D. Radix sort
75. Which sorting algorithm has a worst-case time complexity of O(n log n) and space
complexity of O(n)?
A. Selection sort
B. Insertion sort
C. Heap sort
D. Radix sort
76. Which sorting algorithm works by repeatedly selecting the smallest element from the
unsorted portion and placing it at the beginning of the sorted amount?
A. Bubble sort
B. Insertion sort
C. Selection sort
D. Quick sort
77. In modern terms, Euclid’s algorithm is based on applying__________
A. repeatedly the equity
B. repeatedly the equality
C. repeatedly the equilibrium
D. repeatedly the equal
78. ______________ is a straightforward approach to solving a problem, usually directly
based on the problem statement and definitions of the concepts involved.
A. linear
B. Force
C. Brute force
D. Algorithm
79. Steps for Divide and Conquer approach, select all that apply:
A. Combine, Divide and Conquer
B. Divide, Conquer and Combine
C. Combine, Conquer and Divide
D. Divide, Combine and Conquer
80. The decrease-and-conquer technique is based on exploiting the relationship between a
solution to a given instance of a problem and a solution to its smaller instance.
A. True
B. False
81. The searching problem deal with finding a given value called a/an_______________
A. search key
B. output key
C. input key
D. house key
82. A rooted tree is usually depicted by placing its root on the top.
A. True
B. False
83. The adjacency list of a graph or a digraph is a collection of linked lists, one for each
vertex, that contain all the vertices adjacent to the list’s vertex.
A. True
B. False
84. Which of the following represents the time complexity of LCS?
A. O(mn!)
B. O(n!)
C. O(m!)
D. O(mn)
85. In an organization, algorithms from different areas of computing are grouped together if
they have the same_____________.
A. science approach
B. design approach
C. solution approach
D. algorithm approach
86. Warshall’s algorithm for finding the transitive closure and Floyd’s algorithm for the all-
pairs shortest-paths problem is not based on the idea that can be interpreted as an
application of the dynamic programming technique.
A. False
B. True
87. The term “exhaustive search” can also be applied to two very important algorithms that
systematically process all vertices and edges of a graph.
A. True
B. False
88. As a practical matter, the validity of programs is still established by__________
A. analyzing
B. testing
C. Solving
D. Implementing
89. It is not difficult to identify the basic operation of an algorithm.
A. True
B. False
90. One classifies algorithms according to a _____________
A. Solution type
B. Software type
C. Application type
D. Problem type.
91. Dynamic programming is an algorithm design technique with a rather interesting history.
A. False
B. True
92. Programming an algorithm presents both peril and opportunity.
A. True
B. False
93. A/an__________ is a sequence of vertices in which every consecutive pair of the vertices
is connected by an edge directed from the vertex listed first to the vertex listed next.
A. discontinuous path
B. undirected path
C. continuous path
D. directed path.
94. Most algorithms are destinated to be ultimately implemented
as_________________________
A. computer programs
B. Computer software
C. computer peripheral.
D. Computer hardware
95. It is often convenient to start a link with a special node called______________
A. Sort
B. Algorithm
C. Loop
D. header
96. ____________ is a technique for solving problems with overlapping Subproblems.
A. Dynamic programming
B. Movable programming
C. Static programming
D. Java programming
97. The array and linked list are two principal choices in representing a more abstract data
structure called a linear list or simply a list.
A. True
B. False
98. Data structures and algorithms should be chosen to strike a balance among the
requirements of each _________________
A. operation
B. Application
C. document
D. work
99. An algorithm is a sequence of unambiguous instructions for solving a_____________
problem.
A. problem
B. data
C. information
D. solution
100. A data structure can be defined as a particular scheme of organizing
related______________
A. Items
B. Software items
C. Data items
D. Hardware items
101. _____________is a divide-and-conquer sorting algorithm.
A. Merge sort
B. Queue
C. Star sort.
D. Sort algorithm
102.A stack is a list in which insertions and deletions can be done only at the end. 3rationale
A. True
B. False
103. Which term best describes the time complexity of an exhaustive search algorithm?
A. Constant
B. Quadratic
C. Linear
D. Exponential
104. Which problem-solving technique is commonly associated with exhaustive search?
A. Divide and conquer.
B. Greedy algorithms
C. Dynamic programming
D. Backtracking
105. Which of the following best describes an exhaustive search?
A. A search algorithm that explores all possible solutions
B. A technique that reduces the problem space by eliminating unnecessary options
C. An approach that uses heuristics to find the optimal solution.
D. A method that prioritizes efficiency over completeness
106. Which statement is true about the efficiency of brute force algorithms?
A. They are always more efficient than other algorithms.
B. They are only efficient for small-scale problems.
C. They have the same efficiency as other algorithms in most cases.
D. They are generally less efficient than other algorithms.
107. Which data structure is commonly used in exhaustive search
algorithms?
A. Stacks
B. Queues
C. Priority queues
D. Recursion
108. Which type of problems are most suitable for an exhaustive search approach?
A. Problems with known suboptimal solutions
B. Problems with overlapping subproblems
C. Problems with a high degree of randomness
D. Problems with limited solution spaces
109. What is the primary advantage of using exhaustive search over other algorithms?
A. It always finds the optimal solution.
B. It requires fewer computational resources.
C. It guarantees faster execution time.
D. It is more straightforward to implement.
110. Which technique can be used to optimize a brute force algorithm?
A. Memorization
B. Divide and conquer.
C. Backtracking
D. Heuristic search
111. Which term best describes the approach used by brute force
algorithms?
A. Optimistic
B. Pessimistic
C. Pragmatic
D. Opportunistic
112. When is brute force a suitable approach?
A. When the problem size is too large to handle.
B. When the problem has a known optimal solution.
C. When the problem requires sophisticated heuristics.
113. What is the primary disadvantage of using brute force in algorithm design?
A. It requires extensive knowledge of advanced data structures.
B. It is inefficient and can be computationally expensive.
C. It is difficult to implement and prone to errors.
D. It is only applicable to small-scale problems.
114. What is the main advantage of using an exhaustive search?
A. It guarantees to find the optimal solution.
B. It requires minimal computational resources.
C. It is faster than other search algorithms.
D. It applies only to small-sized problems.
115. What is the time complexity of a brute force algorithm?
A. O(n log n)
B. O(n^2)
C. O(log n)
D. O(1)
116. Which of the following statements is true about exhaustive search algorithms?
A. They are always the most efficient solution,
B. They are primarily used for problem-solving in artificial intelligence.
C. They explore all possible solutions and find the global optimum.
D. They are most suitable for problems with large search spaces.
118. What does the "merge" step involve in the merge sort algorithm?
A. Sorting the individual elements of the array.
B. Dividing the array into smaller subarrays.
C. Combining two sorted subarrays into a single sorted array.
D. Repeatedly partitioning the array into smaller sections.
119. Which of the following statements is true about brute force algorithms?
A. They are always the most efficient solution.
B. They always require exponential time to execute.
C. They are only applicable to problems with small input sizes.
D. They are helpful when no efficient algorithm exists for a problem.
120. Which problem-solving approach is considered more efficient than brute force for large-
scale problems?
A. Greedy algorithms
B. Dynamic programming
C. Divide and conquer.
D. Backtracking
122. What is the primary drawback of using an exhaustive search for large-scale problems?
A. It requires specialized hardware to execute efficiently.
B. It often leads to a stack overflow error.
C. It may take an impractical amount of time to complete.
D. It requires a significant amount of memory to store intermediate results.
124. What is the primary drawback of using an exhaustive search for large-scale problems?
A. It requires specialized hardware to execute efficiently.
B. It often leads to a stack overflow error.
C. It may take an impractical amount of time to complete.
D. It requires a significant amount of memory to store intermediate results.
127. What is the main difference between brute force and greedy algorithms?
A. Greedy algorithms are more efficient than brute-force algorithms.
B. Brute force algorithms explore all possible solutions, while greedy algorithms make
locally optimal choices.
C. Greedy algorithms are only applicable to small-scale problems.
130. Which of the following is an example of a problem where brute force is the only viable
approach?
A. Sorting an extensive array of integers.
B. Finding the shortest path in a graph.
C. Testing all possible combinations of a password.
D. Finding the maximum value in a binary search tree.
131. What is the main drawback of using brute force for problem-solving?
A. It lacks generality and cannot be applied to various problem domains.
B. It requires advanced knowledge of mathematical formulas.
C. Itis highly susceptible to errors and mistakes in implementation
D. It often leads to exponential time complexity.
134.How many times longer will sorting a list of 20 elements take compared to sorting a list of
10 elements?
A. 1
B. 4
C. 20
D. 10
135.When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of _____
times.
A. 19
B. 50
C. 49
D. 0
136. A sort that relatively passes through a list to exchange the first element with any element
less than it and then repeats with a new first element is called______________
A. quick sort
B. insertion sort
C. bubble sort
D. heap sort
137.How many times longer will sorting a list of 500 elements take compared to a list of 50
elements?
A. 500
B. 50
C. 400
D. 100
138.Which sorting algorithm works by repeatedly selecting the smallest element from the
unsorted portion and placing it at the beginning of the sorted amount?
A. Bubble sort
B. Insertion sort
C. Selection sort
D. Quick sort
140. What does the "conquer" step involve in the divide and conquer technique?
A. Breaking down the problem into smaller subproblems.
B. Combining the solutions of the subproblems to obtain the final solution.
C. Iteratively reducing the problem size until it can be solved directly.
D. Analyzing the algorithm's complexity to determine the time and space requirements.
141. Which sorting algorithm works by repeatedly swapping adjacent elements if they are in the
wrong order?
A. Bubble sort
B. Quick sort
C. Heap sort
D. Shell sort
142. Which of the following sorting algorithms has the worst-case time complexity of O(n^2)?
A. Merge sort
B. Insertion sort
C. Selection sort
D. Quick sort
143.Which sorting algorithm is suitable for sorting data that is already partially sorted or
contains many equal elements?
A. Bubble sort
B. Merge sort
C. Insertion sort
D. Quick sort
144.Which searching algorithm efficiently finds an element in a balanced binary search tree?
A. Linear search
B. Binary search
C. Interpolation search
D. Hashing
147. Which sorting algorithm has a best-case time complexity of O(n) and a worst-case time
complexity of O(n^2)?
A. Merge sort
B. Quick sort
C. Insertion sort
D. Radix sort
148.Which of the following is NOT a typical application of the divide and conquer technique?
A. Sorting algorithms
B. Searching algorithms.
C. Graph traversal algorithms
D. Matrix multiplication algorithms
150.Which of the following is NOT a step in the divide and conquer technique?
A. Combine
B. Analyze
C. Divide
D. Search