Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions