Give a big-Oh characterization, in terms of n, of the running time of the example 2 function
Question:
Give a big-Oh characterization, in terms of n, of the running time of the example 2 function shown in Code Fragment 3.10.
Transcribed Image Text:
1 def example1(S): "Return the sum of the elements in sequence S.""" n = len(S) total = 0 2 3 4 for j in range(n): total += S[j] # loop from 0 to n-1 5 6. return total 9 def example2(S): "Return the sum of the elements with even index in sequence S.""" n = len(S) total = 0 for j in range(0, n, 2): total += S[j] 10 11 12 # note the increment of 2 13 14 15 return total 16 def example3(S): """ Return the sum of the prefix sums of sequence S."" n = len(S) 17 1111 18 19 total = 0 20 for j in range(n): for k in range(1+j): total += S[k] # loop from 0 to n-1 # loop from 0 to j 21 22 23 24 return total 25 26 def example4(S): """Return the sum of the prefix sums of sequence S.""" n = len(S) prefix = 0 total = 0 27 28 29 30 for j in range(n): prefix += S[j] total += prefix 31 32 33 return total 34 35 36 def example5(A, B): """Return the number of elements in B equal to the sum of prefix sums in A.' n = len(A) # assume that A and B have equal length 37 38 39 count = 0 for i in range(n): total = 0 # loop from 0 to n-1 40 41 for j in range(n): for k in range(1+j): total += A[k] if B[i) == total: count += 1 # loop from 0 to n-1 # loop from 0 to j 42 43 44 45 %3D3%3= 46 47 return count Code Fragment 3.10: Some sample algorithms for analysis.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 57% (14 reviews)
Consider the number of times ...View the full answer
Answered By
Subash Murugaih
I am leading expert in this web site couple of years and My clients are much happy with my works and services.
4.60+
309+ Reviews
539+ Question Solved
Related Book For
Data Structures and Algorithms in Python
ISBN: 978-1118290279
1st edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Question Posted:
Students also viewed these Computer science questions
-
Find an expression, in terms of n and the fundamental constants, for the de Broglie wavelength of an electron in the nth state of the hydrogen atom.
-
Give an example of each type of function. (a) Linear function (b) Power function (c) Exponential function (d) Quadratic function (e) Polynomial of degree 5 (f) Rational function
-
Give an example of a Code provision with limiting language other than For purposes of this Section. How does the limitation affect the application of the provision you found?
-
Steven Stores, Inc. provided the following statement of net income for the current year. All income is subject to a 40% income tax rate. The company also had $ 735 of unrealized holding gains on its...
-
A contractor wishes to set up a special fund by making uniform semiannual end-of-period deposits for 20 years. The fund is to provide $10,000 at the enc of each of the last 5 years of the 20-year...
-
What angle is needed between the direction of polarized light and the axis of a polarizing filter to cut its intensity in half?
-
15-6. Cules son las tres preguntas que consideran los directivos de marketing en la eleccin de un canal de marketing y de los intermediarios ?
-
In Figure a sled is held on an inclined plane by a cord pulling directly up the plane. The sled is to be on the verge of moving up the plane. In Fig. 6-34, the magnitude F required of the cord's...
-
6. A candlestick chart is similar to a bar chart except that the candlestick chart: A. Represents upward movements in price with Xs. B. Also graphically shows the range of the periods highs and lows....
-
Aubrae and Tylor Williamson began operations of their furniture repair shop (Furniture Refinishers, Inc.) on January 1, 2019. The annual reporting period ends December 31. The trial balance on...
-
Give a big-Oh characterization, in terms of n, of the running time of the example1 function shown in Code Fragment 3.10. 1 def example1(S): "Return the sum of the elements in sequence S.""" n =...
-
Give a big-Oh characterization, in terms of n, of the running time of the example3 function shown in Code Fragment 3.10. 1 def example1(S): "Return the sum of the elements in sequence S.""" n =...
-
If MS bet = 500 and F is 2.00, what is MS with ?
-
Alec is an employee who drives a 2021 Ford C-Max with a fair-market value of $32,000. He has been given the choice to have the fringe benefit reported on his W-2 either using the lease-value rule or...
-
What resource do most thinking and learning technologies rely on to be effective? a) data b) images c) gas d) robots
-
Financial Reporting Problem Marks and Spencer plc (M&S) The financial statements of M&S (GBR) are presented in Appendix A. The companys complete annual report, including the notes to the...
-
Totally Chemical is considering an investment decision project in which the organization expands into the trucking business. Totally Chemical wants to begin this investment decision project by buying...
-
Presented below is the balance sheet of Sandhill Corporation as of December 31, 2017. SANDHILL CORPORATION BALANCE SHEET DECEMBER 31, 2017 Goodwill (Note 2) Buildings (Note 1) Inventory Land Accounts...
-
Prove, using integration, that the elastic potential energy stored in a string of natural length land modulus of is elasticity is x 2 /2I, where x is the extension of the string.
-
Select a mass spectrometric technique with the highest mass resolution for identifying an unknown compound being eluted from a liquid chromatography column
-
Modify our ArrayList implementation to support the Cloneable interface, as described in Section 3.6.
-
Give an array-based list implementation, with fixed capacity, treating the array circularly so that it achieves O(1) time for insertions and removals at index 0, as well as insertions and removals at...
-
Implement a resetCounts( ) method for the FavoritesList class that resets all elements access counts to zero (while leaving the order of the list unchanged).
-
A company is evaluating a new 4-year project. The equipment necessary for the project will cost $3,300,000 and can be sold for $650,000 at the end of the project. The asset is in the 5-year MACRS...
-
You have just been hired as a new management trainee by Earrings Unlimited, a distributor of earrings to various retail outlets located in shopping malls across the country. In the past, the company...
-
I need to see where the calculations for this problem come from plz. 5. Award: 4.00 points Lucido Products markets two computer games: Claimjumper and Makeover. A contribution format income statement...
Study smarter with the SolutionInn App