How many comparisons are needed to locate the maximum and


Question: How many comparisons are needed to locate the maximum and minimum elements in a sequence with 128 elements using the algorithm in Example?

Example: Finding the Maximum and Minimum of a Sequence Consider the following algorithm for locating the maximum and minimum elements of a sequence a1, a2,...,an. If n = 1, then a1 is the maximum and the minimum. If n > 1, split the sequence into two sequences, either where both have the same number of elements or where one of the sequences has one more element than the other. The problem is reduced to finding the maximum and minimum of each of the two smaller sequences. The solution to the original problem results from the comparison of the separate maxima and minima of the two smaller sequences to obtain the overall maximum and minimum.

Solution Preview :

Prepared by a verified Expert
Mathematics: How many comparisons are needed to locate the maximum and
Reference No:- TGS02368654

Now Priced at $10 (50% Discount)

Recommended (92%)

Rated (4.4/5)