Question 4 - A Fantasy to Become Rich [35%] You visited a casino in Macau and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 4 - A Fantasy to Become Rich [35%] You visited a casino in Macau and played n rounds of a gambling game. You are unhappy with the total amount of money won. Suppose now a time machine appears, which allows you to go back to the past and play the game again starting at any of the n rounds. You can choose to leave the game at any round afterwards or play until round n. However, after leaving the game, you cannot join the game anymore. Your task is to design different algorithms to find the maximum amount of money you can win under such constraints. Assume that the input data is saved in a list S, which consists of n integers each representing the amount you win/lose in a round. The numbers are stored chronologically, starting with the result of the first round and ending with the result of the last round. Also, you may assume that there is at least one positive entry in the list S. For example, suppose your game result is S = [-2, 4, -3, 2, 3, -1, 2, -4, -3, 5]. You can win the maximum amount of money by joining the game at round 4 and leaving the game after round 7. Your net gain would then be +2+3-1+2= 6. (a) Design a recursive algorithm to solve the problem faster than O(n) time. Explain how your algorithm works. State and prove your algorithm's running time by setting up and solving a recurrence equation. (b) Design another algorithm to solve the problem in O(n) time and O(1) extra space. Explain how your algorithm works and prove it can run in O(n) time. Question 4 - A Fantasy to Become Rich [35%] You visited a casino in Macau and played n rounds of a gambling game. You are unhappy with the total amount of money won. Suppose now a time machine appears, which allows you to go back to the past and play the game again starting at any of the n rounds. You can choose to leave the game at any round afterwards or play until round n. However, after leaving the game, you cannot join the game anymore. Your task is to design different algorithms to find the maximum amount of money you can win under such constraints. Assume that the input data is saved in a list S, which consists of n integers each representing the amount you win/lose in a round. The numbers are stored chronologically, starting with the result of the first round and ending with the result of the last round. Also, you may assume that there is at least one positive entry in the list S. For example, suppose your game result is S = [-2, 4, -3, 2, 3, -1, 2, -4, -3, 5]. You can win the maximum amount of money by joining the game at round 4 and leaving the game after round 7. Your net gain would then be +2+3-1+2= 6. (a) Design a recursive algorithm to solve the problem faster than O(n) time. Explain how your algorithm works. State and prove your algorithm's running time by setting up and solving a recurrence equation. (b) Design another algorithm to solve the problem in O(n) time and O(1) extra space. Explain how your algorithm works and prove it can run in O(n) time.
Expert Answer:
Answer rating: 100% (QA)
a To design a recursive algorithm we can use dynamic programming to store the maximum amount of money we can win at each round We can define a functio... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
5. Use induction to prove the "extended De Morgan's law" For all n1, AAnn-AUA,UUA, Here each A, is some set, and there is some arbitrary universal set, U, that contains them all as subsets. Proof (by...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
A factor used in measuring the loudness sensed by the human ear is (I/I 0 ), 0.3 where I is the intensity of the sound and I 0 is a reference intensity. Evaluate this factor for I = 3.2 10 6 W/m 2...
-
Consider the following code: For (i = 0; i < 20; i++) For (j = 0; j < 10; j++) A[i] = a [i] * j a. Give one example of the spatial locality in the code. b. Give one example of the temporal locality...
-
The concentration of a hydrogen peroxide solution can be conveniently determined by titration against a standardized potassium permanganate solution in an acidic medium according to the following...
-
Unbalance is a fundamental cause of vibration in machinery. What frequency of interest identifies the unbalanced condition of a rotor?
-
These are selected 2014 transactions for Amarista Corporation: Jan. 1 Purchased a copyright for $120,000. The copyright has a useful life of 6 years and a remaining legal life of 30 years. Mar. 1...
-
Should southwest airlines - use all debt, all stock, or a 50-50 combination of debt and stock to finance future market-development strategy? Provide a summary recommendation/analysis overview of the...
-
Develop an MRP record, similar to the one in Figure 4-17, for wheat germ for the five weeks of January. Wheat germ must be ordered in bulk-container quantities, so the planned orders must be in...
-
EX 2-1: The following are the findings from your audit of the cash and bank accounts of your client Moneycome Company for the year ended 31 December 2017 (Sunday). 1. A check was received from a...
-
Sophia operates a large singing school with 22 employees. She receives advance fee payments from students in respect of each course (a course consists of 26 lessons). If a student does not attend all...
-
You are planning to make monthly deposits of $120 into a retirement account that pays 12 percent interest compounded monthly. If your first deposit will be made one month from now, how large will...
-
Jill Price has an incredible memory. Since she was 15 years old, she can remember everything that she has done and every t.v. show she has watched. What type of memory is special for Jill Price?
-
Daniel is a resident individual who carries on a retail business but does not use the SBE method of accounting for income in his business. On 30 June of the current tax year he had trade debtors of...
-
Describe the classic steps for identifying an endocrine gland. Are these steps practical for identifying the sources of all the hormones we know of today? Explain.
-
The expected return and standard deviation of a portfolio that is 30 percent invested in 3 Doors, Inc., and 70 percent invested in Down Co. are the following: 3 Doors, Inc. Down Co. Expected return,...
-
In 1995 Miguel purchased a home for $130,000. In 2000 he sold it for $170,000 and immediately purchased another one for $180,000, which he sold in 2007 for $235,000. How much taxable capital gain, if...
-
Plaintiff, Beth Lyons, a staff attorney for the Legal Aid Society (Legal Aid) brought suit against her employer, alleging that Legal Aid violated the Americans with Disabilities Act (ADA) and the...
-
B. C. Ziegler and Company (Ziegler) was a securities company located in West Bend. It had established an internal procedure by which its customer lists were treated confidentially. This procedure...
-
On July 5, 2000, Richard Price signed a written employment contract as a new salesman with the Mercury Supply Company. The contract was of indefinite duration and could be terminated by either party...
-
Due to the Covid recession of 2020, the U.S. government budget changed from smaller deficits to very large deficits. What impact would this have on the net exports and private sector balances, all...
-
Verify the log-likelihood in equation (16.4) for the Tobit model. In L = = In { 1-0 (x-di)} 1:y=di 122. + (y; - x) 02 (16.4) i:y;>di
-
Verify the likelihood in equation (16.5) for the two-part model. n2. (16.5) -(-)-(-2)/02 L = [] {(p;)" (1 p; )'-'} [[ ( i=1 ri=1
Study smarter with the SolutionInn App