Give a big-Oh characterization, in terms of n, of the running time of the example3 function shown
Question:
Give a big-Oh characterization, in terms of n, of the running time of the example3 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 the inner ...View the full answer
Answered By
Muhammad Umair
I have done job as Embedded System Engineer for just four months but after it i have decided to open my own lab and to work on projects that i can launch my own product in market. I work on different softwares like Proteus, Mikroc to program Embedded Systems. My basic work is on Embedded Systems. I have skills in Autocad, Proteus, C++, C programming and i love to share these skills to other to enhance my knowledge too.
3.50+
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
-
In a recent survey, 80% of the community favored building a police substation in their neighborhood. If 20 citizens are chosen, what is the mean and standard deviation for the number favoring the...
-
What interest rate, compounded quarterly, is equivalent to a 9.31% effective interest rate?
-
To save money on making military aircraft invisible to radar, an inventor decides to coat them with a non-reflective material having an index of refraction of 1.20, which is between that of air and...
-
15-7. Cules son los tres grados de densidad de distribucin?
-
Several FASB and EITF pronouncements dealt with accounting for extraordinary items. Search the FASB ASC database to identify all of the FASB and EITF pronouncements dealing with extraordinary items...
-
Acored Litter Thordinate to owing that require adjusting entries at the end of the year Therwood pays payroll of $100.000 every other day for a work period. This year the last paris Priday, December...
-
How do you feel about having management responsibilities in today's world, characterized by uncertainty, ambiguity, and sudden changes or threats from the environment? Describe some skills and...
-
Give a big-Oh characterization, in terms of n, of the running time of the example 2 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 example4 function shown in Code Fragment 3.10. 1 def example1(S): "Return the sum of the elements in sequence S.""" n =...
-
On June 5, 2015, Brown, Inc., a calendar year taxpayer, receives cash of $750,000 from the county upon condemnation of its warehouse building (adjusted basis of $500,000 and fair market value of...
-
Find the best predicted tip for a ride that is 3.10 miles. How does the result compare to the actual tip of $4.55? Find the best predicted fare amount for a distance of 3.10 miles. How does the...
-
Since the SUTA rates changes are made at the end of each year, the available 2022 rates were used for FUTA and SUTA. Note: For this textbook edition the rate 0.6% was used for the net FUTA tax rate...
-
I have asked three questions with my textbook chapter in which they come from. it would be greatly appreciated if you could help me answer these three questions. Thanks so much. :) 1. What is the...
-
From your reading in Stevens & Smith (2010), a basic description of a medical detoxification, dual-diagnosis inpatient hospital, independent rehab programs, partial hospitalization, halfway houses,...
-
A particle of mass 2 kg is attached to one end of a light elastic string of natural length 1.5m and modulus of elasticity 50N. The other end of the string is attached to a fixed ceiling and the...
-
A seasonal index may be less than one, equal to one, or greater than one. Explain what each of these values would mean.
-
Suppose that we have made kn total accesses to the elements in a list L of n elements, for some integer k 1. What are the minimum and maximum number of elements that have been accessed fewer than k...
-
Given the set of element {a,b,c,d,e, f } stored in a list, show the final state of the list, assuming we use the move-to-front heuristic and access the elements according to the following sequence:...
-
The java.util.Collection interface includes a method, clear( ), that removes all elements from a collection. Implement such a method in the ArrayList class of Section 7.2.
-
On April 1, year 1, Mary borrowed $200,000 to refinance the original mortgage on her principal residence. Mary paid 3 points to reduce her interest rate from 6 percent to 5 percent. The loan is for a...
-
Give a numerical example of: A) Current liabilities. B) Long-term liabilities?
-
Question Wonder Works Pte Ltd ( ' WW ' ) produces ceramic hair curlers to sell to department stores. The production equipment costs WW $ 7 0 , 0 0 0 four years ago. Currently, the net book value...
Study smarter with the SolutionInn App