A
bubble sort
algorithm is used to sort an array containing 20 elements.
Let
be the number of comparisons made in the best case, and
be the number of comparisons made in the wort case.
What is the value of
?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The best case is when the array is already sorted.
One iteration and no swaps is needed.
Number of comparisons = 1 9 .
The worst case is when the array is completely reversed.
1 9 iteration is needed.
Any pairs of numbers have been compared.
Number of comparisons = ( 2 2 0 ) = 1 9 0
Answer = 1 9 0 + 1 9 = 2 0 9