COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
1 2 4 3 8 5 9
|
|
1 4 2 5 3 8 9
|
|
4 2 9 3 8 5 1
|
|
None of the above
|
Detailed explanation-1: -Expert-Verified Answer Total 18 swapping required to get the bubble sort.
Detailed explanation-2: -Selection Sort This sorting algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning.
Detailed explanation-3: -The basic idea behind the bubble sort is to compare the elements of an array one by one until they are sorted in ascending order, which is called bubble bursting. When an element needs to be moved, instead of moving the entire array, only the element affected by the change is moved.
Detailed explanation-4: -First, a[j] is assigned to swap, followed by a[j+1] being assigned at a[j] and at last swap is assigned to a[j+1]. This continues till all the elements are sorted. After this, the sorted array is printed. This is how the bubble sort is done.