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...
-
A company's past experience indicates that 70% of its credit sales are collected in the month of sale and 25% in the next month. The remainder is never collected. The company's budgeted credit sales...
-
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...
-
Would you feel the same way about having biometric information on your driver's license as on your passport? Why or why not?
-
The accounts of Cookie Lapp eTravel, Inc., at December 31, 20X5, are listed in alphabetical order. Required 1. All adjustments have been journalized and posted, but the closing entries have not yet...
-
Refer to the data for E5-28B. However, instead of the FIFO method, assume that Underwater Way uses the average cost method. Requirements 1. Prepare a perpetual inventory record for the watches on the...
-
The average stock price for companies making up the S&P 500 is $30, and the standard deviation is $8.20 (BusinessWeek, Special Annual Issue, Spring 2003). Assume the stock prices are normally...
-
Muller Manufacturing Co. Ltd. makes a product by way of three consecutive processes. The following data relates to process 2 for the month of May. (i) During May, 1,500 units valued at $226.50 each...
-
4.9 Estimate the static formation temperature from the following data (from Ref. 30): depth=7,646 ft, drilling stopped-22:00
-
This Final Project requires you to create a Linux server environment, demonstrating the various features and tools of a Linux network. You will document this process with both written descriptions,...
-
Linkages Among Financial Decisions, Return, Risk, and Stock Value for IBM The success of a company depends on its ability to make sound financial decisions that yield favorable returns while...
-
A couple acts on the handles of a steering system as shown in Figure 5. The moment applied by the couple about the z axis is zero for the position shown. F= 200i-110j-80k kN. Determine the distance...
-
Prepare journal entries to record the following production activities. 1. Incurred $54,000 of direct labor in the Roasting department and $22,000 of direct labor in the Blending department. Credit...
-
Case 8 Eastman Kodak's Quest for a Digital Future To support the case analysis and the assigned reading. Remember that a case study is a puzzle to be solved, so before reading and answering the...
-
The beginning account balances for Terry's Auto Shop as of January 1, Year 2, follow. Account Titles Cash Inventory Beginning Balances $16,000 8,000 Common Stock Retained Earnings 20,000 4,000 The...
-
Using the data below, what is the value of MSE? Month 1 2 3 4 Actuals 7 5 4 3 Forecast Submit 4.00 3.00 5.00 6.00 Answer format: Number: Round to: 2 decimal places.
-
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._________________________...
-
The adjusted trial balance of Marshall Ltd. at December 31, 2020. Requirements 1. Prepare Marshall Ltd.'s 2020 income statement, statement of retained earnings, and balance sheet. List expenses...
-
Fred's Catering Ltd. had the following selected transactions during May 2020: Requirements 1. Show how each transaction would be handled using the cash basis and the accrual basis, Under each column,...
-
The balance sheet at December 31, 2018, 2019) and 2020 and income statement for the years ended December 31, 2018, 2019, and 2020 for Ojibway Inc. include the following data: Requirements Use the...
Study smarter with the SolutionInn App