Question: [a] Design a java algorithm to rearrange elements of a given array of n integers so that all its negative elements precede all its positive

[a] Design a java algorithm to rearrange elements of a given array of n integers so that all its negative elements precede all its positive elements and zeros (if any). Your algorithm must have a computing time no greater than Q(n). Secondly, your algorithm must use only one 1-D array. Hint: Use the partition idea similar to that of Quicksort. [b] Perform an analysis of your algorithm, i.e., compute the number of times its basic operation is executed and then determine the efficiency class of the algorithm. [c] Implement your algorithm in Java. Your program should prompt the user for the number of elements in the array then prompt the user to enter the elements. Your program should display the original array and finally display the array with the negative elements preceding the positive elements.

KEY POINT: I want the modified program to display the negative numbers on the left side NOT on the right like [-32, -1, -5, -3, -12, 45, 46, 0, 0, 7] I want it to show [0, 45, 46, 0, 7, -5, -3, -1, -12, -32]

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!