Q: 1 Best case time complexity of quick sort is achieved when?
All elements are the same
Array is sorted
Pivot is always the first element
The pivot divides the array equally in every position
[ 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: 2 What is the recurrence relation of the best case in quick sort?
T(n) = 2T(n/2)+Ө(n)
T(n) = T(n-1)+ Ө(n)
T(n) = T(n/2)+ Ө(n2)
T(n) = 2T(n/2)+ Ө(n2)
[ 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: 3 What is the worst-case complexity of selection sort?
O(n log n)
O(log n)
O(n)
O(n2)
[ 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: 4 What will be the output list after completing first pass of bubble sort on input array 32, 51,27,85,66,23,13,57?
32,27,51,66,23,13,57,85
32,51,27,66,23,13,57,85
27,33,51,23,13,57,66,85
23,13,27,33,51,57,66,85
[ 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: 5 The 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.
Unsorted
Sorted
Checked
Selected
[ 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.
Q: 6 Which of the following is a divide-and-conquer algorithm?
Merge sort
Heap sort
Bubble sort
More than one of the above
[ Option A ]
Merge Sort is a classic example of the divide-and-conquer algorithm. It works by dividing the array into two halves, recursively sorting each half, and then combining or merging the sorted halves.
LIST OF PROBLEMS THAT SOLVED USING DIVIDE AND CONQUER APPROACH:
| PROBLEM | DESCRIPTION |
|---|---|
| Merge Sort | Divides array into halves, sorts them recursively, and merges them. |
| Quick Sort | Divides array using a pivot, recursively sorts left and right subarrays. |
| Binary Search | Recursively divides sorted array to locate the target element. |
| Strassen’s Matrix Multiplication | Divides matrices into submatrices to speed up multiplication. |
| Closest Pair of Points | Divides points into halves and solves recursively for minimum distance. |
| Count Inversions in Array | Counts pair inversions using merge-sort style division. |
| Tower of Hanoi | Recursively divides problem into smaller subproblems. |
Q: 7 Merge sort is an example of which algorithm design paradigm?
Greedy
Divide and Conquer
Dynamic Programming
None of the above
[ Option B ]
Merge Sort is an example of the Divide and Conquer algorithm design paradigm. It works by repeatedly dividing the array into two halves, conquering each half by sorting them, and then combining the two sorted halves into one sorted array.
Q: 8 Which of the following sorting algorithm have a worst-case time complexity of O(n log n)?
A1. Bubble Sort
A2. Heap Sort
A3. Quick Sort
A4. Insertion Sort
A5. Selection Sort
A2 only
A2 and A3 only
A1, A2 and A3 only
A2 and A5 only
[ Option A ]
Must Know:
| Algorithm | Best Case | Average Case | Worst Case | Space Complexity | Stable? |
| Bubble Sort | O(n) (if already sorted) | O(n2) | O(n2) | O(1) | Yes |
| Insertion Sort | O(n) (if already sorted) | O(n2) | O(n2) | O(1) | Yes |
| Selection Sort | O(n) (if already sorted) | O(n2) | O(n2) | O(1) | No |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes |
| Quick Sort | O(n log n) | O(n log n) | O(n2) | O(log n) | No |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | No |
Q: 9 Choose true statement:
(I) Binary search is faster than linear search.
(II) Binary search may not be applied on all the input lists on which linear search can be applied.
Only (I)
Only (II)
Both (I) and (II)
Neither (I) nor (II)
[ Option C ]
Statement I says that binary search is faster than linear search. This is true because binary search works by repeatedly dividing the sorted list in half, giving it a time complexity of O(log n), whereas linear search checks each element one by one and takes O(n) time.
Statement II says that binary search may not be applied on all the input lists on which linear search can be applied. This is also true because binary search requires the list to be sorted, while linear search works on both sorted and unsorted lists.
Q: 10 The order of the binary search algorithm is __________.
N
N log N
N2
None of the above
[ Option D ]
Binary Search is an efficient searching algorithm used only on sorted lists or arrays. The key idea behind binary search is that instead of checking every element one by one, it repeatedly divides the search range into two halves. At each step, it compares the target value with the middle element.
If the target is equal to the middle value, the search ends. If the target is smaller, the search continues in the left half, and if it is larger, the search continues in the right half.
Because the size of the search interval becomes half at every step, the time complexity is O(log N).
Q: 11 Read the algorithm and identify the type of sorting used in it.
Set A = 0
WHILE (not sorted yet)
find the smallest unsorted item
swap first unsorted item with the smallest
Set A to A + 1
Binary
Insertion
Selection
Bubble
[ Option C ]
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.