(Latest Revision: Apr 29, 2019)

Weighted Intervals Problem


This exercise is due Thursday, May 9. It has to be turned in on time in order to get participation credit. I'll come into class and go over the solution right away. Then I will collect your work on the exercise. Be ready to turn it in at that time.

EXAMPLE:

Suppose we have the following weighted intervals.
start   finish   weight
 11       14       4
 10       13       5
  9       11       5
 11       14       3
  8        9       2
To solve the problem, we start out by sorting the intervals by finish time. This gives us the following.
start   finish   weight
  8        9       2
  9       11       5
 10       13       5
 11       14       4
 11       14       3
Next we calculate the p-values. P(j) = k where interval k is the last interval prior to interval j in the list below which does not conflict with interval j, or P(j) = 0 if all intervals prior to interval j conflict with it.
#   start    finish    weight    P
1     8         9        2       0
2     9        11        5       1 
3    10        13        5       1
4    11        14        3       2
5    11        14        4       2
Finally, we use the formula OPT(j) = max{OPT(j-1), weight(j)+ OPT(P(j))} to fill in the OPT value for each j. (The base case where j=1 is that OPT(1)=weight(1)).
#   start    finish    weight    P    OPT
1     8         9        2       0     2 
2     9        11        5       1     7
3    10        13        5       1     7
4    11        14        3       2    10
5    11        14        4       2    11
BACKTRACKING:

Since OPT(5)=11>10=OPT(4), we know that interval 5 is part of an optimal solution. Since the P value for 5 is 2, we know that the rest of the intervals are chosen from among intervals 1 and 2.

Since OPT(2)=7>2=Opt(1), we know that interval 2 is part of an optimal solution that uses interval 5. Since the P value for 2 is 1, we know that the rest of the intervals are chosen from "among" interval 1.

As a base case of the backtracking, we see that we can either take interval 1, and get its weight 2, or not take it, and get nothing, so we conclude that interval 1 is a part of the solution.

Thus, by backtracking, we have found that intervals 5, 2, and 1 form an optimal solution, with total weight 11.

The example above shows how to work this kind of problem. Your assignment is to work the following problem, and to produce the corresponding table and backtracking results, according to the technique illustrated in the example.

YOUR ASSIGNED PROBLEM:

start   finish   weight
 13       15       2
 11       13       4
 13       16       2
 14       17       6
 10       13       6
Let me know in class if you have questions about how such problems are solved. The algorithm is covered in sections 6.1 and 6.2.