Give a big-Oh characterization, in terms of n, of the running time of the example4 function shown
Question:
Give a big-Oh characterization, in terms of n, of the running time of the example4 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% (7 reviews)
Consider the number of times the inner ...View the full answer
Answered By
Joemar Canciller
I teach mathematics to students because I love to share what I have in this field.
I also want to see the students to love math and be fearless in this field.
I've been tutoring these past 2 years and I would like to continue what I've been doing.
5.00+
1+ Reviews
10+ 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.
-
A fragment of the source code for a Binary Search Tree (BST) in JavaScript is given down below: class Node { constructor(val){ this.val = val this.left = null this.right = null } } class BST {...
-
Give the m/z values of the fragment ions expected from b - type fragmentation of an M + 1 ion of the peptide N - F - E - S - G - K
-
1- The z-axis carries filamentary current of 10. A. Find Hat (-3,74,0) ? p= = = 2- The Y-axis carries filamentary current of 10 A. Find H at (-3,4,1) ? p= ,= = p= , = H p= 3- The X-axis carries...
-
Use a 15% interest rate to compute the value of P is the diagram. 50 7080
-
Repeat Exercise 27.70, but take the light to be incident at a 45 angle. Data from Exercise 27.70 A soap bubble is 100 nm thick and illuminated by white light incident perpendicular to its surface....
-
15-8. Qu significa distribucin exclusiva?
-
Refer to the preceding facts for Postmans acquisition of 80% of Spartans common stock and the bond transactions. Postman uses the simple equity method to account for its investment in Spartan. On...
-
Question 6 (2 points) Marlow Company purchased a point of sale system on January 1 for $3,400. This system has a useful life of 10 years and a salvage value of $400. What would be the book value of...
-
Lyons document storages controller, eric petro, told rene that the bonds were issued in 1999 at a discount and that only approximately $9.1 million was received in cash. Explain what is meant by the...
-
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 =...
-
Give a big-Oh characterization, in terms of n, of the running time of the example 5 function shown in Code Fragment 3.10. 1 def example1(S): "Return the sum of the elements in sequence S.""" n =...
-
Highland Corporation, a private corporation, was organized on January 1, 2024. It is authorized to issue 50,000, $3 noncumulative preferred shares, and an unlimited number of common shares. The...
-
Description: duff owes relatives $13,000 for college loans. find the required quarterly payment into a sinking fund if duff pays off the loan in 3 years and the interest rate is 8% per year...
-
1 3 , 9 5 0 ) Repairs and Maintenance ( $ 2 , 8 5 0 ) Utilities Expense ( $ 8 8 0 ) Operating Income $ 1 0 , 2 4 2 Other Income - Gain on Sale $ 3 0 0 Interest Expense ( $ 2 5 0 ) Earnings Before...
-
Description: The company currently has outstanding a bond with a 5.5 percent coupon rate and another bond with a 3.5 percent coupon rate. The firm has been informed by its investment banker that...
-
Find the equation of line joining the points (4, -3) and (-2, 7).
-
Calculate the work of reversible expansion of 1 mole of ideal gas at 25 degree celsius from 10 L to 20 L.
-
A particle P of mass 0.35 kg is attached to the mid-point of a light elastic string of natural length 4 m. The ends of the string are attached to fixed points A and .8 which are 4.8m apart at the...
-
Determine the reactions in supports A and D and connections B and C. Sketch its shear and moment diagram and determine the magnitude ankoration of the maximum shear and moment for every member. 18 3...
-
The java.util.Collection interface includes a method, contains(o), that returns true if the collection contains any object that equals Object o. Implement such a method in the ArrayList class of...
-
Describe a fast recursive algorithm for reversing a singly linked list L, so that the ordering of the nodes becomes opposite of what it was before.
-
Communication security is extremely important in computer networks, and one way many network protocols achieve security is to encrypt messages. Typical cryptographic schemes for the secure...
-
The payroll register of Ruggerio Co. indicates $13,800 of social security withheld and $3,450 of Medicare tax withheld on total salaries of $230,000 for the period. Federal withholding for the period...
-
All of the following are included on Form 1040, page 1, EXCEPT: The determination of filing status. The Presidential Election Campaign check box. The income section. The paid preparer signature line.
-
Question One: (25 marks) (X) Inc. purchased 80% of the outstanding voting shares of (Y) for $360,000 on July 1, 2017. On that date, (Y) had common shares and retained earnings worth $180,000 and...
Study smarter with the SolutionInn App