Describe an algorithm that produces the maximum, me- dian, mean, and minimum of a set of three integers. (The median of a set of integers is the middle element in the list when these integers are listed in order of increasing size. The mean of a set of integers is the sum of the integers divided by the number of integers in the set.)

Accepted Solution

AnswerThe mean of three numbers x1,x2,x3 can be obtained by a calculus. The first step of the algorithm is 1) [tex] mean(x1,x2,x3) = \frac{x1+x2+x3}{3} [/tex]In order to obtain the median, maximun and minumun of x1, x2 and x3, we can compare x1 and x2. The smaller of those numbers will be compared to x3 and, if x3 is even smaller, then x3 is the minimun, the other small number is the median, and the remaining number is the maximun. Otherwise, we compare x3 with the bigger number to find median and maximun. To summarize:2) compare x1 with x2. The bigger of the two numbers will be called 's' (for  small) and the smaller will be called 'b' (from big).3) compare x3 with s. The smaller of this subset will be the minimun of the entire set of 3 elements.4) Check if x3 is the minimun, in that case, s is the median, because s is between x3 and b. We also conclude that b is the maximun5) if x3 in not the minimun, then compare it with b. The bigger element between the two of them will be the maximun of the set, and the smaller one will be the median.I hope it helps you!