Question: Exercise 3 (Greedy algorithms (30 points)) In this exercise, you will plan out your homework with a greedy algorithm. You are given as input a
Exercise 3 (Greedy algorithms (30 points)) In this exercise, you will plan out your homework with a greedy algorithm. You are given as input a list of homeworks defined by two arrays, an array of weights (the relative importance of the homework towards your final grade), and an array of deadlines. Those arrays are not sorted. Each index on those arrays, which are of the same size, represents a single homework to submit. Weights and deadlines are both integers between 1 and 100. Each homework takes exactly one hour to complete. Your task is to output a homeworkPlan, which will take the form of an array of length equal to the weights and deadlines. Each index in this array represents the same homework as each index in the input arrays. For each homework, indicate the time at which you plan on completing the homework. This time should be defined as an integer between 1 and the latest deadline of your homeworks, divided into slots of one hour. If you do not plan on completing a specific homework at all indicate 0 in the corresponding slot of the homeworkPlan. The homework is considered due at the end of the time slot. In other words, if the homework is due at t 14, then you can complete it before or during the slot t=14. For example. Homework 2 is defined as the homework with deadline deadlines [2] and weight weights [2] If your solution plans on doing Homework 2 first, then homeworkPlan [2]-1 should appear in your output. You can only complete a single homework in a 1 hour slot. Note that sometimes you will be given too much homework to complete in time, and that is ok ay Your homework plan should maximize the sum of the weights of completed assignments To organize your schedule, we give you a class HW_sched.java, which defines an Assignment object, with a number (it's index in the input array), a weight and a deadline.In addition, we provide you the file GreedyTester. java that demonstrates how to use this class to initialize an ArrayList of homework objects of the appropriate size. In order to organize your schedule efficiently, you will have to sort the homeworks. For your con- venience, we provide a compare method, which takes as input two assignments, compares them, and outputs the order they should appear. You have to determine what comparison criterion you want to use to compare assignments in this problem. Given two assignments Al and A2, the method should output . 0, if the two items are equivalent I, if al should appear before a2 in the sorted list . -1, if a2 should appear before al in the sorted list Your compare method should be the only tool you use to re-organize lists and arrays in this problem. Exercise 3 (Greedy algorithms (30 points)) In this exercise, you will plan out your homework with a greedy algorithm. You are given as input a list of homeworks defined by two arrays, an array of weights (the relative importance of the homework towards your final grade), and an array of deadlines. Those arrays are not sorted. Each index on those arrays, which are of the same size, represents a single homework to submit. Weights and deadlines are both integers between 1 and 100. Each homework takes exactly one hour to complete. Your task is to output a homeworkPlan, which will take the form of an array of length equal to the weights and deadlines. Each index in this array represents the same homework as each index in the input arrays. For each homework, indicate the time at which you plan on completing the homework. This time should be defined as an integer between 1 and the latest deadline of your homeworks, divided into slots of one hour. If you do not plan on completing a specific homework at all indicate 0 in the corresponding slot of the homeworkPlan. The homework is considered due at the end of the time slot. In other words, if the homework is due at t 14, then you can complete it before or during the slot t=14. For example. Homework 2 is defined as the homework with deadline deadlines [2] and weight weights [2] If your solution plans on doing Homework 2 first, then homeworkPlan [2]-1 should appear in your output. You can only complete a single homework in a 1 hour slot. Note that sometimes you will be given too much homework to complete in time, and that is ok ay Your homework plan should maximize the sum of the weights of completed assignments To organize your schedule, we give you a class HW_sched.java, which defines an Assignment object, with a number (it's index in the input array), a weight and a deadline.In addition, we provide you the file GreedyTester. java that demonstrates how to use this class to initialize an ArrayList of homework objects of the appropriate size. In order to organize your schedule efficiently, you will have to sort the homeworks. For your con- venience, we provide a compare method, which takes as input two assignments, compares them, and outputs the order they should appear. You have to determine what comparison criterion you want to use to compare assignments in this problem. Given two assignments Al and A2, the method should output . 0, if the two items are equivalent I, if al should appear before a2 in the sorted list . -1, if a2 should appear before al in the sorted list Your compare method should be the only tool you use to re-organize lists and arrays in this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
