0
0

What is the maximum number of comparison required to sort an array of 5 elements in bubble sort?

What is the maximum number of comparison required to sort an array of 5 elements in bubble sort?
1). 5
2). 3
3). 10
4). 25

This Question has 1 answers.

Bubble sort algorithm requires a pair of nested loops. The outer loop must iterate once for each element for the given elements i.e. n times while the inner loop iterates n times for first iteration, n - 1 time for second iteration, n - 2 times for the third iteration and this process continues.

Total number of comparison = (n - 1) + (n - 2) + (n - 3) + … = n(n - 1)/2

= 5(4)/2

= 20/2

= 10

Add Answer / Comment

Captcha Image