Question: hi how to do this in python? Exercise 2 - Separate positive and negative numbers Given a list of both positive and negative numbers in

 hi how to do this in python? Exercise 2 - Separate

hi how to do this in python?

Exercise 2 - Separate positive and negative numbers Given a list of both positive and negative numbers in random order, design and implement an efficient algorithm to rearrange the array elements so that positive and negative numbers are placed alternatively, starting from a positive number, and so that positives are sorted and negatives are sorted. If there are more negative or positive numbers, they should be placed at the end of the rearranged list (for this latter part, the order in which numbers appear is not important). Example: Given [8,1,2,4,6,12,5,10,16,7,11], the algorithm should output: [1,4,6,8,12,10,5,2,16,7,11] Hint You can do this using a modified version of insertion sort in O(N2), and of mergesort in O(NlogN). If you only care about alternating +/ without sorting them, try using Quicksort' pivoting method (see next week lectures) to elegantly do it in O(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!