Question: We are given an array A of n positive and n negative numbers, which are intermixed. We would like to rearrange the numbers in A

We are given an array A of n positive and n negative numbers, which are intermixed. We would
like to rearrange the numbers in A such that positive and negative numbers appear in alternating
order.
For example, if n=4 and A=2,3,-1,4,-1,-5,-2,2>, then A=-1,2,-1,3,-5,4,-2,2>
or A=4,-5,2,-1,3,-1,2,-2> are both correct solutions. Describe a linear-time ((n)) in-
place algorithm to solve this problem (an in-place algorithm produces the solution within the input
array, using at most (1) extra space).
Prove the correctness of your algorithm using loop invariants and analyze its runtime and space
requirement.
 We are given an array A of n positive and n

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!