Unpredictable loop variables. Consider the following function: def func (lst: List[int]) -> None: n = len...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Unpredictable loop variables. Consider the following function: def func (lst: List[int]) -> None: n = len (1st) i = 0 3 4 j = 1 while i < n: if 1st [i] >= 0: i = i + j 6 7 8 else: 1st [i] = abs (1st [i]) 9 i = 0 10 j = j * 2 11 Find, with proof, an input family for func whose running time is O(log n). Find, with proof, an input family for func whose running time is O(n) and for which the else branch (Lines 9-11) executes N(logn) times. To simplify your analysis, you may assume n (the length of the list) is a power of 2." You may use the following formula, valid for all n €N and r E R where r+ 1: n-1 1- rn 1-r i=0 Prove that the worst-case running time for func is O(n). Unpredictable loop variables. Consider the following function: def func (lst: List[int]) -> None: n = len (1st) i = 0 3 4 j = 1 while i < n: if 1st [i] >= 0: i = i + j 6 7 8 else: 1st [i] = abs (1st [i]) 9 i = 0 10 j = j * 2 11 Find, with proof, an input family for func whose running time is O(log n). Find, with proof, an input family for func whose running time is O(n) and for which the else branch (Lines 9-11) executes N(logn) times. To simplify your analysis, you may assume n (the length of the list) is a power of 2." You may use the following formula, valid for all n €N and r E R where r+ 1: n-1 1- rn 1-r i=0 Prove that the worst-case running time for func is O(n).
Expert Answer:
Answer rating: 100% (QA)
Answer Explanation a Guess the input that gives Olog n running time The all integers in the input li... View the full answer
Related Book For
Calculus Early Transcendentals
ISBN: 978-0321947345
2nd edition
Authors: William L. Briggs, Lyle Cochran, Bernard Gillett
Posted Date:
Students also viewed these accounting questions
-
Consider the following function main: Int main() { int inStock[10][4]; int alpha [20]; int beta[20]; int gamma[4]= {11,13,15,17}; int delta [10] = {3,5,2,6,10,9,7,11,1,8}; } a) Write the definition...
-
Consider the following function and its power series: a. Let S n (x) be the sum of the first n terms of the series. With n = 5 and n = 10, graph f(x) and S n (x) at the sample points x = -0.9, -0.8,...
-
Consider the following function f: X R f(x, x) = -9x-10x2+0 [-In(100x-x) - In(x) - ln(x) - In(50 - x + x)] where is a given parameter and X = {(x1, x) x > 0, x > 0, x + x < 100, x1 - x2 < 50}....
-
The following trial balance is taken from the General Fund of the City of Jennings for the year ending December 31, 2017. Prepare a condensed statement of revenues, expenditures, and other changes in...
-
List the three control problems associated with competing processes and briefly define each.
-
Treating the data as samples from larger populations, test the claim that there is a difference between the mean departure delay time for Flight 3 and Flight 21. Refer to the following list of...
-
Consider a bond with a face value of \(\$ 1,000\) and coupon payment at the end of each period \(k\) given by a rate \(c_{k}=\max \left[6 \%-r_{k}, 0 ight]\), where \(r_{k}\) is the short rate for...
-
On January 1, 2017, Phantom Corp. acquires $300,000 of Spider Products, Inc. 9% bonds at a price of $278,384. The interest is payable each December 31, and the bonds mature on December 31, 2019. The...
-
You take a long position in a one-year forward contract on a stock whose price you expect to increase in the future. The current price of the stock is $100 per share. The interest rate is 10%...
-
Prepare a Consolidated Balance Sheet for Big Lake Bakeries which owns 100% of Marble Falls Orchards. The fair value of Marble Falls net fixed assets are $2,675,000. Big Lake aquired 100% of Marble...
-
Which signs point to a diagnosis of Alzheimer's disease? Select all that apply. Diplopia Bradykinesia Mood swings Disorientation Loss of initiative
-
1. You want to build a CRR binomial model to value options on Moderna (MRNA). The current stock price of MRNA is 310.20. Assume the volatility of MRNA is 61.2% (annual) and the risk-free interest...
-
Luis is an instructor at the Harrisonburg Automotive Mechanic School, where he leads the program in charge of automotive technicians. Currently, Luis is trying to arrange for the restoration of a...
-
Jefferson Products, Inc., is considering purchasing a new automatic press brake, which costs $320,000 including installation and shipping. The machine is expected to generate net cash inflows of...
-
Nguyen, Inc. is considering the purchase of a new computer system (ICX) for $150,000. The system will require an additional $20,000 for installation. If the new computer is purchased it will replace...
-
Colonial Furniture Co. uses a standard cost system. One of the company's most popular products is a cherry wood desk. The per-unit standard costs of the desk, assuming a "normal" volume of 2,000...
-
You are a recent graduate of Kwantlen Polytechnic University. For 6 months you have been actively looking for your first full time job post graduation. you are feeling a little discouraged. Your...
-
Define deferred revenue. Why is it a liability?
-
A large building shaped like a box is 50 m high with a face that is 80 m wide. A strong wind blows directly at the face of the building, exerting a pressure of 150 N/m 2 at the ground and increasing...
-
The output of an economic system Q, subject to two inputs, such as labor L and capital K, is often modeled by the Cobb-Douglas production function Q = cL a K b . When a + b = 1, the case is called...
-
Find an equation of the line tangent to the graph of f at the given point. f(x) = sec -1 (e x ); (ln 2, /3)
-
In the second quarter of 2021, personal consumption expenditures, exports, and imports increased. Investment and government expenditure decreased. Real GDP increased by 6.5 percent following a 6.3...
-
When real GDP increased in the second quarter of 2021, consumption expenditure, exports, and imports increased. Fixed investment decreased, which included a decrease in business inventory investment....
-
Are U.S. exports part of U.S. induced expenditure or autonomous expenditure? Are U.S. imports part of U.S. induced expenditure or autonomous expenditure? U.S. imports are recovering thanks to the $2...
Study smarter with the SolutionInn App