Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The bubble sort presented in Fig. 6.15 is inefficient for large arrays. Make the following simple modification to improve the performance of the bubble sort.

The bubble sort presented in Fig. 6.15 is inefficient for large arrays. Make the following simple modification to improve the performance of the bubble sort.

a) After the first pass the largest number is guaranteed to be in the highest-numbered element of the array; after the second pass, the two highest numbers are in place, and so on. Instead of making nine comparisons on every pass, modify the bubble sort to make eight comparisons on the second pass, seven on the third pass and so on.

b)The data in the array may already be in the proper order or near-proper order, so why make nine passes if fewer will suffice? Modify the sort to check at the end of each pass whether any swaps have been made. If none has been made, then the data must already be in the proper order, so the program should terminate. If swaps have been made, then at least one more pass is needed.

{Please INclude psuedo Code}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago