// A[1...n] is an array of n elements function fun (A[]) function sum (A[], i) temp...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
// A[1...n] is an array of n elements function fun (A[]) function sum (A[], i) temp [n] 1. Create new array 2. temp [1] A[1] ; k=2; 3. for (i=2; i<n; i++) 4. 5. 6. 7. if (A[i] >= sum (A, 1)) temp [k] =A[i]; k++; return temp [] 1. s= 0 2. for (j-1; j<i; j++) s += A[j] 3. 4. return s 1. [15 points] Consider the algorithm shown above. a) (2 pts) What does the algorithm do? Justify your answer. b) (2 pts) What is the output of the algorithm on input array A = [1, 3, 5, 7, 15, 2, 4, 40, 50, 100]? c) (4 pts) Analyze the algorithm and determine its running time as a function of n. Use the Big-O() notation and consider the behavior of the algorithm on the worst possible input.. d) (7 pts) Come up with a better algorithm for the same problem. For example if your algorithm in part (c) was (say) O(n), you should produce an algorithm that is strictly less than O(n), like O(n) or O(n²), etc... // A[1...n] is an array of n elements function fun (A[]) function sum (A[], i) temp [n] 1. Create new array 2. temp [1] A[1] ; k=2; 3. for (i=2; i<n; i++) 4. 5. 6. 7. if (A[i] >= sum (A, 1)) temp [k] =A[i]; k++; return temp [] 1. s= 0 2. for (j-1; j<i; j++) s += A[j] 3. 4. return s 1. [15 points] Consider the algorithm shown above. a) (2 pts) What does the algorithm do? Justify your answer. b) (2 pts) What is the output of the algorithm on input array A = [1, 3, 5, 7, 15, 2, 4, 40, 50, 100]? c) (4 pts) Analyze the algorithm and determine its running time as a function of n. Use the Big-O() notation and consider the behavior of the algorithm on the worst possible input.. d) (7 pts) Come up with a better algorithm for the same problem. For example if your algorithm in part (c) was (say) O(n), you should produce an algorithm that is strictly less than O(n), like O(n) or O(n²), etc...
Expert Answer:
Answer rating: 100% (QA)
1 Given Algorithm Analysis a What does the algorithm do Explanation The algorithm processes an input array A of n elements and creates a new array tem... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Mylne vient d'achever le dessin du prochain modle de voiture hybride d'une marque automobile. Elle est trs satisfaite du rsultat. Mylne est designer industrielle dans les transports et travaille son...
-
A compare-exchange operation on two array elements A[i] and A[j], where i < j, has the form COMPARE-EXCHANGE (A, i, j) 1 If A[i] > A[j] 2 exchange A[i] with A[j] After the compare-exchange operation,...
-
Emily Jackson (Social Security number 765-12-4326) and James Stewart (Social Security number 466-74-9932) are partners in a partnership that owns and operates a barber shop. The partnership's first...
-
PIM Industries, Inc., manufactures electronics components. Each unit costs $30 before the final test. The final test rejects, on average, 5 percent of the 50,000 units manufactured per year. The...
-
A prototype spillway has a characteristic velocity of 3 m/s and a characteristic length of 10 m. A small model is constructed by using Froude scaling. What is the minimum scale ratio of the model...
-
Home loans typically involve "points," which are fees charged by the lender. Each point charged means that the borrower must pay 1 % of the loan amount as a fee. For example, if the loan is for...
-
What are the advantages of gear drive over other drives?
-
Browning Design Works generated $300,000 in operating income on sales revenue of $2,000,000. The company had $2,200,000 in assets on January 1 and $2,800,000 in assets on December 31. Required a....
-
A charging RC circuit controls the intermittent windshield wipers in a car. The emf is 12.0 V. The wipers are triggered when the voltage across the 120F capacitor reaches 12.0 V; then the capacitor...
-
Grimes Corporation began business in 2017 and incurred losses for its first two years. In 2019, it became profitable. The following table shows Grimess taxable income before consideration of its...
-
public sector hospital wants to automate its manual paper based operations to speed up the operations and facilitate its patients and staff members. For this purpose, they want to develop a database...
-
Calculate the 3x3 determinant: -3 7 8 -7 5 0 -6 2 1 F
-
Make 2000 word essay Research paper of this topic Research Topic: Jenni rivera Point 1: Early life and career Subpoint a: background information on Jenny Rivera's upbringing and family Subpoint b:...
-
How did Brown v. Board of Education change public education? Has the promise of Brown v. Board of Education been realized? Support your position with reference to a current event.
-
Three boxes, A, B, and C, are placed on a frictionless surface as shown in the diagram below. C B A If you push on box A with a force of 8.25 N, find the contact force (in N) between each pair of...
-
Find d'y dx if -2x + 7y4 10.
-
What are the three functional groups in the molecule?
-
Linda Lopez opened a beauty studio, Lindas Salon, on January 2, 2011. The salon also sells beauty supplies. In January 2012, Lopez realized she had never filed any tax reports for her business and...
-
Bea Jones (age 32) moved from Texas to Florida in December 2011. She lives at 654 Ocean Way, Gulfport, FL 33707. Bea's Social Security number is 466-78-7359 and she is single. Her earnings and income...
-
Ray and Maria Gomez have been married 3 years. They live at 1610 Quince Ave., McAllen, TX 78701. Ray works for Palm Oil Corporation and Maria works for the City of McAllen. Maria's Social Security...
-
Yolanda earns $112,000 in 2012. Calculate the FICA tax that must be paid by: Yolanda:.....................Soc.Sec..................$__________...
-
When managers use offers of rewards and threats of punishments to try to get others to do what they want them to do, they are using which type of power? (a) formal authority (b) position (c) referent...
-
In the research on leader behaviors, which style of leadership describes the preferred high-high combination? (a) transformational (b) transactional (c) laissez-faire (d) democratic
-
How is a person with an authoritarian personality expected to act? (a) Strong tendency to obey orders. (b) Challenges the authority of others. (c) Tries to play down status differences. (d) Always...
Study smarter with the SolutionInn App