Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 (5 points) Suppose that you have a collection of magnets of m different lengths: Ll > L2 > ... > Lm (You can
Question 2 (5 points) Suppose that you have a collection of magnets of m different lengths: Ll > L2 > ... > Lm (You can assume that you have an unlimited number of magnets of each of these lengths.) You would like to connect a series of these magnets, end-to-end, to create a total length of n. For example, if you have magnets of length 20, 5 and 1, you could create a total length of 72 by using twelve magnets of length 5 and twelve magnets of length 1. Another solution would be to use two magnets of length 20, six magnets of length 5, and two magnets of length 1. An optimal solution uses the smallest* number of magnets possible to create a total length of n. (a) Describe a greedy approach to solving this problem. In your solution, do not refer to the specific lengths (20, 5, 1) mentioned above, but refer instead to the general lengths: L] > L2 > ... > Lm (b) Use an example to demonstrate that your greedy algorithm is *not* guaranteed to be optimal if the lengths of magnets available are 30, 7, 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started