the interval scheduling problem and proved that the algorithm described (choosin
ID: 3644474 • Letter: T
Question
the interval scheduling problem and proved that the algorithm described (choosing the interval with earliest deadline) below, always finds an optimal solution. For this problem you will write, analyze, and test several implementations of this algorithm.The following scheduling problem. Imagine you are a highly-in- demand actor, who has been presented with offers to star in n different movie projects under development. Each offer comes specified with the first and last day of filming. To take the job, you must commit to being available throughout this entire period. Thus you cannot simultaneously accept two jobs whose intervals overlap.Must solve the following algorithmic scheduling problem:
Problem: Movie scheduling Problem
Input: A set I of n intervals on the line.
Output: What is the largest subset of the mutually non-overlapping intervals which can selected from I?
Efficient algoritm:
OptimalScheduling (I)
While (I ! = 0) d0
Accept the job from I with the earliest completion date.
Delete j, and any interval, which intersects j from I.
From the interface below implement the algorithm in best way you can think of. Analyze the implementation and give a bound on the execution time. (Hint: it can actually be done in time O(n) plus the cost of sorting the list once.)
public interface IntervalScheduler
{
/**
* Returns a subset of maximal cardinality selected from
* the given list of intervals.
*/
public List<Interval> schedule(List<Interval> intervals);
}
Explanation / Answer
public static void refreshCalendar(int month, int year){ String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int nod, som; //Number Of Days, Start Of Month //Prepare buttons btnPrev.setEnabled(true); //Enable buttons at first btnNext.setEnabled(true); if (month == 0 && year = realYear+100){btnNext.setEnabled(false);} //Too late lblMonth.setText(months[month]); //Refresh the month label (at the top) lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 180, 25); //Re-align label with calendar cmbYear.setSelectedItem(String.valueOf(year)); //Select the correct year in the combo box //Get number of days and start of month GregorianCalendar cal = new GregorianCalendar(year, month, 1); nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); som = cal.get(GregorianCalendar.DAY_OF_WEEK); //Clear table for (int i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.