Suppose you are trying to solve the Interval Partitioning pr
Suppose you are trying to solve the Interval Partitioning problem by using the Interval Scheduling algorithm. The algorithm is quite simple:
1. Run the Earliest Finishing Time algorithm on S.
2. Assign the jobs output by this algorithm from S to one set, output this set, and delete these jobs from S.
3. Repeat the first two steps until S is empty.
The intuition behind this algorithm is that after every execution of the Earliest Finishing Time algorithm, the depth of the remaining jobs must decrease by 1. Therefore, this algorithm must stop after d iterations, where d is the depth of S. Unfortunately, this intuition is incorrect. Your task is to come up with a counterexample, i.e., construct an input of jobs for which this algorithm outputs more sets than the depth. Briefly explain why your input has this property.
Solution
Algorithm:
Let R be the set of all requests
Let R be the set of all requests
while !R.empty():
Choose a request i R that has the earliest start time
if i can be assigned to some resource k <= d:
assign request i to resource k
else:
allocate a new resource d+1
assign request i to resource d+1
d = d + 1
return d
This issue can be understood ideally with a covetous procedure of planning solicitations in view of soonest begin time i.e., from the arrangement of outstanding solicitations, we generally select the one with the most punctual begin time and relegate it to one of the accessible assets (on the off chance that it would not bring about a contention) or request another asset for this demand.
Give us a chance to characterize the profundity of an arrangement of solicitations R to be the most extreme number of solicitations in R in strife whenever. Obviously for any arrangement of solicitations R, the quantity of assets required is at any rate the profundity of R on the grounds that the solicitations in struggle must be allocated to various assets.
We now demonstrate by inconsistency that the above eager calculation utilizes precisely d assets to plan an arrangement of solicitations R, where d is the profundity of the set R.
Assume the eager calculation utilizes more than d assets. Give j a chance to be the main demand that is allocated to the asset d+1. Since we handle demands as indicated by non-diminishing begin times, there are d asks for that begin (at or) before j and are in struggle with j. In this way toward the begin time of demand j, there are in any event d+1 asks for in strife, negating our presumption that the profundity is d. Subsequently, the insatiable calculation utilizes precisely d assets and thus is ideal.
| while !R.empty(): |
| Choose a request i R that has the earliest start time |
| if i can be assigned to some resource k <= d: |
| assign request i to resource k |
| else: |
| allocate a new resource d+1 |
| assign request i to resource d+1 |
| d = d + 1 |
| return d This issue can be understood ideally with a covetous procedure of planning solicitations in view of soonest begin time i.e., from the arrangement of outstanding solicitations, we generally select the one with the most punctual begin time and relegate it to one of the accessible assets (on the off chance that it would not bring about a contention) or request another asset for this demand. Give us a chance to characterize the profundity of an arrangement of solicitations R to be the most extreme number of solicitations in R in strife whenever. Obviously for any arrangement of solicitations R, the quantity of assets required is at any rate the profundity of R on the grounds that the solicitations in struggle must be allocated to various assets. We now demonstrate by inconsistency that the above eager calculation utilizes precisely d assets to plan an arrangement of solicitations R, where d is the profundity of the set R. Assume the eager calculation utilizes more than d assets. Give j a chance to be the main demand that is allocated to the asset d+1. Since we handle demands as indicated by non-diminishing begin times, there are d asks for that begin (at or) before j and are in struggle with j. In this way toward the begin time of demand j, there are in any event d+1 asks for in strife, negating our presumption that the profundity is d. Subsequently, the insatiable calculation utilizes precisely d assets and thus is ideal. |

