Divide and Conquer Project
Writing in language: C 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 sellDay 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=""><= 1 number 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 selling). so in the example above, we would return 4. ● your output should print the following to standard output (e.g., using printf() or system.out.println(), etc.): o the optimal solution for input.txt is x. o here, input.txt should be whatever the name of the given input file is, and x should be the actual optimal solution. this problem is not hard to get a solution that works using two nested for-loops (it runs in time o(n^2)). we are wanting to improve this to a divide and conquer algorithm that runs in o(n*log n) time. you must provide a bash script named ‘project1.sh’ that will act similarly to a makefile. 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 there are no source files for this project. however there is a blank project1.sh file for you to fill in as well as several input files to test your code with. 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 with all the provided 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). also, there is an example output.txt file for what your output should look like. **did the code give a divide and conquer algorithm that runs in o(n*log n) time that returns the correct answer for all possible inputs? 1="" number="" 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="" selling).="" so="" in="" the="" example="" above,="" we="" would="" return="" 4.="" ●="" your="" output="" should="" print="" the="" following="" to="" standard="" output="" (e.g.,="" using="" printf()="" or="" system.out.println(),="" etc.):="" o="" the="" optimal="" solution="" for="" input.txt="" is="" x.="" o="" here,="" input.txt="" should="" be="" whatever="" the="" name="" of="" the="" given="" input="" file="" is,="" and="" x="" should="" be="" the="" actual="" optimal="" solution.="" this="" problem="" is="" not="" hard="" to="" get="" a="" solution="" that="" works="" using="" two="" nested="" for-loops="" (it="" runs="" in="" time="" o(n^2)).="" we="" are="" wanting="" to="" improve="" this="" to="" a="" divide="" and="" conquer="" algorithm="" that="" runs="" in="" o(n*log="" n)="" time.="" you="" must="" provide="" a="" bash="" script="" named="" ‘project1.sh’="" that="" will="" act="" similarly="" to="" a="" makefile.="" 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="" there="" are="" no="" source="" files="" for="" this="" project.="" however="" there="" is="" a="" blank="" project1.sh="" file="" for="" you="" to="" fill="" in="" as="" well="" as="" several="" input="" files="" to="" test="" your="" code="" with.="" 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="" with="" all="" the="" provided="" 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).="" also,="" there="" is="" an="" example="" output.txt="" file="" for="" what="" your="" output="" should="" look="" like.="" **did="" the="" code="" give="" a="" divide="" and="" conquer="" algorithm="" that="" runs="" in="" o(n*log="" n)="" time="" that="" returns="" the="" correct="" answer="" for="" all="" possible="">= 1 number 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 selling). so in the example above, we would return 4. ● your output should print the following to standard output (e.g., using printf() or system.out.println(), etc.): o the optimal solution for input.txt is x. o here, input.txt should be whatever the name of the given input file is, and x should be the actual optimal solution. this problem is not hard to get a solution that works using two nested for-loops (it runs in time o(n^2)). we are wanting to improve this to a divide and conquer algorithm that runs in o(n*log n) time. you must provide a bash script named ‘project1.sh’ that will act similarly to a makefile. 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 there are no source files for this project. however there is a blank project1.sh file for you to fill in as well as several input files to test your code with. 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 with all the provided 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). also, there is an example output.txt file for what your output should look like. **did the code give a divide and conquer algorithm that runs in o(n*log n) time that returns the correct answer for all possible inputs?>