The given array is arr = {1, 2, 4, 3}. Bubble sort is used to sort the array elements. How many passes will be done to sort the array?

The given array is arr = {1, 2, 4, 3}. Bubble sort is used to sort the array elements. How many passes will be done to sort the array? Correct Answer 1

Concept:

Bubble sort repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

Array elements: 1,2,4,3

1st Comparison = 1,2,4,3

2nd Comparison = 1,2,4,3

3rd Comparison = 1,2,4,3

1 swap is required to swap 4 and 3.

After 1st pass the array becomes = 1,2,3,4

Since array is sorted after the 1st pass

Hence the answer is Option 3.'

Related Questions