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: 1How many interchanges will happen when the sequence of letters of “SORTED” is sorted using bubble sort?
Option B
In Bubble Sort, elements are compared with their adjacent elements, and an interchange (swap) occurs whenever two adjacent elements are in the wrong order.
The number of interchanges required to sort a sequence is equal to the number of inversions in that sequence.
An inversion is a pair of letters in which the earlier letter should come after the later letter in alphabetical order.
Now count the inversions.
Total interchanges = 4+2+2+2+1 = 11.
Q: 2What 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: 3Consider 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: 4Best 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: 5Which 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: 6Quicksort 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: 7Arrange 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: 8What 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: 9What 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: 10What 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²).
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.