Question: Q 5 ) ( 2 5 pts ) Come up with a set of 1 0 numbers between 1 and 1 0 0 , let's

Q5)(25pts) Come up with a set of 10 numbers between 1 and 100, let's store these numbers in an array called \( A \), provide a trace of the call to MaxHeapify \((A,1,10)\). Make sure the set of numbers you chose results in at least \(\mathbf{2}\) swaps.
Assume you are given a sequence consisting of three types of \( n \) fruits: Apples, oranges, and bananas. The fruits are all mixed in the sequence and we want to order them such that all the apples are at the beginning of the sequence, followed by all the oranges, which are then followed by all the bananas. This arrangement must be done in-place, that is you are only allowed to use constant space other than the input sequence containing the fruits. You are allowed to access a fruit at any index i and inspect its type, but you can only do this once. You are also allowed to swap two fruits at any pair of indices i,j. Each of these operations cost O(1) time.
(a) Design an algorithm to do the desired arrangement in \( O(n)\) time. (b) Argue why your algorithm has the given bound.
Use only two pointers
Q 5 ) ( 2 5 pts ) Come up with a set of 1 0

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 Programming Questions!