Question
a)There is a divide-and-conquer algorithm that uses less key constants to simultaneously determine the maximum and the minimum. This uses the following idea: 1. If
a)There is a divide-and-conquer algorithm that uses less key constants to simultaneously determine the maximum and the minimum.
This uses the following idea: 1. If the set has only one element e, then this is at the same time the minimum and the maximum.
2. For a set with two elements (e1 and e2) one can find out with a comparison, which is the minimum and which is the maximum.
3. If the set has more than two elements, divide it recursively into two roughly equal subsets. As a result you get one smallest and one largest element (Min1, Max1, Min2, Max2). From this, 2 comparisons can be used to determine the total maximum and total minimum of the currently considered sublists.
Enter an algorithm in pseudocode that implements this idea.
b)In Java, implement a version of the algorithm from part a) that uses only positions as the transfer parameter, i. it should only be worked on a single list. This makes sense, especially against the background, that this is a search, so it should not be necessary to move elements or copy to find a record. Use a two-element int array with the maximum and minimum as the return type.
1-2 3nStep 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