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
-
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...
-
In his exciting novel Congo, Michael Crichton describes a search by Earth Resources Technology Service (ERTS), a geological survey company, for deposits of boron coated blue diamonds, diamonds that...
-
Rita is a trader. She provided the following information on 31 July 202: $ Inventory ........................................................... 3,140 Cash at bank...
-
A certain underlying state graph is a tree where each node has three successor nodes, indexed \(a,b, c\). There are two assets defined on this tree which pay no dividends except at the terminal time...
-
Mikita Inc. experienced the following accounting events during its 2014 accounting period: 1. Paid cash to settle an account payable. 2. Collected a cash advance for services that will be provided...
-
A simple loan with a present value of $5500 will be paid off in 5 years. If the interest rate is 7% what will the future payment be?
-
You run a payroll report that shows 100 employees received paychecks this week. However, when you look at the master payroll report you see there are 110 employees listed. What could be the possible...
-
How can a domain name infringe some other persons trademark?
-
Think about someone whom you find to be an excellent speaker. What makes this speaker excellent? How does he or she structure introductions and conclusions? Does he or she give attention to language...
-
Find a YouTube video of a global multimedia presentation (e.g., TED Talk, RSA speech). Write a brief summary about how one of your personal speech designs might be altered when tailored to a global...
-
What are the legal consequences of violating Canadas anti-spam legislation?
-
Have you ever seen a speaker reading a speech? What was your impression of that speaker? How did you feel as an audience member?
-
Prepare a Power point presentation for the board of directors (BOD) outlining the justification for implementing a new corporate information strategy (CIS) function describing activities,...
-
Refer to the data for problem 13-36 regarding Long Beach Pharmaceutical Company. Required: Compute each division's residual income for the year under each of the following assumptions about the...
-
For the particular case of hard spheres, the pressure in the virial equation of state is determined by evaluating the pair correlation function at contact. Write the pair correlation function as...
-
Use a virial expansion approach to determine the first few nontrivial order contributions to the pair correlation function \(g(r)\) in \(d\) dimensions. Show that the pair correlation function is of...
-
Show that, in the case of a degenerate gas of fermions \(\left(T \ll T_{F} ight)\), the correlation function \(g(r)\), for \(r \gg \hbar / p_{F}\), reduces to the expression \[g(r)-1=-\frac{3(m k...
Study smarter with the SolutionInn App