Solveeit Logo

Question

Computer Science Question on Sorting

If a list contains ’n’ number of elements and all the elements are by default sorted in ascending order, how many comparisons will be required during 1st pass of bubble sort to arrange the list in ascending order?

A

0

B

1

C

n - 1

D

n

Answer

n - 1

Explanation

Solution

Bubble Sort makes n - 1 comparisons in the first pass, even if the list is already sorted, but no swaps occur.