Question: In class, we discussed a method for making the bubble sort more efficient by not comparing and swapping the largest value after every pass (outside

In class, we discussed a method for making the bubble sort more efficient by not comparing and swapping the largest value after every pass (outside loop), since it has already been sorted to its correct position.

For example, if we were to sort the following 3 numbers: 5 3 1

This is how it would be sorted:

1st pass (outside loop) - 1st iteration (inside loop) - Swap 5 and 3 to get: 3 5 1

1st pass (outside loop) - 2nd iteration(inside loop) - Swap 5 and 1 to get: 3 1 5

You notice that the largest number 5 is now currently correctly sorted, so there is no need to compare it any further and your next pass would be a as follows: 2nd pass(outside loop) - 1st iteration (inside loop) - Swap 3 and 1: 1 3 5

No further comparisons are needed since 5 is already in the correct position

----------------------------------------------------------------

For your assignment, you need to write the pseudocode to perform the bubble sort, with the added efficiency of eliminating the final comparison after each pass. For your program, you are sorting a random list of 20 numbers stored in an array.

Tips: You need to use two loops to accomplish this as demonstrated in class. You need an outside loop to control each pass and an inside loop to control each comparison for swapping.

Program Language just like this:

In class, we discussed a method for making the bubble sort more

start Declarations num SIZE 100 num scores[SIZE num x num y num temp num number0fE1s = 0 num comparisons num QUIT 999 337 fi11ArrayO sortArrayO displayArrayO stop fi11Array O output "Enter a score or ", QuIT, " to quit" input scores [x) while x

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!