Question: In Java Problem Description In this project, our input is an array of doubles, where each entry A [ i ] denotes the price of
In Java
Problem Description
In this project, our input is an array of doubles, where each entry A i denotes the price
of a stock or some other asset on the ith day. For example, if
then this means that the stock in question was worth on day it was worth on
day and so on
We will consider buying the stock once and then later selling it once of course we
must sell the stock after we have bought it If we buy the stock on buyDay and we sell
the stock on sellDay, then the goal is to maximize our profit A sellDayA buyDay
In the example above, the optimal solution is for buyDay to be buying at the price
and sellDay to be selling at the price This gives us a profit of
Stating the parameters formally:
We must sell on a different day than we buy, and we must sell after we buy. In
other words, we must have buyDay sellDay.
This means that if A has numbers in it there is no feasible solution. This will
affect the base case of your algorithm.
The return value should be the optimal profit you don't need to return the exact
days you are buying and sellingIn the example above, we would return
Your output should print the following to standard output eg using printf
or System.out.println etc.:
The optimal solution for input.txt is X
Here, input.txt should be whatever the name of the given input file is and
should be the actual optimal solution.
Your output must exactly match the format above, including letter capitalization
and punctuation marks.
This problem is not hard to get a solution that works using two nested forloops it
runs in time : We are wanting to improve this to a divide and conquer algorithm
that runs in time. If you do not give a divide and conquer algorithm
for this project, you will get a The entire point of this project is to design and
implement a divide and conquer algorithm, not just to get some solution that works.
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
