Asked by Joy

Use Bubble Sort to sort the list:

7, 12, 5, 22, 13, 32

What is the maximum number of comparisons required for a list of 6 numbers?

How many vcomparisons did I actually need?

Answers

Answered by MathMate
Number of comparisons for 6 numbers:
5+4+3+2+1=15

You need all 15 comparisons unless you modify the algorithm to keep track of exchanges.

There are 4 exchanges in this particular example.
Answered by Joy
Thanks for explaining this to me!
Answered by MathMate
You're welcome!
There are no AI answers yet. The ability to request AI answers is coming soon!

Related Questions