You are given a function foo() that represents a biased coin. When foo() is called, it...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
You are given a function foo() that represents a biased coin. When foo() is called, it returns 0 with 60% probability, and 1 with 40% probability. You have to write a new function, bar(), that returns 0 and 1 with a 50% probability each. Your function should use only foo(), no other library/built-in method. In other words, inside bar(), you can only use calls to foo() as well as loops and if conditions and any other basic operators (no other function calls). To help you in that regard, you must answer the following questions. foo(): //returns 0 with probability 0.6 and 1 with probability 0.4 //you cannot change this function bar() //you have to design this //should return 0 with probability 0.5 and 1 with probability 0.5 1. What is the probability that by running foo() twice we get output (0, 1)? How about (1,0)? In other words, what is the probability that two runs of foo() give us 0 followed by 1? What is the probability that two runs of foo() give us 1 followed by 0? 2. Given the answer to the previous question design bar(). Activate Windows 3. What is the expected running time of bar()? What is the worst-case running time of bar()? Settings to activate W You are given a function foo() that represents a biased coin. When foo() is called, it returns 0 with 60% probability, and 1 with 40% probability. You have to write a new function, bar(), that returns 0 and 1 with a 50% probability each. Your function should use only foo(), no other library/built-in method. In other words, inside bar(), you can only use calls to foo() as well as loops and if conditions and any other basic operators (no other function calls). To help you in that regard, you must answer the following questions. foo(): //returns 0 with probability 0.6 and 1 with probability 0.4 //you cannot change this function bar() //you have to design this //should return 0 with probability 0.5 and 1 with probability 0.5 1. What is the probability that by running foo() twice we get output (0, 1)? How about (1,0)? In other words, what is the probability that two runs of foo() give us 0 followed by 1? What is the probability that two runs of foo() give us 1 followed by 0? 2. Given the answer to the previous question design bar(). Activate Windows 3. What is the expected running time of bar()? What is the worst-case running time of bar()? Settings to activate W
Expert Answer:
Answer rating: 100% (QA)
Lets address the questions 1 Probability of 01 and 10 in two runs of foo Probability of 01 P01 P0P1 ... View the full answer
Related Book For
Financial Accounting and Reporting a Global Perspective
ISBN: 978-1408076866
4th edition
Authors: Michel Lebas, Herve Stolowy, Yuan Ding
Posted Date:
Students also viewed these programming questions
-
Large Mart has previously attempted to develop a study pillow which would have allowed students to upload study material into their brains whilst sleeping. However, Large Mart has recently discovered...
-
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...
-
The inequality describes the range of monthly average temperatures T in degrees Fahrenheit at a certain location. (a) Solve the inequality. (b) If the high and low monthly average temperatures...
-
List and explain the stages in the product life cycle. How can a small firm extend its product's life?
-
Draw a motion diagram, a force-identification diagram, and a free-body diagram. You are a rock climber going upward at a steady pace on a vertical wall.
-
A fluid which obeys \(\mu=\frac{\tau}{d u / d y}\) : (a) Real fluid (b) Perfect fluid (c) Newtonian fluid (d) None of these
-
Bad budget system or unethical behavior? Clarence Cleaver is the budget director for the Harris County School District. Mr. Cleaver recently sent an urgent E-mail message to Sally Simmons, principal...
-
7. Are there issues associated with keeping the large sum of money in accumulated earnings? The corporation has a large amount of money in retained earnings. The corporations retained earnings...
-
1. Which aspect of the French revolution most disturbed commentators? 2. How would you align each of these writers on a spectrum running from extreme right to extreme left in politics? 3. How would...
-
Do you think there is a correlation in the rise of feminism in the late 1960s and the examples of movies for "Best Picture" being more male themed? Take into account posters for Patton, The...
-
Consider the three displacement vectors A = (41 - 31) m, B = (21 - 2) m, and C = (-8 + 1) m. Use the component method to determine the following. (a) The magnitude and direction of the vector D = A +...
-
A small car with a mass of 2.8 kg on an air track is moving to the right at 1.7 m/s, what is its Kinetic Energy in Joules?
-
A cat is running north for 25 m to get away from the dog. Then the cat turns down an alley at a 25 S of W and runs faster for 10.0 m. Finally, the cat makes one last turn and goes 16 m south and lost...
-
Which one of the following is least likely to be an objective of a cost accounting system? . OB. O C. O D. Product costing. Department efficiency. Sales commission determination. Inventory valuation.
-
A 1.00-km length of power line carries a total charge of 230 mC distributed uniformly over its length. Find the magnitude of the electric field 54.3 cm from the axis of the power line, and not near...
-
Issues referred to you by the CFO of Raven Ltd (Raven): Currently, Raven is working on a new product that it thinks will revolutionize a segment of the skin care market and generate huge revenues....
-
List four items of financial information you consider to be important to a manager of a business that has been operating for a year.
-
1 Give some arguments in favor of at least four different methods of depreciation. 2 Does depreciation provide or consume cash? 3 Give some arguments in favor of each method of reporting the sale of...
-
Haeffner PLC is an accounting firm. Some of its clients face the following situations. For each, it is assumed that a reliable estimate can be made of any outflows expected: 1. On 9 December X1 the...
-
Poulenc & Associates, a consulting firm, was incorporated on 1 June X1. On 30 June, the trial balance shows the following balances for selected accounts: Analysis reveals the following additional...
-
Consider the data file mroz on working wives and the model \(\ln (W A G E)=\beta_{1}+\beta_{2} E D U C+\) \(\beta_{3} E X P E R+e\). Use the 428 observations on married women who participate in the...
-
Problem Decide whether the sampling method is independent or dependent. Then determine whether the response variable is qualitative or quantitative. (a) Joliet Junior College decided to implement a...
-
Using the data from Table 2, construct a \(95 \%\) confidence interval estimate of the mean difference, \(\mu_{d}\). By Hand Approach Step 1 Compute the differenced data. Because the sample size is...
Study smarter with the SolutionInn App