Consider the following code. int f(int x, int y) { int r = 1; while (y...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following code. int f(int x, int y) { int r = 1; while (y > 1) { if (y % 2 == 1) { r = x * r; 1 2 3 4 5 6 7 8 9 } x = x= x; y = y / 2; } 10 return rx; 11 } 1. Complete the following table for iterations 0,1,2,3, 4 (iteration 0 means outside of the loop) iteration xy loop invariant 0 1 2 4 2. Find a loop invariant that involves r? 3. Find a loop invariant that involves x and y? 4. Formally prove that the loop invariant in part (b) (that involves x and y) is true before and after each execution of the loop. That is, you need to prove that the loop invariant holds true initially, then at the end of each iteration. 5. This function returns r r. What does it computes in terms of the inputs x and y? Consider the following code. int f(int x, int y) { int r = 1; while (y > 1) { if (y % 2 == 1) { r = x * r; 1 2 3 4 5 6 7 8 9 } x = x= x; y = y / 2; } 10 return rx; 11 } 1. Complete the following table for iterations 0,1,2,3, 4 (iteration 0 means outside of the loop) iteration xy loop invariant 0 1 2 4 2. Find a loop invariant that involves r? 3. Find a loop invariant that involves x and y? 4. Formally prove that the loop invariant in part (b) (that involves x and y) is true before and after each execution of the loop. That is, you need to prove that the loop invariant holds true initially, then at the end of each iteration. 5. This function returns r r. What does it computes in terms of the inputs x and y?
Expert Answer:
Answer rating: 100% (QA)
1 Initially x 3 r 1 y 4 first iteration y 2 1 is false So r remains sam... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these computer network questions
-
Sundance Systems has the following transactions during July. July 5 Purchases 56 LCD televisions on account from Red River Supplies for $3,300 each, terms 3/10, n/30. July 8 Returns to Red River two...
-
If the focal length of a lens is 3 centimeters and the image distance is 5 centimeters from the lens, what is the distance from the object to the lens?
-
What is the output of the following? A. 1223445 B. 2445 C. 22445 D. 223445 E. 2233445 F. None of the above. public class InitOrder { } {System.out.print("1"); } static System.out.print("2"); } public...
-
A marble of mass m and radius r rolls along the looped rough track of Fig. 8-58. What is the minimum value of the vertical height h that the marble must drop if it is to reach the highest point of...
-
The Audiofile Company produces boomboxes. However, management has decided to subcontract out the production of the speakers needed for the boomboxes. Three vendors are available to supply the...
-
While the electromagnetic interaction between the photons and the charged electrons and positrons kept them in equilibrium with each other during the early universe, show that the direct...
-
Faith Evans Corporation is a regional company which is an SEC registrant. The corporations securities are thinly traded on NASDAQ (National Association of Securities Dealers Quotes). Faith Evans...
-
Discuss the ways in which wrong decision making can impact the success of a project. Highlight the various leadership styles that were utilized in the case. Give examples specifically from the case....
-
The AGRI Venture: An Integrated Marketing Communications Program. Chapter 16 states that there are three major forms of cooperative advertising: horizontal, ingredient-sponsored and vertical. Discuss...
-
An annuity has an income of 2 0 0 per year for 1 0 years at an interest rate of 1 0 % what is the present value.
-
An object 2 cm high is placed 2 3 cm from a convex lens of focal length 1 5 cm . ( a ) Determine the position of the image by calculation. ( b ) Determine the size of the image by calculations. ( c )...
-
I am currently part of a research based writing-intensive course to valuing a company including financial figures. In this course, we are asked to pick one company and talk about a specific dilemma...
-
You have just received a windfall from an investment you made in a friend's business. She will be paying you $49,725 at the end of this year, $99,450 at the end of next year, and $149,175 at the end...
-
_______ algorithms improve system performance and allow for multiple operations to be performed simultaneously on a single computer - parallelor- distributed
-
An AM radio tuning circuit has a coil with an inductance of 6 . 0 mH and a capacitor set at 7 . 5 - 6 microF. What frequency will it detect?
-
Cellular respiration can best be described as taking electrons from food and giving them to phosphate to make ATP converting higher-energy organic molecules to lower-energy organic molecules and...
-
A seasonal index may be less than one, equal to one, or greater than one. Explain what each of these values would mean.
-
Mallory Corporation has a calendar year-end. The corporation has paid estimated payments of $10,000 during 2012 but still owes an additional $5,000 for its 2012 tax year. a. When is the 2012 tax...
-
Kathy Kennedy (age 44) is a single taxpayer and she lives at 212 North Pine Way, Payson, AZ 85541. Her Social Security number is 467-98-9784. Kathy's earnings and income tax withholding as the...
-
How are qualified dividends taxed in 2012? Please give the two rates of tax which apply to qualified dividends, and specify when each of these rates applies._________________________...
-
True or False: When dealing with multiple alternatives having unequal lives, the planning horizon equals the least common multiple of lives.
-
For each of the following categories, describe some of the difficulties that you would face in estimating appropriate values to be used in conducting an economic analysis. a. Cash flows b. MARR c....
-
Given the following information about sources of capital, what is the appropriate weighted average cost of capital to use in determining MARR? a. 9.87 percent b. 10.55 percent c. 12.42 percent d....
Study smarter with the SolutionInn App