Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ou are a savvy investor who is interested in an especially hot asset that is now on the market: a rare Pikachu Pok emon trading
ou are a savvy investor who is interested in an especially hot asset that is now on the market: a rare Pikachu Pok emon trading card. You want to purchase and sell this card just once, and time these events to maximize your rate of return, ie the percentage by which the cards value increases between purchase and sale.
Your top tradingdesk researchers have prepared their best estimates of how much the cards value will change on each of the following n days. These estimates are given as nonnegative real multiplicative factors, ie a gain is represented by and a loss is represented by Given the array An of these estimates, you want to find indices i j n that maximize
Ai Ai Aj
ie the aggregate growth in value if the card is purchased at the start of day i and sold at the
end of day jIf the card would lose value every day, this can be indicated by taking i j
For instance, if A then the maximum aggregate growth iswhichisachievedbyijNotethatitisalsoachievedbyij So an optimal choice of i and j is not necessarily unique, but the maximum aggregate growth is unique.
In this question you will design a divideandconquer algorithm that solves this problem. You may assume that two real numbers can be multiplied in constant time, and for simplicity, you may assume that n is a power of two if you wish
a Suppose that for some index k of interest, you want to optimize the aggregate growth under the constraint that you own the card on day k and sell it strictly after day k ie you purchase it at the start of some day i k and sell it at the end of some day j k Give an algorithm that solves this problem in On time. On input A n and k it should output the maximum aggregate growth, and corresponding purchase and sale days i j that achieve it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started