The interval partitioning problem is described as follows: Given a set {1, 2, …, n} of n requests, where ith request starts at time s(i) and finishes at time f(i), find the minimum number of resources needed to schedule all requests so that no two requests are assigned to the same resource at the same time.
I read from many sources, that the solution often is:
- sort again by earliest time of requests.
- For each requests in sorted request:
if can choose one resource that can do this requests:
assign that request to resource
else
create new resource
count++
assign that request to new resource
The result will be count after finishing algorithm.
However, I approach with different idea. The following is algorithm of my idea:
- Break all time range into 2 parts: (time=start_time, type=start) and (time=end_time, type=end)
- Sort all that events. If time equals, prefer type=end.
- Go from that sorted events, if type = start: count++. else count --
count will be the total machine we need.
My question is: is there any wrong with my approach.
Thanks