a) Describe in detail (and in English) the steps of an algorithm that finds the maximum and minimum of a sequence of n elements by examining pairs of successive elements, keeping track of a temporary maximum and a temporary minimum. If n is odd both the temporary maximum and temporary minimum should initially equal the first term, and if n is even, the temporary minimum and temporary maximum should be found by comparing the initial two elements. The temporary maximum and temporary minimum should be updated by comparing them with the maximum and minimum of the pair of elements being examined.________________b) Express the algorithm described in part (a) in pseudocode.________________c) How many comparisons of elements of the sequence arc carried out by this algorithm? (Do not count comparisons used to determine whether the end of the sequence has been reached.) How does this compare to the number of comparisons used by the algorithm in Exercise 5?

Solution:Step 1:a). We have to describe an algorithm that finds the maximum and minimum of a sequence of n elements by examining pairs of successive elements, keeping track of a temporary maximum and a temporary minimum.Step 2:The way to deal with the calculation is very like the conventional strategy for finding the maximum and minimum elements. Here, if n is odd, both the brief temporary maximum and temporary minimum ought to at first equivalent the primary term, and if n is even, the temporary minimum and temporary maximum ought to be found by looking at the underlying two components. The brief temporary maximum and temporary minimum ought to be refreshed by contrasting them and the maximum and minimum of the match of components being analyzed. Just a single loop is adequate to locate the maximum and minimum values.Step 3:b). We have to express the algorithm in the form of a pseudocode.Algorithm: Finding the maximum and minimum elementsProcedure max-min(a1,a2,a3 ………..an: natural numbers)If n = odd thenMax:= a1Min: = a1Else Max: = max(a1,a2)min:= min(a1,a2)i:=3While i If max < max(a1,a2)If min >min(a1,a2)i:=i+2Return min, max{min is the smallest element ,m is the largest}Step 5:c). Next, we need to appraise the quantity of examinations utilized as a part of the above calculation. We see that there is just a solitary loop that keeps running for [n/2] time ventures, since just a single of the two components in a couple is thought about. This is unmistakably a large portion of the quantity of correlations utilized by the standard calculation for finding the maximum and minimum values.