The following is a pseudocode algorithm for a recursive function that returns the factorial of a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The following is a pseudocode algorithm for a recursive function that returns the factorial of a non-negative integer n. The algorithm works for most input but is missing out on one edge case. FUNCTION Factorial (n) if n = 1 else result 1 result = n* Factorial (n-1) Task 2.1 Write program code for this algorithm including the amendment you would make to: make the function works for all cases adhere to good programming style Verify that your program works by testing it for suitable values of n<=100. Evidence 7: Your program code. Evidence 8: Two screenshots showing the output from running the program code for n=0) and n=50. Task 2.2 While concise and elegant, recursive functions are more computationally resource intensive, and break down when the input size is large (e.g. when n=1000 for the above recursive factorial function). To improve its efficiency and ability to handle large input sizes, convert the recursive factorial function into an iterative one. Evidence 9: Your converted program code. Evidence 10: One screenshot showing the output from running the program code for n=1000. The following is a pseudocode algorithm for a recursive function that returns the factorial of a non-negative integer n. The algorithm works for most input but is missing out on one edge case. FUNCTION Factorial (n) if n = 1 else result 1 result = n* Factorial (n-1) Task 2.1 Write program code for this algorithm including the amendment you would make to: make the function works for all cases adhere to good programming style Verify that your program works by testing it for suitable values of n<=100. Evidence 7: Your program code. Evidence 8: Two screenshots showing the output from running the program code for n=0) and n=50. Task 2.2 While concise and elegant, recursive functions are more computationally resource intensive, and break down when the input size is large (e.g. when n=1000 for the above recursive factorial function). To improve its efficiency and ability to handle large input sizes, convert the recursive factorial function into an iterative one. Evidence 9: Your converted program code. Evidence 10: One screenshot showing the output from running the program code for n=1000.
Expert Answer:
Answer rating: 100% (QA)
Task 21 Recursive Factorial Function Heres the modified program ... View the full answer
Related Book For
Auditing a risk based approach to conducting a quality audit
ISBN: 978-1133939153
9th edition
Authors: Karla Johnstone, Audrey Gramling, Larry Rittenberg
Posted Date:
Students also viewed these databases questions
-
What are the key design considerations when implementing a hybrid separation process (e.g., combining membrane separation with distillation) to improve energy efficiency in a chemical manufacturing...
-
KYC's stock price can go up by 15 percent every year, or down by 10 percent. Both outcomes are equally likely. The risk free rate is 5 percent, and the current stock price of KYC is 100. (a) Price a...
-
1. Suppose India follows China and accelerates its industrialization. For India, this will: A. Decrease imports and raise net exports B. Increase imports and lower net exports C. Increase imports and...
-
1. Develop a forecasting model, justify its selection over other techniques, and project attendance through 2015. 2. What revenues are to be expected in 2014 and 2015? 3. Discuss the school's...
-
Sketch the bonding molecular orbital that results from the linear combination of two 1s orbitals. Indicate the region where interference occurs and state the kind of interference (constructive or...
-
Assuming that the necessary assumptions are met, construct a 95\% confidence interval for \(ho\) when (a) \(r=0.78\) and \(n=15\); (b) \(r=-0.62\) and \(n=32\); (c) \(r=0.17\) and \(n=35\).
-
Assume M. Crue opened a store in San Francisco, starting with cash and common stock of $104,000. Sharon Saboda, the store manager, then signed a note payable to purchase land for $95,000 and a...
-
Given that 57.7 fex is equal to 1 gal and that 14.3 glo is equal to 1 day, how many cL/hr are there in 0.568 fex/glo? ( NOTE: A fex and glo are are both fictitious units of volume and time,...
-
In 1913, how long did the average worker stay with the plant? What was the average tenure of a worker? Assume the one-millionth vehicle was produced in 1916 at a cost of $8084 (in 2013 US$). By how...
-
An element with molar mass 2.7 x 10 kg mol'forms a cubic unit cell with edge length 405 pm. If its density is 2.7 x 103 kg m, what is the nature of the cubic unit cell?
-
5) It costs a company c(x) = -0.004x2 + 500x + 50000 to make its product. Find the marginal cost and use it to find how fast the cost is increasing when x = 2000 units. (4 points)
-
1. Place 0.5 g of well-powdered 3-nitrobenzoic acid and a stirring bar into a 10 mL round bottom flask. (The powdering is best done with a 25 mL Erlenmeyer and smooth surfaced weighing paper.) 2....
-
Identify and define at least one ethical framework that the company, Equifax, apparently employed in making its decision in that ethical dilemma. This is during the time that Equifax had a data...
-
An ideal gas initially at 325 K undergoes an isobaric expansion at 2.50 kPa. The volume increases from 1.00 m to 3.00 m and 12.0 kJ is transferred to the gas by heat. (a) What is the change in...
-
Bonus: What is the minimum height you would have to place a solid ball of mass M and radius R (I = 2MR2 / 5) on a hill in order for the ball to make it completely around a circular loop at the bottom...
-
Horton Manufacturing Incorporated produces blinds and other window treatments for residential homes and offices. The owner is concerned about the maintenance costs for the production machinery...
-
Can partitioned join be used for r r.A s? Explain your answer
-
During the course of auditing year-end financial statements, the auditor becomes aware of misstatements in a company's financial statements. When combined, the misstatements result in a 4%...
-
Describe the forces that continue to cause audit firms to experience high rates of litigation.
-
Locate and read the article listed below and answer the following questions. Johnstone, K. 2000. Client-Acceptance Decisions: Simultaneous Effects of Client Business Risk, Audit Risk, Auditor...
-
Refer to Exercise 7.12. (a) Obtain the maximum likelihood estimates of \(\mu\) and \(\sigma\). (b) Find the maximum likelihood of the probability that the next run will have a production greater than...
-
A statistical test of hypotheses includes the step of setting a maximum for the probability of falsely rejecting the null hypothesis. Engineers make many measurements on critical bridge components to...
-
A manufacturer wants to establish that the mean life of a gear when used in a crusher is over 55 days. The data will consist of how long gears in 80 different crushers have lasted. (a) Formulate the...
Study smarter with the SolutionInn App