Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this part you will explore the number of comparisons needed for exchange sort from a theoretical perspective. Let n be the number of items
In this part you will explore the number of comparisons needed for exchange sort from a theoretical perspective.
Let n be the number of items to sort and consider the case n
The st item will be compared with the ndrdth etc. item, and so on up to the th item, a total of comparisons.
The nd item will be compared with the rdthth etc. item, and so on up to the th item, a total of comparisons.
The rd item will be compared with the ththth etc. item, and so on up to the th item, a total of comparisons.
The sort continues in this way until the th item is reached. This is compared with the th item, taking just comparison, and the algorithm will now finish.
This requires a total of comparisons. We could just add these numbers together but there is a neater way. You can probably see that their average is and as there are of them the total must be times just as we found in part di
In the general case with n items the average will be n and there will be n numbers, giving a total of n times n comparisons.
iHow does the number of comparisons needed by exchange sort compare with that required by bubble sort
iiSection discusses an improved form of bubble sort, which it calls bubble sort Although in the worst case bubble sort can require n times n comparisons, the same as exchange sort, bubble sort has a particular feature that means it will generally take fewer comparisons. Explain what this feature is and describe what kind of data it makes bubble sort useful for sorting.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started