There are multiples parts to this question. Be sure to clearly indicate your answer for each...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
There are multiples parts to this question. Be sure to clearly indicate your answer for each part. Consider this program and its specification. # Pre: n, p, s are integers; 2 < p < n; p is a prime number; In mod p != 0; 0 <= S <= n. # Post: Return 'happy'. Bounce (n, p,s): X = S; 1. d = 1; 2. while x > 0: 3. X = X + d 4. 5. if x > n: if x < 0: 0: 6. if m == 7. else: * m = s mod p р * -1 d; -1 * d; return 'happy' d = d = return 'sad' X = n - (x - n); m = x mod p X = -1 * X; m = X Part (a): Briefly explain why the loop iterates fewer than 2n times if it terminates. A rigorous proof is not expected. You just need to show appropriate insight. Part (b): Give an appropriate loop invariant for proving that Bounce is partially correct. Be careful here. Your answer to part (c) relies on a correct answer to part (b). Part (c): Use your loop invariant from part (b) to prove that Bounce is partially correct. There are multiples parts to this question. Be sure to clearly indicate your answer for each part. Consider this program and its specification. # Pre: n, p, s are integers; 2 < p < n; p is a prime number; In mod p != 0; 0 <= S <= n. # Post: Return 'happy'. Bounce (n, p,s): X = S; 1. d = 1; 2. while x > 0: 3. X = X + d 4. 5. if x > n: if x < 0: 0: 6. if m == 7. else: * m = s mod p р * -1 d; -1 * d; return 'happy' d = d = return 'sad' X = n - (x - n); m = x mod p X = -1 * X; m = X Part (a): Briefly explain why the loop iterates fewer than 2n times if it terminates. A rigorous proof is not expected. You just need to show appropriate insight. Part (b): Give an appropriate loop invariant for proving that Bounce is partially correct. Be careful here. Your answer to part (c) relies on a correct answer to part (b). Part (c): Use your loop invariant from part (b) to prove that Bounce is partially correct.
Expert Answer:
Answer rating: 100% (QA)
Part a The loop iterates fewer than 2n times because the value of x increases or decreases by at lea... 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 programming questions
-
1. Aris and Amy, a married couple, have decided that they would like to turn their hobby into a business venture. They are keen gardeners and have begun to make floral displays and arrangements for...
-
Task 1 Blake County had the following agreements in 20X9. You have been asked to advise on the accounting treatment for each of these agreements. In the space provided, indicate whether each of these...
-
Using the SEDAR database, find the most recent annual reports for two Canadian retailers (e.g., Loblaw, Rona, Danier Leather). Required: a. Based on the information provided in the companies audited...
-
Molten salt is used in an electro-refiner to treat nuclear fuel waste. Eventually, the salt needs to be purified (for reuse) or disposed of. A promising method of purification involves oxidation....
-
On January 2, 2011, Phillips Company purchased 80% of Sanchez Company and 90% of Thomas Company for $225,000 and $168,000, respectively. Immediately before the acquisitions, the balance sheets of the...
-
Suppose that, as in the corn farm example, the farm has random production and the final spot price is governed by the same demand function. However, the crop of the farm is not perfectly correlated...
-
Two couples act on the beam as shown. Determine the magnitude of F so that the resultant couple moment is M counterclockwise. Where on the beam does the resultant couple act? Given: M = 300 lb⋅...
-
I. TITLE: TEMPERATURE MEASUREMENT II. OBJECTIVES This simple experiment on temperature measurement is aimed to compare and explain the measured temperature data from the standard temperatures of...
-
Complete the missing amounts in the following production report. Materials are added at the beginning of the process; conversion costs are incurred evenly; the ending inventory is 60% complete. The...
-
You have been assigned the task of evaluating consumer acceptance of and favorability toward a new product that a company has just test marketed in your area. In order to determine the degree to...
-
What is the name of the compound with the formula Sr 3 (PO 4 )2?
-
An ocean wave is cyan. What color(s) of light does it absorb? What colors does it reflect?
-
State whether each of the following is an example of a physical or chemical property of matter: (a) Graphite conducts electricity. (b) Bismuth, Bi, loses its iridescence upon melting. (c) A copper...
-
If \(n_{1}=31, s_{1}=12, n_{2}=51\), and \(s_{2}=10\), test whether \(\sigma_{1}>\sigma_{2}\) at the \(\alpha=0.05\) level of significance. Perform the appropriate hypothesis test.
-
Define the wavelength of sound in terms of successive compressions of air.
-
Knowledge Networking, Inc., is a growing business of high-tech electronics equipment and software. It is a specialty retail and online business that has tripled its revenues in the past seven years....
-
Identify the Critical Infrastructure Physical Protection System Plan.
-
Fisafolia Corporation has gross income from operations of $220,000 and operating expenses of $160,000 for 2012. The corporation also has $20,000 in dividends from publicly traded domestic...
-
William sold Section 1245 property for $25,000 in 2012. The property cost $35,000 when it was purchased 5 years ago. The depreciation claimed on the property was $16,000. a. Calculate the adjusted...
-
Your supervisor has asked you to research the following situation concerning Owen and Lisa Cordoncillo. Owen and Lisa are brother and sister. In May 2012, Owen and Lisa exchange business pickup...
-
Organization is viewed as a/an ________ process and a management activity, which is crucial for predicting the consumption of a companys resources. Active Passive Intermediary None of the above
-
A narrow span of control does not aid better communication between the superior and the subordinates. True False
-
The ________ networks are usually temporary in nature. Line-and-staff organization Network organizational Virtual organization Tall organizational
Study smarter with the SolutionInn App