Programming Project 1 Divide and Conquer In this project, our input is an array of doubles,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Programming Project 1 Divide and Conquer 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. So for example, if A = [5, 2, 3, 6, 1, 3] then this means that the stock in question was worth 5 on day 0, it was worth 3 on day 2, etc. 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[sellDay] - A[buyDay]. In the example above, the optimal solution is for buyDay to be 1 (buying at the price A[1] = 2) and sell Day to be 3 (selling at the price A[3] = 6). This gives us a profit of 4. 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 Since everyone is coding in their own preferred language, we are asking you to provide a bash script named project1.sh that will act similarly to a makefile. I covered how bash scripts work in class in the Project 1 overview lecture, and I recorded a short follow-up to this here: https://youtu.be/CalFJWiyU U In short, your bash script should contain the command to compile your code, and then on a different line, it should contain the line to execute your code. There are several input files for you to test your code on, and the bash script should take a command line argument specifying which input file to run on. So, the command to execute your code should look like this: bash project1.sh input.txt See the YouTube video that I linked for more details on how to use command line arguments inside a bash script. Files provided in the project: Since you are programming in different languages, we are providing no source files for your code. We have provided a blank project1.sh file for you to fill in as well as several input files for you to test your code on. Each input file contains a single price on each line of the file. The first line should be index 0 of your array, the second line should be index 1, etc. We will test your code will all the privided input files, but we will also be testing with some different input files that will be in the same format. Some of these files may be very large (hundreds of thousands of entries). Programming Project 1 Divide and Conquer 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. So for example, if A = [5, 2, 3, 6, 1, 3] then this means that the stock in question was worth 5 on day 0, it was worth 3 on day 2, etc. 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[sellDay] - A[buyDay]. In the example above, the optimal solution is for buyDay to be 1 (buying at the price A[1] = 2) and sell Day to be 3 (selling at the price A[3] = 6). This gives us a profit of 4. 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 Since everyone is coding in their own preferred language, we are asking you to provide a bash script named project1.sh that will act similarly to a makefile. I covered how bash scripts work in class in the Project 1 overview lecture, and I recorded a short follow-up to this here: https://youtu.be/CalFJWiyU U In short, your bash script should contain the command to compile your code, and then on a different line, it should contain the line to execute your code. There are several input files for you to test your code on, and the bash script should take a command line argument specifying which input file to run on. So, the command to execute your code should look like this: bash project1.sh input.txt See the YouTube video that I linked for more details on how to use command line arguments inside a bash script. Files provided in the project: Since you are programming in different languages, we are providing no source files for your code. We have provided a blank project1.sh file for you to fill in as well as several input files for you to test your code on. Each input file contains a single price on each line of the file. The first line should be index 0 of your array, the second line should be index 1, etc. We will test your code will all the privided input files, but we will also be testing with some different input files that will be in the same format. Some of these files may be very large (hundreds of thousands of entries).
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Tiering of suppliers what is it? effects of reducing supplier base? Relation between OEM and supplier 1 base?
-
Question 5 (1 point) III Listen Provide an appropriate response. Find the indefinite integral sin 2t dt. 7.1.3.jpg O O O O cost+C -cost + C cos 2t + C -2 cos 2t + C 7.1.2.jpg Q Search 7.1.1.jpg
-
Use the demand schedule to the upper right to calculate total revenue and marginal revenue at each quantity. Plot the demand, total-revenue, and marginal-revenue curves and explain the relationships...
-
The adjusted trial balance for Sweet Home Catering, Inc., is presented below. Prepare the income statement and statement of retained earnings for Sweet Home Catering, Inc., for the month ended March...
-
Consider a binomial random variable with n = 8 and p = .7. Let x be the number of successes in the sample. a. Find the probability that x is 3 or less. b. Find the probability that x is 3 or more. c....
-
On January 1, 2008, ABC Ltd. started its business by purchasing a productive oil well. The proved oil reserves from the well are expected to generate $7,000 cash flow at the end of 2008, $6,000 at...
-
To be relevant to a particular decision, a cost must have three attributes. What are they? R-1
-
This information relates to Crisp Co. 1. On April 5, purchased merchandise from Frost Company for $28,000, terms 2/10, n/30. 2. On April 6, paid freight costs of $700 on merchandise purchased from...
-
XYX corporations capital structure calls for 60% debt and 40% common equity. The companys cost of debt is 8%.Retained earnings are estimated to be $160 million.The companys cost of retained earnings...
-
Summary of this paragraph Although not everyone agrees that the unbridled globalization of professional sports is all for the good, the process and possibilities are definitely far reaching. Today's...
-
4) The heat transfer correlation for a liquid flowing over a single cylinder is given by the following equation for Nusselt number (Nu): Nu-h D/k=(0.506 Re5+ 0.00141 Re) Pro where hheat-transfer...
-
Reply to The culture established by Mr. Kelleher places importance on employee happiness, which directly influences customer satisfaction and overall organizational achievements. To maintain this...
-
we as a country that has a real risk free rate of 2 percent, expected inflation rate: Year 1(Jan 2020)2.0 percent Year 2 (Jan 2021)3.0 percent Year 3(Jan 2022)3.0 percent Calculate the average...
-
shows a rotating shaft carrying two steady downward loads F at C and D, respectively and D is right in the middle between A and B. The shaft is held by a pair of bearings at A and B, respectively. As...
-
Suppose the U.S. and Japan trade with each other. For simplicity, assume that the only 2 goods that are traded are phones and bikes. The figure below summarizes the impact. of trade in the United...
-
1. On January 1, 2021 ALAN COMPANY acquired a piece of land with a building for a lumpsum amount of P1,000,000. The fair value of the land and building were P900,000 and P300,000 respectively. ALAN...
-
A firm has the following balance sheet: Assets Cash Accounts receivable Inventory Plant and equipment $ 15,000 150,000 92,000 170,000 $427,000 Liabilities and Equity Accounts payable Long-term debt...
-
Below is information from the statement of retained earnings of Mrs. Bells Cookies, Inc. for a recent year. Prepare the statement of retained earnings for Mrs. Bells Cookies in good form. You will...
-
Primorsk Corporation began the year 20x6 with cash of $55,900. In addition to earning a net income of $32,500 and paying a cash dividend of $19,500, Primorsk borrowed $78,000 from the bank and...
-
Saxon wants to know if its profitability performance has increased from 20x6 to 20x7. The company had net income of $24,000 in 20x6 and $25,000 in 20x7. Total assets were $200,000 at the end of 20x5,...
Study smarter with the SolutionInn App