// 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 particle moves in a plane under the action of a force which is always perpendicular to the particle's velocity and depends on a distance to a certain point on the plane as 1/m, where n is a...
-
Vicky was an employee during 2 0 2 3 and she received the following income and benefits from her employer: Salaries paid and received in 2 0 2 3 - $ 4 2 , 0 0 0 Bonus declared by her employer on...
-
Use Table 1, or software, to find (a) \(B(8 ; 16,0.40)\); (b) \(b(8 ; 16,0.40)\); (c) \(B(9 ; 12,0.60)\); (d) \(b(9 ; 12,0.60)\); (e) \(\sum_{k=6}^{20} b(k ; 20,0.15)\); (f) \(\sum_{k=6}^{9} b(k ;...
-
Use regression analysis to fit a linear trend model to the data set. a. What is the estimated regression function? b. Interpret the R2 value for your model. c. Prepare a line graph comparing the...
-
Please create social messages for Twitter, Facebook, and Linkedln to promote the following article. Include attributions and hashtags specific to each platform. Make them fun so they stand out and...
-
4. Distinct Items There is a list of items in the shopping cart, each having a cost associated with it. There are n items, the cost of the ith item is / dollars and m items have already been bought...
-
A retail mall with total space of 3.2 million square feet has secured an anchor tenant that has leased 850,000 square feet. In-line tenants will occupy 1.4 million square feet. The balance is common...
-
Gender: Male (1), Female (2) For the (non-music) audio services you have used, what is your satisfaction with the relevance of topics? SiriusXM (4), Spotify (podcasts) (7) Extremely Somewhat Neither...
-
Please answer the tasks below in as much detail as possible and attach all completed evidence to this workbook. Tasks 1-Identify customer preferences (PC1.1, PC1.2, PC2.2, PE1,KE1, KE5, KE6) Identify...
-
For a type-3 Compensated error amplifier (fig.7-28a), determine the k-factor for a Scamp of 185. For a gain of 24dB at a cross-over frequency of 15KHZ, (Let 2 = 1K), determine the values at Ry, C1 g...
-
Fill in the blanks to predict the products.
-
Multisim allows you to put digital logic theory into practice through schematic simulations and deployment to hardware. This software acts as a verification tool to aid your understanding of digital...
-
Convex & Concave MIRROR Worksheet The same object (height = y) is placed at several different distances s to the left of the same mirror (focal length =). For each case, draw the 3 principal rays to...
-
Akramin just graduated with a Master of Engineering in Manufacturing Engineering and landed a new job in Melaka with a starting salary of RM 4,000 per month. There are a number of things that he...
-
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..................$__________...
-
True or False: Benefits and disbenefits must be converted to monetary values to use benefit-cost analysis.
-
Using an Internet-based search on 'build operate transfer," find an additional definition from a source other than used in Section 14.2. Copy and paste it, as well as any graphics, examples,...
-
Elm City is considering a replacement for its police radio. The benefits and costs of the replacement are shown below. What is the replacement's benefit/cost ratio if the effective annual interest...
Study smarter with the SolutionInn App