COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Insertion
|
|
Selection
|
|
Bubble
|
|
Quick
|
Detailed explanation-1: -With a worst-case complexity of O(n^2), bubble sort is very slow compared to other sorting algorithms like quicksort. The upside is that it is one of the easiest sorting algorithms to understand and code from scratch.
Detailed explanation-2: -Selection sort performs a smaller number of swaps compared to bubble sort; therefore, even though both sorting methods are of O(N2), selection sort performs faster and more efficiently!
Detailed explanation-3: -Insertion sort is an efficient sorting algorithm than selection and bubble sort. The average case time complexity of the insertion sort is closer to the worst-case time complexity, i.e. O(n²). The above pseudo-code sort the array in increasing order.
Detailed explanation-4: -Stability. Bubble sort and insertion sort are stable, whereas selection sort isn’t. The selection sort can be made stable by incorporating the indices of equal elements when comparing and sorting them. But then the space complexity increases from O(1) to O(N), where N is the size of the array.