In class we described the following problem called the "Stock Market Problem": We are given an array A of n values where A[i] indicates the value of a share of Millisoft stock on day i. That is, we have a history of n days of the values of this stock. For simplicity, assume that n is a power of 2.
Our objective is to find the maximum profit that could be made by purchasing a single share on some day and selling on that day or later. (Buying and selling on the same day makes 0 profit, so you can't do worse than that!) Remember, you cannot sell on a day before your buy day!
Your job is to describe and analyze a divide-and-conquer algorithm for this problem.
temp1 = (a+b)(c+d)
temp2 = ac
temp3 = bd
z = temp2 2^{n} + (temp1 - temp2 - temp3) 2^{n/2} + temp3
Nothing for you to do here! This is just the description of the
algorithm.
Last modified December 2004 by Ran Libeskind-Hadas