next up previous
Next: Q3: Divide and conquer Up: CSL102: Special on-line examination Previous: Q1: Longest plateau

Q2: Divide and conquer for max and min

Consider the problem of computing both the maximum and minimum values in an array of size $ n$ . A naive algorithm will require roughly $ 2n$ comparisons. Here is an alternative strategy: First, recursively sub-divide the array in two parts and compute the minimum and maximum in each part. Then compare the results obtained from each part to output the final answer. Show that the divide and conquer strategy will require roughly $ 3n/2$ comparisons. Write an imperative program based on the above idea.

You may write the program in any language of your choice. However it may be simplest to complete this Python program template.



Subhashis Banerjee 2009-04-03