Question: Problem 7 . Given an array A of length n , and two indices i and j with i j , define Prod ( A
Problem Given an array A of length n and two indices i and j with i j define ProdA i j as the
product of elements from Ai to Aj ie Ai Ai Aj If i j then Prodi j Ai
For example, if A then ProdA
Now, consider the following problem MaxProdA:
Input: An array A of length n where all elements are positive, but may include fractional values eg
Ai is valid
Output: The maximum possible value of ProdA i j for some subarray Aij
For example, if A the maximum product is which is achieved by the subarray
a Write pseudocode for a recursive algorithm MaxProdA that solves the problem in On log n time.
You only need to provide the pseudocode and the recurrence relation for the algorithm. points
Hint: The recurrence formula is similar to one weve used before, so you dont need to prove that it
solves to T n On log n
Note: While there are faster, nonrecursive algorithms for this problem, you must use a recursive
algorithm for this homework.
Solution. Solution to the part a goes here
b Now, write pseudocode for a recursive algorithm that solves the problem in On time. As in Part
provide the pseudocode and the recurrence relation for the algorithm. points
Hint: Similar to the Max Profit problem covered in class, solve a helper problem MaxProdXi j
which gives additional information beyond just the maximum product.
If youre confident with the On algorithm, you can directly wr
ite a single solution for both Part
and Part However, if youre unsure, first implement the On log n solution for Part then write
the separate On algorithm.
Solution. Solution to the part b goes here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
