Question discussion

How many swaps of adjacent elements does bubble sort perform while sorting the array 5, 1, 4, 2, 8 in ascending order?

1385Medium DSSSB TGT Computer Science 0 replies 1 views
0

How many swaps of adjacent elements does bubble sort perform while sorting the array 5, 1, 4, 2, 8 in ascending order?

  • A4
  • B3
  • C5
  • D6
Correct answer: A

Explanation

The number of adjacent swaps equals the number of inversions: (5, 1), (5, 4), (5, 2) and (4, 2), i.e. 4.

Discussion 0

Nobody has replied yet. Start the discussion!