2. a. Write pseudocode for a divide-and-conquer algorithm for finding valuesof both the largest and smallest elements in an array of n numbers.b. Set up and solve (for n = 2k) a recurrence relation for the number of keycomparisons made by your algorithm.c. How does this algorithm compare with the brute-force algorithm for thisproblem?

Respuesta :

The pseudocode :

Pair MaxiMini(array, sizeof_array)

if sizeof_array = 1

return element as both maximum and minimum

else if sizeof_array = 2

do one comparison to find the maximum and minimum

return that pair

else

# sizeof_array > 2

recursion for maximum and minimum of the left half

recursion for maximum and minimum of the right half

one comparison determines the true max of the two elements

one comparison determines the true min of the two elements

return the pair of maximum and minimum

ACCESS MORE
EDU ACCESS
Universidad de Mexico