Consider the following program, which takes as input an integer n > 0, and returns some...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following program, which takes as input an integer n > 0, and returns some other integer as a result. P(n) { i = 0; 8 := 0; while (i < n) do i=i+1 s = sti return s (a) Compute P(n) on a few test values of your choice, and determine the function g(n) computed by the program. Your answer should include at least 5 tests, but you do not need to include the intermediate steps of the computation. (You may run the program on a computer if you like.) (b) Prove that the program P(n) computes the function g(n) by presenting an appropriate loop invariant for the program. Your solution should include a clear description of the loop invariant, a proof that the loop invariant is correct, and a proof that the correctness of the program follows from the loop invariant. Consider the following program, which takes as input an integer n > 0, and returns some other integer as a result. P(n) { i = 0; 8 := 0; while (i < n) do i=i+1 s = sti return s (a) Compute P(n) on a few test values of your choice, and determine the function g(n) computed by the program. Your answer should include at least 5 tests, but you do not need to include the intermediate steps of the computation. (You may run the program on a computer if you like.) (b) Prove that the program P(n) computes the function g(n) by presenting an appropriate loop invariant for the program. Your solution should include a clear description of the loop invariant, a proof that the loop invariant is correct, and a proof that the correctness of the program follows from the loop invariant.
Expert 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 programming questions
-
PLEASE GIVE CORRECT ANSWERS Prove that the number of comparators in any sorting network is (n log n). [4 marks] (ii) What does Part (d)(i) imply in terms of the depth of any sorting network? [1 mark]...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
The Kroger Company reported the following data in its annual report (in millions). Instructions a. Compute Kroger?s inventory turnovers for fiscal years ending January 28, 2017, and January 30, 2016,...
-
MusicBiz.net Ltd. specializes in sound equipment. Because each inventory item is expensive, MusicBiz uses a perpetual inventory system. Company records indicate the following data for a line of...
-
Identify the slide error in the following trial balance, assuming this is the only error. Body Boot Camp Trial Balance April 30, 2020 $330 Cash.. Supplies. Notes payable. Michelle Jackson, capital....
-
Determine if the mixed method aspect is concurrent, sequential,, or nested. Develop a hypothetical research scenario that would necessitate the use of the Mixed Method A-B-A Design. The research will...
-
At December 31, 2010, Grinkov Corporation had the following account balances. Installment Accounts Receivable, 2009........................$ 65,000 Installment Accounts Receivable,...
-
Data Manipulation Tasks a Insert 20 records into each table for testing purposes. a Delete an entire order by using the unique identifier for that order. o Update the price of a product by using the...
-
In a survey, adults were asked to answer yes or no to the question Do you regularly watch the evening TV news? Some of the results from the survey are detailed in the Venn diagram opposite. One adult...
-
14. Arrange the following compounds in the increasing order of acidic strength (i) Benzoic acid (ii) p-methoxy benzoic acid (iii) O-methoxy benzoic acid (a) i < ii > iii (b) iii
-
1. Use the following problem for the next 2 questions. The total assets of the corporation is only 10M excluding the land on which its office is situated. A domestic corporation shows the following...
-
A helicopter's speed increases from 30 m/s to 50 m/s in 5 seconds. What is the acceleration of this helicopter?
-
A cart rolling down an incline for 8.0 seconds has an acceleration of 7.0 m/s. If the cart has a beginning speed of 2.0 m/s, what is its final speed?
-
What is the market risk premium and pricing for this bond. Information as below Offering Date 02/08/2021 Dated Date 02/11/2021 First Coupon Date 08/15/2021 Original Offering* $500,000.00 Amount...
-
As she climbs a hill, a cyclist slows down from 52 m/s to 22 m/s in 10 seconds. What is her deceleration?
-
The ability to communicate in English is important for many jobs and therefore some companies offer ESL (English as a Foreign Language) courses to their non-English-speaking employees. One...
-
Suppose the S&P 500 futures price is 1000, = 30%, r = 5%, = 5%, T = 1, and n = 3. a. What are the prices of European calls and puts for K = $1000? Why do you find the prices to be equal? b. What...
-
Indicate, in each of the following situations, the number of exemptions the taxpayers are entitled to claim on their 2012 income tax returns. Number of Exemptions a. Donna, a 20-year-old single...
-
Ken (age 31) and Amy (age 28) Booth have brought you the following information regarding their income, expenses, and withholding for the year. They are unsure which of these items must be used to...
-
Clarita is a single taxpayer with two dependent children, ages 10 and 12. Clarita pays $3,000 in qualified child care expenses during the year. If her adjusted gross income (all from wages) for the...
-
A cyclotron is made of sheet metal in the form of an empty tuna-fish can, set on a table with a flat-side down and then sliced from above through its center into two D-shaped pieces. The two "Dees"...
-
A nice feature of the cyclotron described in the preceding problem is that the alternating current frequency applied to the "Dees" is a constant \(\omega=q B / m c\) for nonrelativistic particles,...
-
Consider two inertial frames \(\mathcal{O}\) and \(\mathcal{O}^{\prime}\) where \(\mathcal{O}^{\prime}\) is moving with velocity \(\mathbf{v}\) relative to \(\mathcal{O}\). We split all three-vectors...
Study smarter with the SolutionInn App