MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many swaps are required to sort the given array using bubble sort-{ 2, 5, 1, 3, 4}
A
4
B
5
C
6
D
7
Explanation: 

Detailed explanation-1: -Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations to sort the given array.

Detailed explanation-2: -Total 10 swaps are required to sort the array.

Detailed explanation-3: -In bubble sort, Number of swaps required = Number of inversion pairs. When an array is sorted in descending order, the number of inversion pairs = n(n-1)/2 which is maximum for any permutation of array.

Detailed explanation-4: -Total 18 swapping required to get the bubble sort.

Detailed explanation-5: -Note: Bubble sort with n element required n-1 passes.

There is 1 question to complete.