Top MCQs on Algorithms | DSA Quiz for Beginners

Last Updated : 26 Sep, 2023

Algorithm is defined as a process or set of well-defined instructions that are typically used to solve a particular group of problems or perform a specific type of calculation. To explain in simpler terms, it is a set of operations performed in a step-by-step manner to execute a task.
More On Algorithms…

DSA Quiz for Beginners | Algorithms

DSA Quiz for Beginners | Algorithms

Question 1

If the given input array is sorted or nearly sorted, which of the following algorithm gives the best performance?

Tick

Insertion sort

Cross

selection sort

Cross

Merge sort

Cross

Quick sort



Question 1-Explanation: 

Insertion sort takes linear time when the input array is sorted or almost sorted (maximum 1 or 2 elements are misplaced). All other sorting algorithms mentioned above will take more than linear time in their typical implementation.

Hence Option (A) is correct

Question 2

What is the worst-case complexity of Selection sort algorithm?

Cross

O(n)

Tick

O(n^2)

Cross

O(n log(n))

Cross

none



Question 2-Explanation: 

The worst-case complexity of the Selection Sort algorithm is O(n^2), where n represents the number of elements in the input array.

Selection Sort works by repeatedly finding the minimum element from the unsorted portion of the array and swapping it with the element at the current position. In the worst-case scenario, each iteration requires scanning the remaining unsorted portion of the array to find the minimum element, resulting in nested loops.

In the worst case, the number of comparisons made by Selection Sort is approximately (n-1) + (n-2) + (n-3) + ... + 2 + 1, which can be simplified to (n^2 - n) / 2. This gives a time complexity of O(n^2).

Hence option (B) is correct.

Question 3

what is the time complexity of the best sorting algorithms?

Cross

O(n)

Tick

O(n log(n))

Cross

O(n^2)

Cross

none



Question 3-Explanation: 

After analyzing the complexity of all sorting algorithms, O(nlogn) is the best complexity considered.

For more reference:

https://www.geeksforgeeks.org/time-complexities-of-all-sorting-algorithms/

Hence Option (B) is correct.

Question 4

Which of the following sorting algorithms has the worst time complexity for most inputs?

Cross

Quick sort

Cross

Merge sort

Tick

Bubble sort

Cross

None



Question 4-Explanation: 

Because the Average and worst-case time complexity of Bubble sort is  n^2. Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order until the entire array is sorted.
for more reference:

https://www.geeksforgeeks.org/time-complexities-of-all-sorting-algorithms/

Hence Option (C) is correct.

Question 5

Which of the following is not a stable sorting algorithm in its typical implementation?

Tick

Quick sort

Cross

Bubble Sort

Cross

Merge sort

Cross

selection sort



Question 5-Explanation: 

In its typical implementation, the Quick Sort algorithm is not a stable sorting algorithm. On the other hand, algorithms like Merge Sort and Insertion Sort are stable sorting algorithms, meaning that the relative order of equal elements is maintained during the sorting process.

Hence Option (A) is correct.

Question 6

What is the best case for linear search?

Cross

O(logn)

Cross

O(n)

Tick

O(1)

Cross

O(nlogn)



Question 6-Explanation: 

In the best case, the key might be present at the first index. So the best case complexity is O(1)

Hence Option (C) is correct.

Question 7

What is the time complexity of binary search with iteration?

Tick

O(logn)

Cross

O(n)

Cross

O(n^2)

Cross

None



Question 7-Explanation: 

Binary Search is defined as a searching algorithm used in a sorted array by repeatedly dividing the search interval in half.  and reduce the time complexity to O(log N).

Hence Option (A) is correct.

Question 8

what is the condition for applying binary search?

Cross

data is not sorted

Tick

data must be sorted

Cross

Either A  or B

Cross

None



Question 8-Explanation: 

The binary search can only be applied if the array is in sorted order.

Hence Option (B) is correct.

Question 9

What is the operator used to make 2's Two's compliment.?

Cross

& Bitwise AND Operator 
 

Cross

| Bitwise OR operator

Tick

~ Bitwise Negate Operator

Cross

^ Bitwise Exclusive OR



Question 9-Explanation: 

The bitwise  Negate operator is a unary operator (works on only one operand)., and is and used to find 2's complement.

Hence Option (C) is correct.

Question 10

What is a Single Operand Operator below.?

Cross

& Bitwise AND Operator 
 

Cross

| Bitwise OR operator

Cross

^ Bitwise Exclusive OR

Tick

~ Bitwise Negate Operator



Question 10-Explanation: 

The bitwise complement operator is a unary operator (works on only one operand),  except this all of the above are binary Operand operators.

Hence Option (D) is correct.

There are 30 questions to complete.


Share your thoughts in the comments

Similar Reads