Page 1 of 1

Let A[1::n] be an array of n positive numbers. Entry A[i] represents the trading price of a stock X on the i-th day (and

Posted: Sun May 15, 2022 12:11 pm
by answerhappygod
Let A[1::n] be an array of n positive numbers. Entry A
represents the trading
price of a stock X on the i-th day (and hence the numbers are
ordered chronologically).
Write an algorithm max-profit that returns a pair (a, b) such that
if one buys stock X
on the a-th day and sells it on the b-th day, the maximum profit is
made. Give the time
complexity of your algorithm in Big-O. Show the derivation of the
complexity result.