This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1What is the complexity of selection sort algorithms?
Option C
Selection sort is a sorting algorithm in which the smallest element is repeatedly selected from the unsorted part of the array and placed at its correct position.
For n elements, the algorithm performs comparisons approximately equal to [n(n−1)]/2. Since the dominant term is n2, the time complexity of selection sort is O(n2).
Q: 2Consider the following scenario during insertion sort when the array looks like as : {25, 75, 95, 125, 80, 5, 10}. The number of comparisons that it will further take for the array to be completely sorted are?
Option A
The given array state is {25, 75, 95, 125, 80, 5, 10}. This indicates that the first four elements are already sorted, and insertion sort will now continue with the remaining elements.
First, 80 is inserted into the sorted part {25, 75, 95, 125}. It is compared with 125, 95, and 75 before being placed in its correct position. This takes 3 comparisons. The array becomes {25, 75, 80, 95, 125, 5, 10}.
Next, 5 is inserted. It is compared with 125, 95, 80, 75, and 25 before reaching the beginning of the array. This requires 5 comparisons. The array becomes {5, 25, 75, 80, 95, 125, 10}.
Finally, 10 is inserted. It is compared with 125, 95, 80, 75, 25, and then with 5 before being placed correctly. This takes 6 comparisons.
So,
For 80, 3 comparisons.
For 5, 5 comparisons.
For 10, 6 comparisons.
Therefore, total comparison, 3+5+6 =14.
Q: 3Best case time complexity of quick sort is achieved when?
Option D
The best-case time complexity of Quick Sort occurs when the pivot divides the array into two equal halves at every recursive step.
| Case | Time Complexity |
|---|---|
| Best | O(n log n) |
| Average | O(n log n) |
| Worst | O(n2) |
Q: 4Which of the following sorting technique was applied for an input array {10, 5, 16, 2, 8, 9} which gives array {2, 5, 10, 16, 8, 9} after three iterations?
Option C
In Insertion Sort, the array is conceptually divided into two parts:
During each iteration, the algorithm takes the next element from the unsorted part and inserts it into its correct position within the sorted part by shifting larger elements to the right.
Thus, after the Kth iteration, the first (K+1) elements become sorted.
Array Initially:
10, 5, 16, 2, 8, 9
Iteration 1:
Insert 5 into the sorted portion [10].
5, 10, 16, 2, 8, 9
Now first 2 elements are sorted.
Iteration 2:
Insert 16 into the sorted portion [5, 10].
Since 16 is larger than both, it stays at the end.
5, 10, 16, 2, 8, 9
Now first 3 elements are sorted.
Iteration 3:
Insert 2 into the sorted portion [5, 10, 16].
All elements shift right.
2, 5, 10, 16, 8, 9
This exactly matches the array given in the question after three iterations.
Q: 5Quicksort algorithm is based on which algorithm design technique?
Option C
Quicksort is a popular sorting algorithm used to arrange elements in ascending or descending order. It is based on the Divide and Conquer technique.
In Divide and Conquer:
Q: 6Arrange in increasing order of time complexity
Option A
To arrange in increasing order, we compare time complexities of the given algorithms. Binary Search has time complexity O(log n), Merge Sort has O(n log n), and Bubble Sort has O(n2).
Since log n < n log n < n2, the increasing order is Binary Search → Merge Sort → Bubble Sort.
Q: 7What is the recurrence relation of the best case in quick sort?
Option A
A recurrence relation is an equation that expresses the running time of a problem in terms of smaller instances of the same problem. It is used in the analysis of recursive algorithms because recursion naturally breaks a large problem into smaller subproblems.
By writing and solving the recurrence relation, we can calculate the overall time complexity of the algorithm in an exact and systematic way.
In the best case of Quick Sort, each partition splits the array into two equal halves. The partitioning step itself requires scanning the entire array once, which takes Θ(n) time. After this step, two recursive calls are made on subarrays of size n/2 each, giving 2T(n/2). Therefore, the recurrence relation can be expressed as T(n) = 2T(n/2) + Θ(n). By applying the Master Theorem to this recurrence, we find that the solution is T(n) = Θ(n log n).
Q: 8What is the maximum number of comparisons required to search an element in unsorted list of ‘n’ elements using binary search?
Option D
Binary search works only on a sorted list. It repeatedly divides the search space into halves, giving a time complexity of O(log2 n). In an unsorted list, binary search cannot be applied.
Q: 9What is the worst-case complexity of selection sort?
Option D
The worst-case time complexity of Selection Sort is O(n²). This is because, in every pass of the algorithm, the smallest (if sort in ascending order) or largest (if sort in descending order) element is selected from the unsorted portion of the array by scanning all remaining elements. This requires (n−1) comparisons in the first pass, (n−2) in the second pass, and so on, until only one element is left.
The total number of comparisons becomes (n−1)+(n−2)+...+1=n(n−1)/2, which simplifies to O(n²).
Q: 10What will be the output list after completing first pass of bubble sort on input array 32, 51,27,85,66,23,13,57?
Option A
The input array is 32, 51, 27, 85, 66, 23, 13, 57. In bubble sort, we compare adjacent elements and swap them if the left element is greater than the right. During the first pass, the largest element moves to the last position.
During first pass, compare 32 and 51 → no swap, 51 and 27 → swap, 51 and 85 → no swap, 85 and 66 → swap, 85 and 23 → swap, 85 and 13 → swap, and 85 and 57 → swap. After completing these comparisons and swaps, the array becomes 32, 27, 51, 66, 23, 13, 57, 85.
Q: 11Time complexity of binary search algorithm for N elements is
Option B
Binary search works only on a sorted array and repeatedly divides the search space into half. In each step, it compares the target element with the middle element and eliminates one half of the array.
Since the number of elements is reduced by half every time, the number of steps required grows logarithmically with respect to N. Therefore, the time complexity of binary search in the worst case is O(log N).
Q: 12The average successful search time for sequential search of ‘n’ terms is
Option B
In Sequential or Linear Search, elements are checked one by one from the beginning until the required element is found. If the search is successful, the element may be located at any position from the first to the last, and each position is equally likely. Therefore, the number of comparisons required can be 1, 2, 3, … up to n.
To find the average number of comparisons, we take the mean of all possible cases:
(1+2+ ... +n)/n = [n(n+1)/2]/n = (n+1)/2.
Thus, the average successful search time in sequential search is (n+1)/2.
Q: 13Which of the following statements is correct (n is the number of elements to be searched)?
Option A
Time complexity tells us how much time an algorithm takes with respect to input size n. In linear search, we check elements one by one.
In the worst case, when the element is at the last position or not present, we need to check all n elements, so the time complexity becomes O(n).
| Algorithm | Best Case | Worst Case |
|---|---|---|
| Linear Search | O(1) | O(n) |
| Binary Search | O(1) | O(log n) |
Q: 14Binary search is optimal when the element are
Option C
Binary Search works on the principle of repeatedly dividing the search space into halves. For this method to work correctly, the elements must be sorted. The order of sorting can be either ascending or descending.
Q: 15The binary search algorithm assumes that the items in the array are ___________ and it either finds the item or eliminates half of the array with one comparison.
Option B
Binary Search is an efficient search algorithm that works on the principle of divide and conquer:
With each comparison, half of the array is eliminated, making the search faster than Linear Search.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.