The following divide-and-conquer algorithm is proposed for finding the | StudySoup

Textbook Solutions for Data Structures and Algorithm Analysis in Java

Chapter 7 Problem 7.40

Question

The following divide-and-conquer algorithm is proposed for finding the simultaneousmaximum and minimum: If there is one item, it is the maximum and minimum,and if there are two items, then compare them and in one comparison you can findthe maximum and minimum. Otherwise, split the input into two halves, dividedas evenly as possibly (if N is odd, one of the two halves will have one more elementthan the other). Recursively find the maximum and minimum of each half, andthen in two additional comparisons produce the maximum and minimum for theentire problem.a. Suppose N is a power of 2. What is the exact number of comparisons used bythis algorithm?b. Suppose N is of the form 3 2k. What is the exact number of comparisons usedby this algorithm?c. Modify the algorithm as follows: When N is even, but not divisible by four, splitthe input into sizes of N/2 1 and N/2 + 1. What is the exact number ofcomparisons used by this algorithm?

Solution

Step 1 of 6)

The first step in solving 7 problem number 40 trying to solve the problem we have to refer to the textbook question: The following divide-and-conquer algorithm is proposed for finding the simultaneousmaximum and minimum: If there is one item, it is the maximum and minimum,and if there are two items, then compare them and in one comparison you can findthe maximum and minimum. Otherwise, split the input into two halves, dividedas evenly as possibly (if N is odd, one of the two halves will have one more elementthan the other). Recursively find the maximum and minimum of each half, andthen in two additional comparisons produce the maximum and minimum for theentire problem.a. Suppose N is a power of 2. What is the exact number of comparisons used bythis algorithm?b. Suppose N is of the form 3 2k. What is the exact number of comparisons usedby this algorithm?c. Modify the algorithm as follows: When N is even, but not divisible by four, splitthe input into sizes of N/2 1 and N/2 + 1. What is the exact number ofcomparisons used by this algorithm?
From the textbook chapter Sorting you will find a few key concepts needed to solve this.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Data Structures and Algorithm Analysis in Java 3 
Author Mark A. Weiss
ISBN 9780132576277

The following divide-and-conquer algorithm is proposed for finding the

Chapter 7 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back