Question: C-5.1 Consider a modification of the selection-sort algorithm where instead of finding the smallest element in the unsorted part of the array and swapping it

 C-5.1 Consider a modification of the selection-sort algorithm where instead of

C-5.1 Consider a modification of the selection-sort algorithm where instead of finding the smallest element in the unsorted part of the array and swapping it to be in its proper place, as given in Algorithm 5.3, we instead perform a sequence of swaps to move the smallest element to its proper location, as shown in Algorithm 5.20 Show that this algorithm, which is known as bubble-sort, runs in (n2) time Algorithm BubbleSort(A): Input: An array A of n comparable elements, indexed from 1 to n Output: An ordering of A so that its elements are in nondecreasing order. fori1 to n 1 do I/ Move the smallest element in Ali +1.. nl to Ali by swaps for j ndown to i 1 do if Alj 1> Alj] then Swap Alj 1 and Alj return A Algorithm 5.20: The bubble-sort algorithm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!