Question
Develop an efficient in-place algorithm called Partition-Even-Odd(A) that partitions an array A in even and odd numbers. The algorithm must terminate with A containing all
Develop an efficient in-place algorithm called Partition-Even-Odd(A) that partitions an array A in even and odd numbers. The algorithm must terminate with A containing all its even elements preceding all its odd elements. For example, for input A = 7, 17, 74, 21, 7, 9, 26, 10, the result might be A = 74, 10, 26, 17, 7, 21, 9, 7 .
Partition-Even-Odd must be an in-place algorithm, which means that it may use only a constant memory space in addition to A. In practice, this means that you may not use another temporary array.
i) Write the pseudo-code for Partition-Even-Odd.
ii) Characterize the complexity of Partition-Even-Odd. Briefly justify your answer.
iii) If the complexity of your algorithm is not already linear in the size of the array, write a new algorithm Partition-Even-Odd-Optimal with complexity O(N) (with N = |A|).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started