Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 1: Give a pseudo-code (with explanations) for the most efficient algorithm, call it Rearrange1(A), that takes as input an array $A$ of $N$ positive
Part 1: Give a pseudo-code (with explanations) for the most efficient algorithm, call it Rearrange1(A), that takes as input an array $A$ of $N$ positive integers and outputs another array $B$ in which even integers from $A$ appear before odd integers. Your algorithm should not use any other data structures except for standard arrays such as int[] in Java. For example, on input $A=\{12,8,9,4,19,16,41\}$ the algorithm can output $B=\{12$, $8,4,16,9,19,41 } .$ Note that even and odd integers do not need to appear in the same order as in A. For example, $B=\ {8,4,12,16,19,41,9\}$ is also a legitimate output. Explain the time complexity of your Rearrangel algorithm. How many passes over the arrays does it perform? How much additional space is created? Part 2: Give a pseudo-code (with explanations) for an improved and most efficient version of this algorithm, call it Rearrange2(A), which rearranges the input array A in-place, that is taking only a constant amount of additional space. In particular, your algorithm may not create any additional arrays. Explain the time complexity of your Rearrange2 algorithm. How many passes over the array A does it perform? How much additional space is created? CS.VS. 1085
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