An array contains four occurrences of 0, five occurrences of 1, and three…

PYQ GATE 2000

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.

Attempted by 1 students.

Sign up free to check your answer

Sign up free

Explore the full course: Algorithms

Loading lesson…