Ask Question

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?

+2
Answers (1)
  1. 16 December, 15:43
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “2. a. Write pseudocode for a divide-and-conquer algorithm for finding valuesof both the largest and smallest elements in an array of n ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers