Question: Sort array in o(n) time, heres the problem N oranges and apples are arranged in a line in mixed order. It is night, however, and

Sort array in o(n) time, heres the problem  Sort array in o(n) time, heres the problem N oranges and

N oranges and apples are arranged in a line in mixed order. It is night, however, and you cannot see anything. Yet, your goal is to separate the oranges from the apples, for example putting the oranges first. You are not allowed to count the number of the fruits in the line. The only operations allowed are i) Check the fruit in a given position (say by smelling it) and determine if it is orange or apple, and i) Swap the fruits in two different positions in the line with the help of another friend of yours. Explain how to solve the problem using only these two operations in O(N) time

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!