For each of the following three code snippets (corresponding Python code is list in the Appendix...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For each of the following three code snippets (corresponding Python code is list in the Appendix at the end of this assignment): Calculate the theoretical time complexity by counting the number of subtractions as basic operation. What do you think is the Big-Oh for the complexity? Prove how did you get the big-Oh only for Code Snippet 1. b. Plot a graph of the theoretical time complexity. c. Implement the code in the language of your choice, and find the running time for several values of n (for а. instance, for n= 1000, 2000, 3000...10000) and plot the results. (make sure not to have other applications running in the background. You can use different values for n as you see fit). Submit the full code as an appendix to your assignment. d. Using the two plotted graphs, comment on the growth rate of the theoretical time complexity in comparison with the actual running times. Code Snippet 1. NegativeSum for (i = 1; i <= n; i++) 0; NegativeSum NegativeSum i; www ma m w m mam Part Snippet 2. Negative3Sum 0; for (i = 1; i <= 3*n; i++) Negative3Sum Negative3Sum Part Snippet 3. NegativeSubSum for (i = 1; i <= n; i++) for (j = 1; j<= i; itt) 0; NegativeSubSum NegativeSubSum - j; Appendix A (Python code for the code snippets in Question I) 1. Code Snippet 1 NegativeSum for i in range (1, n+1): NegativeSum = NegativeSum i 2. Code Snippet 2 Negative3Sum for i in range (1, (n*3)+1): Negative3Sum Negative3Sum i 3. Code Snippet 3 NegativeSubSum for i in range (1, n+1): for j in range (1, i+l): NegativeSubSum = NegativeSubSum - j For each of the following three code snippets (corresponding Python code is list in the Appendix at the end of this assignment): Calculate the theoretical time complexity by counting the number of subtractions as basic operation. What do you think is the Big-Oh for the complexity? Prove how did you get the big-Oh only for Code Snippet 1. b. Plot a graph of the theoretical time complexity. c. Implement the code in the language of your choice, and find the running time for several values of n (for а. instance, for n= 1000, 2000, 3000...10000) and plot the results. (make sure not to have other applications running in the background. You can use different values for n as you see fit). Submit the full code as an appendix to your assignment. d. Using the two plotted graphs, comment on the growth rate of the theoretical time complexity in comparison with the actual running times. Code Snippet 1. NegativeSum for (i = 1; i <= n; i++) 0; NegativeSum NegativeSum i; www ma m w m mam Part Snippet 2. Negative3Sum 0; for (i = 1; i <= 3*n; i++) Negative3Sum Negative3Sum Part Snippet 3. NegativeSubSum for (i = 1; i <= n; i++) for (j = 1; j<= i; itt) 0; NegativeSubSum NegativeSubSum - j; Appendix A (Python code for the code snippets in Question I) 1. Code Snippet 1 NegativeSum for i in range (1, n+1): NegativeSum = NegativeSum i 2. Code Snippet 2 Negative3Sum for i in range (1, (n*3)+1): Negative3Sum Negative3Sum i 3. Code Snippet 3 NegativeSubSum for i in range (1, n+1): for j in range (1, i+l): NegativeSubSum = NegativeSubSum - j
Expert Answer:
Related Book For
Fundamental Accounting Principles
ISBN: 978-0077862275
22nd edition
Authors: John Wild, Ken Shaw, Barbara Chiappetta
Posted Date:
Students also viewed these algorithms questions
-
Calculate the theoretical time complexity by counting the number of subtractions as a basic operation. What do you think is the Big-Oh for the complexity?
-
For each of the following three separate cases X, Y and Z, compute cash flows from operations using the indirect method. The list includes all balance sheet accounts related to cash from operating...
-
For each of the following three businesses, which costing method would better reflect the businesss economic reality? a. Art dealer b. Automobile manufacturer c. Specialty liquor store
-
Which set of parametric equations is shown in the graph below? Explain your reasoning. (a) (b) x = t y = f
-
What is a recognition lag, and why is it a challenge for monetary policy?
-
A ventilation system has been designed for a large laboratory with a volume of 1100 m3. The volumetric flow rate of ventilation air is 700 m3/min at 22C and 1 atm. (The latter two values may also be...
-
What does argv provide to our program?
-
The Clampett Oil Company has a tanker truck that it uses to deliver fuel to customers. The tanker has five different storage compartments with capacities to hold 2,500, 2,000, 1,500, 1,800 and 2,300...
-
(1) Write a MATLAB script to find area using the Simpson's 3/8 rule. The code should perform all checks on the number of data points required for application of the rule assuming equally spaced data....
-
As the volunteer business manager for the New City Band (City Band), you are responsible for preparing the operating budget for the organizations upcoming summer concert season. Each year, City Band...
-
(24) Consider an experiment where we collect N = 106 molecules of a gas in closed container. The probability a gas molecule is on the left or right side of the container is modeled by a Bernoulli...
-
1. Global climate change (driven by global warming and greenhouse gas emissions) is an especially vexing problem for states to solve. Identify and explain three reasons why this problem is so hard...
-
The diameter of an undirected unweighted graph G, denoted by diam (G), is the maximum distance between any pair of nodes in G. Equivalently, it is the longest of the shortest paths between all pairs...
-
5.4 Describe briefly two advantages and two disadvantages of a corporate form of business organization as compared to a partnership. 5.5 Jack Flubber, who owns Sons of Flubber Construction Co., and...
-
Think about taxes and how they are used to control market performance during an inflationary gap (taxes increase) and recessionary gap (taxes decrease). How can monetary policy work against (counter)...
-
A 12-in-diameter distribution line will operate at a working pressure of 100 lb/in2. Average depth of cover will be 5.0 ft under a paved roadway. The native soil is sand. Using standard AWWA design...
-
Match 1 - ADR 2- IFRS 3- FRN 4- GDR 5- ETF 6- DCF 7- GAAP A) Any of a variety of equity valuation models build around future streams of cash taken back to the present value. B) Accounting standard...
-
Halley's comet travels in an ellipti- cal orbit with a = 17.95 and b = 4.44 and passes by Earth roughly every 76 years. Note that each unit represents one astronomical unit, or 93 million miles. The...
-
Using the data in situation a of Exercise, prepare the employers September 30 journal entries to record salary expense and its related payroll liabilities for this employee. The employees federal...
-
Identify the following as either an advantage (A) or a disadvantage (D) of bond financing. a. Bonds do not affect owner control. b. A company earns a lower return with borrowed funds than it pays in...
-
BOGO Inc. has two sequential processing departments, roasting and mixing. At the beginning of the month, the roasting department has 2,000 units in inventory, 70% complete as to materials. During the...
-
John bought 1,000 shares of Intel stock on October 18, 2015, for $30 per share plus a $750 commission he paid to his broker. On December 12, 2019, he sells the shares for $42.50 per share. He also...
-
Laura Li, a U.S. resident, worked for three months this summer in China. What type of tax authority may be especially useful in determining the tax consequences of her foreign income?
-
Aishwaryas husband passed away in 2018. She needs to determine whether Jasmine, her 17-year-old stepdaughter, who is single, qualifies as her dependent in 2019. Jasmine is a resident but not a...
Study smarter with the SolutionInn App