167k views
2 votes
InExercise1youwereaskedtomodifytheSortsprogramsothatitwouldoutput thenumberofswapsusedbyasortingmethod.Itisalittlemoredificulttohavethe programalsooutputthenumberofcomparisons(compares)needed.Youmustinclude oneormorestatementstoincrementyourcounterwithinthesortingmethods themselves.Foreachofthelistedmethods,makeandtestthechangesneeded,and listboththenumberofswapsandthenumberofcomparesneededbytheSorts programtosortanarrayof50randomintegers. a. selectionSort swaps:____ compares:____ b. bubbleSort swaps:____ compares:____ c. shortBubble swaps:____ compares:____ d. insertionSort swaps:____ compares

1 Answer

3 votes

Answer:

D. InsertionSort swap: compares

Step-by-step explanation:

The insertion sort swap is useful in making changes to the program needed to be sorted.

It should be noted that, this method is used to list the numbers of swap and the number of compares which are needed by the sort program.

User Andrew Paramoshkin
by
4.5k points