Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

ISBN: 0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the unions in the particular country?

Answered: 1 week ago