Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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.
    1. 47
    2. Both A and B
    3. 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



Your comments will be displayed only after manual approval.