the interval scheduling problem and proved that the algorithm described (choosin
ID: 3644470 • 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.
create a completely naive implementation using only an unordered list to store the set of intervals. Analyze your implementation and identify a tight Big-O bound on the execution time.
Explanation / Answer
import java.util.*; public class Deal { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: Deal hands cards"); return; } int numHands = Integer.parseInt(args[0]); int cardsPerHand = Integer.parseInt(args[1]); // Make a normal 52-card deck. String[] suit = new String[] { "spades", "hearts", "diamonds", "clubs" }; String[] rank = new String[] { "ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king" }; List deck = new ArrayList(); for (int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.