Prove that the Task Selection algorithm is correct, meaning that it always returns a maximum set of non-overlapping tasks. (Hint: use a replacement-type argument similar to that used in proving correctness of Kruskal’s algorithm.)
Explanation :
Assume that each task t has a positive duration i.e., f(t) − s(t) > 0. Let t1, . . . , tn be the tasks selected by TSA(Task Selection Algorithm) , where the tasks are in the order in which they were selected (i.e. increasing start times). Let Topt be a maximum set of non-overlapping tasks. Let k be the least integer for which tk Topt. Thus t1, . . . , tk−1 ∈ Topt.
Claim: t1, . . . , tk−1 are the only tasks in Topt that start at or before tk−1. Suppose, by way of contradiction, that there is a task t in Topt that starts at or before tk−1, and t ti , i = 1, . . . , k − 1. Since t does not overlap with any of these ti , either t is executed before t1 starts, in between two tasks ti and ti+1, where 1 ≤ i < k − 1. In the former case, ASA would have selected t instead of t1 since f(t) < f(t1). In the latter case, ASA would have selected t instead of ti+1, since both start after ti finishes, but f(t) < f(ti+1). This proves the claim.
Hence, the first k − 1 tasks (in order of start times) in Topt are identical to the first k − 1 tasks selected by TSA. Now let t be the k th task in Topt. Since TSA selected tk instead of t as the k th task to add to the output set, it follows that f(tk) ≤ f(t). Moreover, since both tasks begin after tk−1 finishes, the set Topt2 − t + tk is a non-overlapping set of tasks (since tk finishes before t, and starts after tk−1 finishes) with the same size as Topt. Hence, Topt2 is also optimal, and agrees with the TSA output in the first k tasks.
By repeating the above argument we are eventually led to an optimal set of tasks whose first n tasks coincide with those returned by TSA. Moreover, this optimal set could not contain any other tasks. For example, if it contained an additional task t, then t must start after tn finishes. But then the algorithm would have added t (or an alternate task that started after the finish of tn) to the output, and would have produced an output of size at least n+ 1. Therefore, there is an optimal set of tasks that is equal to the output set of TSA, meaning that TSA is a correct algorithm.
For Better understanding (In image form) :
Get Answers For Free
Most questions answered within 1 hours.