Give a big-Oh characterization, in terms of n, of the running time of the example1 function shown
Question:
Give a big-Oh characterization, in terms of n, of the running time of the example1 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: 26% (15 reviews)
Consider the number of times ...View the full answer
Answered By
Mugdha Sisodiya
My self Mugdha Sisodiya from Chhattisgarh India. I have completed my Bachelors degree in 2015 and My Master in Commerce degree in 2016. I am having expertise in Management, Cost and Finance Accounts. Further I have completed my Chartered Accountant and working as a Professional.
Since 2012 I am providing home tutions.
3.30+
2+ 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
-
The programming language is Java and all of the Classes I was given are in bold. ALIEN CLASS import imagePackage.RasterImage; import java.awt.BasicStroke; import java.awt.Color; import...
-
What amount will be required to purchase, on a man's 40th birthday, an annuity to provide him with 30 equal semiannual payments of $1000 each, the first to be received on his 50th birthday, if...
-
(a) How long does it take the astronaut in Example 28.2 to travel 4.30 ly at 0.99944c (as measured by the Earth-bound observer)? (b) How long does it take according to the astronaut? (c) Verify that...
-
15-5. Cul es la distincin principal entre un sistema corporativo y otro administrado de marketing vertical?
-
Garrison holds a controlling interest in Robertsons outstanding stock. For the current year, the following information has been gathered about these two companies: Garrison uses the cost method to...
-
Acer's Companies, a home improvement store chain, reported the following summarized figures mix the icon to view the income stament) Click the icon to view the balance sheets) Acce's has 10.000...
-
The following data is available for Crater Corporation?s North American division for the years 2014 and 2015. During these years there were no inventories in the system. Required: 1. Classify the...
-
Show that n log n is (n).
-
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 =...
-
You have recently been hired as the assistant controller for Stanton Industries. Your immediate superior is the controller who, in turn, reports to the vice president of finance. The controller has...
-
The requirement for extended disclosures for oil and gas reserves described in Chapter 2 followed a Congressional hearing on the poor disclosures that Shell Oil had for its reserves. A.Explain three...
-
Question 9 Big Data techniques implemented in the financial sector include: fraud detection O marketing email campaign O customer relationship management techniques O inventory analysis
-
Problem 8-19A Attaining notfonpmt entity variances The Redmond Management Association held its annual public relations luncheon in April Year 2. Based on the previous year's results, the organization...
-
Kay, who is not a real estate dealer, sold an apartment house to Polly during the current year (2020). The closing statement for the sale is as follows. Total selling price $190,000 Add: Polly's...
-
1 English Writing Requirement Assignment Guidelines Sem 1 2023-24 Subject code AAE1D02 Subject title Introduction to Space Exploration Credit value 3 CAR Teachers Prof. WEN Chih-Yung, Prof. WU Bo,...
-
A light string of unknown natural length is fixed to a ceiling at one end, with a mass of 0.4 kg attached to the other end. The string is allowed to hang in equilibrium such that the length of the...
-
If the amplifier indicated by the box input impedance of oo, which of the following statements are true ? has an open loop gain as well as Feedback factor (\beta = 1/ R_1\) The feedback is voltage...
-
Al says he can prove that all sheep in a flock are the same color: Base case: One sheep. It is clearly the same color as itself. Induction step: A flock of n sheep. Take a sheep, a, out. The...
-
Alice has two circular queues,C and D, which can store integers. Bob givesAlice 50 odd integers and 50 even integers and insists that she stores all 100 integers in C and D. They then play a game...
-
Suppose Bob has four cows that he wants to take across a bridge, but only one yoke, which can hold up to two cows, side by side, tied to the yoke. The yoke is too heavy for him to carry across the...
-
Question 24 Not yet answered Marked out of 1.00 P Flag question Muscat LLC's current assets and current liabilities are OMR 258,000 and OMR 192,000, respectively. In the year 2020, the company earned...
-
Question 24 Miami Company sold merchandise for which it received $710,400, including sales and excise taxes. All of the firms sales are subject to a 6% sales tax but only 50% of sales are subject to...
-
f the IRS intends to close a Taxpayer Assistance Center, they must notify the public at least _____ days in advance of the closure date. 14 30 60 90
Study smarter with the SolutionInn App