-
An array contains four occurrences of 0, five occurrences of 1, and three occurrences of 2 in any order. The array is to be sorted using swap operations (elements that are swapped need to be adjacent).
(a) What is the minimum number of swaps needed to sort such an array in the worst case?
(b) Give an ordering of elements in the above array so that the minimum number of swaps needed to sort the array is maximum.
-
- 47
- Both A and B
- None of these
Correct Option: C
(a) 47
(b) 22210000 1111 Arrangements that satisfy one of the following two constraints are also correct.
(i) 1’s in the first 4 positions and no 2 in the last 3 positions
or
(ii) 1’s in the last 3 positions and no zero in the first 4 positions
or