Question: Designing and analysing a divide-and-conquer algorithm: The input is an array A[1],...,A[n] of ints, and one has to decide, whether the sum of the numbers
Designing and analysing a divide-and-conquer algorithm: The input is an array A[1],...,A[n] of ints, and one has to decide, whether the sum of the numbers is odd. (Remember the rules: even + even = even, even + odd = odd, odd + odd = even.) Take care only to use int-arithmetic (as in Java). For example, for array (1,2,3) the answer is NO, and for array (2,3,6) the answer is YES. (i) Specify how to split the array A. [2 marks] (ii) Specify how the results for the subproblems are combined into a solu- tion for array A. [4 marks] (iii) Specify the base case(s) and how to handle them. [1 marks] (iv) Write down a recurrence which describes the run-time of your algo- rithm. [2 marks] (v) Solve the recurrence by using the (simplified) Master Theorem (state which case applies), obtaining a-expression. [1 marks] (vi) Explain in a few words an alternative algorithm for solving this prob- lem, and state the asymptotic run-time for it. Compare the run-time for your above clever (divide-and-conquer) algorithm with that run- time. State which algorithm is asymptotically better, or whether they are asymptotically equally good.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
