Given an integer V > 1 and a list of m distinct integers L[1..m] where L[i]...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given an integer V > 1 and a list of m distinct integers L[1..m] where L[i] <V, for i=1tom and L[m] = 1 Implement the greedy algorithm to represent V as the sum of products using minimum possible number of integers from L as discussed in class. You may use another array R[1..m] to keep track of the intermediate results. Then print the outcome using values from R and L. For instance, given V = 69, m = 5 and L = [14, 8, 6, 5, 1]. Then the algorithm will find R= [4,1,0,1,0], which will lead to V = 14 x 4+8x1+6x0+5x1+1 x 0, that is, V = 14 x 4+8x1+5x1 a- Test your algorithm for three cases of your choice. In each of the three cases V should be greater than 150, m should be at least 6, and the maximum value in L should be in the range [10, 20]. Keep in mind that the integers in L must be distinct. Two of your cases should produce minimum combinations, while the third example should not produce the actual minimum combination. In other words, the third example will illus- trate that the algorithm does not work for every given case. b- Find the complexity of your program c- Show that the implemented greedy algorithm is loop invariant. Given an integer V > 1 and a list of m distinct integers L[1..m] where L[i] <V, for i=1tom and L[m] = 1 Implement the greedy algorithm to represent V as the sum of products using minimum possible number of integers from L as discussed in class. You may use another array R[1..m] to keep track of the intermediate results. Then print the outcome using values from R and L. For instance, given V = 69, m = 5 and L = [14, 8, 6, 5, 1]. Then the algorithm will find R= [4,1,0,1,0], which will lead to V = 14 x 4+8x1+6x0+5x1+1 x 0, that is, V = 14 x 4+8x1+5x1 a- Test your algorithm for three cases of your choice. In each of the three cases V should be greater than 150, m should be at least 6, and the maximum value in L should be in the range [10, 20]. Keep in mind that the integers in L must be distinct. Two of your cases should produce minimum combinations, while the third example should not produce the actual minimum combination. In other words, the third example will illus- trate that the algorithm does not work for every given case. b- Find the complexity of your program c- Show that the implemented greedy algorithm is loop invariant.
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-6. On December 12, Irene purchased the building where her store is located. She paid...
-
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...
-
Prove that: [A (B C)] + [B (C A)] + [C (A B)] = 0. Under what conditions does A (B C) = (A B) C?
-
Write 3 hypotheses about the relationship between ROA and goodwill, between ROA and sales, ROA and short term investments.
-
Given the information below, and assuming the following balances: Cash, $42,000; Accounts Receivable, $173,000; Allowance for Doubtful Accounts, $400 credit; Inventory, $12,000: a. Prepare on...
-
In a 4-stage turbine, steam is supplied at \(300 \mathrm{~N} / \mathrm{cm}^{2}\) and \(3800 \mathrm{C}\). The exhaust pressure is \(0.05 \mathrm{~N} / \mathrm{cm}^{2}\) and the overall turbine...
-
Oakley Company manufactures and sells adjustable canopies that attach to motor homes and trailers. The market covers both new units as well as replacement canopies. Oakley developed its 20x2 business...
-
The big hope housing company uses a predetermined overhead rate to allocate overhead based on Direct Labor cost. This years budget includes Overhead equal to $500,000 and Direct Labor cost of...
-
For R, partition the data sets into 60% training and 40% validation and implement the 10-fold cross-validation. Use the statement set. seed(1) to specify the random seed for data partitioning and...
-
On January 3, 2020, Baxter, Inc. acquired 40% of the outstanding common stock of Anchor Co. for $2,800,000. This investment gave Baxter the ability to exercise significant influence over Anchor....
-
Saltwater is denser than fresh water. A ship floats in both fresh water and saltwater Compared to the freshwater, the volume of saltwater displaced by the ship is A) greater than the volume of fresh...
-
What is the area and uncertainty in area of one side of a rectangular wooden board that has a length of ( 2 1 . 4 \ pm 0 . 4 ) cm and a width of ( 9 . 8 \ pm 0 . 1 ) cm ? ( Give your answers in cm 2...
-
As compared to operating company IPOs, SPAC IPOs are typically a slower process. Group of answer choices True False 2. What is the primary purpose of a SPAC? Group of answer choices To take a company...
-
A diffraction study of a cubic system with Cu K radiation ( = 0.154 nm) offered the interplanar spacing of a plane, d110 = 2.22 nm. Find out the interplanar spacing of the plane (220), with the aid...
-
At wood machine. A 20kg box and a 30kg crate are attached to the two ends of a massless string that passes over a massless frictionless pulley. The system is released from rest. Without performing a...
-
An accountant of the trading business could not agree with the Trail Balance. The excess of amount was transferred to Suspense A/C. The following errors were subsequently discovered. 1. Received RO...
-
Calculate I, , and a for a 0.0175 m solution of Na 3 PO 4 at 298 K. Assume complete dissociation. How confident are you that your calculated results will agree with experimental results?
-
Let us associate a weight w(x) = 2 d with each leaf x of depth d in a binary tree T, and let L be the set of leaves of T. Prove that x L w(x) 1. (This is known as the Kraft inequality.)
-
Argue that after executing RB-DELETE-FIXUP, the root of the tree must be black.
-
In how many ways can we choose three distinct numbers from the set {1, 2, . . . ,99} so that their sum is even?
-
Describe how competence, caring, and character affect your credibility as a communicator.
-
Define and explain business ethics, corporate values, and personal values.
-
Explain the importance of establishing credibility for business communications.
Study smarter with the SolutionInn App