Precondition: L is a nonempty list of integers. Postcondition: Return the indices a and b that...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Precondition: L is a nonempty list of integers. Postcondition: Return the indices a and b that give the longest strictly increasing sublist 1[a:b] of L. maxSublist (L): 1. a = 0; current = 0; i = 1; max = 1 2. while i < len (L): 3. 4. 5. 6. 7. 8. i=i+ 1 9. return a, a + max if L[i-1] < L[i]: if (i+1) current > max: max = (i+1) current; a = current else: current i (a) (3 marks) Find an appropriate LI for this program. (b) (10 marks) Use your LI to prove partial correctness for this program. (c) (2 marks) Find a decreasing sequence of natural numbers e that will show that this program terminates. Precondition: L is a nonempty list of integers. Postcondition: Return the indices a and b that give the longest strictly increasing sublist 1[a:b] of L. maxSublist (L): 1. a = 0; current = 0; i = 1; max = 1 2. while i < len (L): 3. 4. 5. 6. 7. 8. i=i+ 1 9. return a, a + max if L[i-1] < L[i]: if (i+1) current > max: max = (i+1) current; a = current else: current i (a) (3 marks) Find an appropriate LI for this program. (b) (10 marks) Use your LI to prove partial correctness for this program. (c) (2 marks) Find a decreasing sequence of natural numbers e that will show that this program terminates.
Expert Answer:
Answer rating: 100% (QA)
a Loop Invariant LI At the start of each iteration of the while loop in lines 28 the variables current i max and a satisfy the following conditions 1 ... 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
-
( a * | b * ) * ( ( \ epsi | a ) | b * ) * ( a | b ) * abb ( a | b ) *
-
answer all questions as instructed below. make sure you have attended all questions .Comparative Architectures (a) Describe the organisation of a two-level branch predictor that makes use of a global...
-
Write an alternative definition that is tail-recursive (iterative) and makes use of accumulator variables. [10 marks] Explain why your alternative definition executes more efficiently. [3 marks] 1...
-
Find the area under one arch of the cycloid x = a(t - sin t), y = a(1 - cos t).
-
Two first-order spectrum lines are measured by a 9650-slit/cm spectroscope at angles, on each side of center, of +26o38', +41 o 03' and -26 o 18', -41 o 27'. Calculate the wavelengths based on these...
-
Why is the handling of troubled debt restructuring under SFAS No. 114 illogical?
-
Assume the following information: Given this information, what would be the yield (percentage return) to a U.S. investor who used covered interest arbitrage? (Assume the investor invests $1 million.)...
-
In March 2011, an explosion occurred at Kirk Co.'s plant, causing damage to area properties. By May 2011, no claims had yet been asserted against Kirk. Kirk's management and legal counsel, however,...
-
Find the measure of the marked angles. (4x+41) (7x+8)
-
Wolfe Industries pays its employees on a semimonthly basis. Using the wagebracket tables in Appendix C, compute the federal income tax deductions for the following employees of Wolfe Industries. No...
-
Balance at the end of the financial year: 28 February 2022. Vehicles R600 000 Accumulated depreciation R250 000. Adjustment: Depreciation is calculated at 10% on cost. An old vehicle was disposed on...
-
Analyze the the code and find the line or lines that will be executed the greatest number of times. 1 int function(int a, int j){ 2 12345 int prefix_sum = 0 while (j) { int i = 0; while i
-
How do matrix organizational structures integrate cross-functional collaboration and manage the complexities inherent in dual reporting relationships ?
-
How are the traditional competitors positioned against these market forces? What are their strengths? What are there vulnerabilities?
-
how might distance learning be designed and used to avoid some of the learning and transfer of training problems of the traditional lecture methods?
-
For JP Morgan Chase explain the companies current competitive position in the industry of retail banking. Along with 3 strategic issues the company must address and why they are strategic issues.
-
Digital Organics (DO) has the opportunity to invest $1.22 million now (t= 0) and expects after-tax returns of $690,000 in t=1 and $790,000 in t=2. The project will last for two years only. The...
-
Write electron configurations for the following ions, and determine which have noble-gas configurations: (a) Cd2+ (b) p3- (c) Zr4+ (d) Ru3+ (e) As3- (f) Ag+
-
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._________________________...
-
Skyler is covered by his company's health insurance plan. The health insurance costs his company $3,500 a year. During the year, Skyler is diagnosed with a serious illness and the health insurance...
-
Why are the legal procedures related to mergers so onerous?
-
Where does the creation of value lie in a merger?
-
Alpha AG is wholly owned by Mr Alpha and Beta AG is wholly owned by Mr Beta. The key figures for the two companies are as follows: Alpha acquires Beta. Calculate the shareholdings (as a percentage)...
Study smarter with the SolutionInn App