Give a big-Oh characterization, in terms of n, of the running time of the example 5 function
Question:
Give a big-Oh characterization, in terms of n, of the running time of the example 5 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: 55% (9 reviews)
Consider the number of times the inner ...View the full answer
Answered By
Sheikh Muhammad Ibrahim
During the course of my study, I have worked as a private tutor. I have taught Maths and Physics to O'Level and A'Level students, as well as I have also taught basic engineering courses to my juniors in the university. Engineering intrigues me alot because it a world full of ideas. I have passionately taught students and this made me learn alot. Teaching algebra and basic calculus, from the very basics of it made me very patient. Therefore, I know many tricks to make your work easier for you. I believe that every student has a potential to work himself. I am just here to polish your skills. I am a bright student in my university. My juniors are always happy from me because I help in their assignments and they are never late.
4.90+
14+ Reviews
24+ 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?
-
Gamma Company adjusts its accounts at the end of each month. The following information has been assembled in order to prepare the required adjusting entries at December 31:1. A one-year bank loan of...
-
A student bought a $75 used guitar and agreed to pa: for it with a single $85 payment at the end of 6 months Assuming semiannual (every 6 months) compounding, what is the nominal annual interest...
-
Crystal lattices can be examined with x rays but not UV. Why?
-
15-9. Cul es la diferencia principal entre el canal de marketing y la cadena de suministro ?
-
How important was Ians knowledge of the billing procedures used within the steel industry in his being able to establish his business? Given his cash position when he opened his business, do you...
-
Dr. McMuffin has a medical clinic formed as a corporation that provides specialty care services to patients. The balances in the accounts as of January 1, 2021 are as follows: Cash 70,000 Notes...
-
The cash payments of The Aristocrat's Jewels, a retail business, for June are listed below. The general ledger accounts used to record these transactions appear below. INSTRUCTIONS 1. Open the...
-
Give a big-Oh characterization, in terms of n, of the running time of the example4 function shown in Code Fragment 3.10. 1 def example1(S): "Return the sum of the elements in sequence S.""" n =...
-
Given an n-element sequence S, Algorithm D calls Algorithm E on each element S[i]. Algorithm E runs in O(i) time when it is called on element S[i]. What is the worst-case running time of Algorithm D?
-
Create the amortization schedule for a loan of $15,000, paid monthly over three years using a 9 percent APR.
-
What is current divider rule?Explain with a suitable example.
-
How do we design a Successive Approximation Register using PSPICE software?
-
1.Differentiate between a leader and a manager. 2.Highlight the sources of leadership power. 3.Highlight the styles of leadership and the one which is applicable in a small business. 4.Examine some...
-
A light string is attached to a ceiling at the point A. The natural length of the string is 1.3 m and the string has a mass of 3m attached to the free end. The string is allowed to rest in...
-
Saccharin is an artificial sweetener that is used in diet beverages. In order for it to be metabolized by the body, it must pass into cells. Below are shown the two forms of saccharin. Saccharin has...
-
Consider a deletion operation in an AVL tree that triggers a trinode restructuring for the case in which both children of the node denoted as y have equal heights. Give a schematic figure, in the...
-
Draw the AVL tree resulting from the removal of the entry with key 62 from the AVL tree of Figure 11.13b. 4 62 44 78) 50 88 48 54 T4 T2 (b)
-
Draw the AVL tree resulting from the insertion of an entry with key 52 into the AVL tree of Figure 11.13b. 4 62 44 78) 50 88 48 54 T4 T2 (b)
-
Mass LLp developed software that helps farmers to plow their fiels in a mannyue sthat precvents erosion and maimizes the effoctiveness of irrigation. Suny dale paid a licesnsing fee of $23000 for a...
-
Average Rate of Return The following data are accumulated by Lone Peak Inc. in evaluating two competing capital investment proposals: 3D Printer Truck Amount of investment $40,000 $50,000 Useful life...
-
4. (10 points) Valuation using Income Approach An appraiser appraises a food court and lounge and provides the following assessment: o O The building consists of 2 floors with the following (6)...
Study smarter with the SolutionInn App