Which of the following sorting algorithms has the lowest worst-case co...
Worst case complexities for the above sorting algorithms are as follows: Merge Sort — nLogn Bubble Sort — n^2 Quick Sort — n^2 Selection Sort — n^2
Which of the following sorting algorithms has the lowest worst-case co...
Explanation:
Merge Sort:
Merge Sort is a divide and conquer algorithm that divides the input array into two halves, sorts each half recursively, and then merges the sorted halves to produce a sorted output. It has a worst-case time complexity of O(n log n), where n is the number of elements in the input array.
Bubble Sort:
Bubble Sort is a simple comparison-based sorting algorithm. It repeatedly swaps adjacent elements if they are in the wrong order. Bubble Sort has a worst-case time complexity of O(n^2), where n is the number of elements in the input array.
Quick Sort:
Quick Sort is another divide and conquer algorithm that works by selecting a pivot element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively. Quick Sort has a worst-case time complexity of O(n^2), but on average it has a time complexity of O(n log n).
Selection Sort:
Selection Sort is a simple comparison-based sorting algorithm. It repeatedly finds the minimum element from the unsorted part of the array and swaps it with the element at the beginning of the unsorted part. Selection Sort has a worst-case time complexity of O(n^2).
Comparison:
- Merge Sort has a worst-case time complexity of O(n log n).
- Bubble Sort and Selection Sort both have a worst-case time complexity of O(n^2).
- Quick Sort has a worst-case time complexity of O(n^2), but on average it has a time complexity of O(n log n).
Conclusion:
Among the given sorting algorithms, Merge Sort has the lowest worst-case time complexity of O(n log n). Therefore, option 'A' is the correct answer.