



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This assignment was submitted to Prof. Madhulata Nirmal at Chhattisgarh Swami Vivekanand Technical University for Theory of Complexity and Algorithms course. It includes: Greedy, Algorithms, Value, Index, Table, Fractional, Knapsack, Problem, Interval, Scheduling, Finish, Times
Typology: Exercises
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Greedy algorithms
Solve the Fractional Knapsack Problem for this set of items, where the maximum total allowed weight is Wmax = 15.
Using the value indices, we select the items in order b, a, e, d, f, g, c, h until the knapsack is full. Then we Pick item b. Total benefit (so far) = 5. Total weight (so far) = 1. Pick item a. total benefit = 19. Total weight = 4. Pick item e. Total benefit = 27. Total weight = 6. Pick item d. Total benefit = 39. Total weight = 10. Pick item f. Total benefit = 49. Total weight = 14. Pick 18 of item g. Total benefit = 49 + 18 (16) = 51. Total weight = 14 + 18 (8) = 15. Therefore, our solution is to take items b, a, e, d, f, 18 g for a total benefit of 51.
j sj fj 1 1 3 2 2 4 3 3 5 4 4 6 5 5 6 6 2 7 7 3 7 8 5 8 9 7 9 10 6 10 11 8 10 Having done this sorting, then we schedule the tasks in order, omitting those that conflict with already scheduled tasks. So we schedule (1, 3), which means we can’t schedule (2, 4). Then we schedule (3, 5), which means we can’t schedule (4, 6), etc. In the end, the tasks we will schedule using this procedure will be (1, 3), (3, 5), (5, 6), (7, 9), for a total of four tasks we can schedule (which is the most we could schedule on a single machine). Note that (in this case) there is more than one way we could schedule four tasks, but we won’t be able to schedule five tasks on a single machine in any fashion.
(b) Solve the Task Scheduling Problem for this collection of tasks (i.e. find the minimum number of machines required to complete all tasks, and give a schedule for doing so). Solution: This is similar to the above problem, but this time we’ll sort the tasks in order by their start times. j sj fj 1 1 3 2 2 4 3 2 7 4 3 5 5 3 7 6 4 6 7 5 6 8 5 8 9 6 10 10 7 9 11 8 10
Using these observations above, the argument can be made more pre- cise and mathematically formal to show that this greedy algorithm will minimize the number of coins used.
Solution: Well, I’m not going to give any particular example here, but will leave it up to you to find your own. You can certainly give examples that consists of only three coins, namely values 1, x, y for some x and y. (The value 1 is included because of the condition I imposed.) Think about the observations made for an optimal solution in the previous problem, and see where they might go wrong if you have other values of coins.
Here the solution (I hope) is straightforward. First of all, without loss of generality (by sorting and renumbering if necessary) we will assume that x 1 < x 2 < x 3 < · · · < xn. If it’s not clear from the problem description, we’re assuming that we can place a guard at any real number (and they need not be placed at a particular painting, but can be placed in between paintings). With this in mind, we will place the first guard at the real number x 1 + 1. This guard will cover the painting at position x 1 , and possibly others. So we can find the smallest index j such that xj− 1 ≤ x 1 + 1 but x 1 + 1 < xj. (In other words, this first guard can watch paintings at positions x 1 ,... , xj− 1 , but not the one at position xj .)
This leaves us with a subproblem consisting of paintings xj ,... , xn for some j ≥ 2. Then we repeat the argument above. This will give us the minimum number of guards necessary to guard all the paintings.
(Note that if the guards can only be placed at the same positions of the paintings, then a similar argument can be used to find the minimum number of guards. How would this procedure be modified to do so?)