\documentclass[11pt]{article}

\usepackage{fullpage}
\usepackage{graphicx,epsfig}


\begin{document}

\title{{\bf In-class work: Weighted interval scheduling}
}


\date{}

\maketitle


This problem is not in the textbook, but is a classic
dynamic-programming problem. It is the more general version of the
activity selection problem in CLRS 16 --- which we'll discuss next time.

\paragraph{The problem:} Imagine you have a set of jobs: each job has
to start and end at a certain time and has a certain value or
weight. The weight of a job measures its importance---higher weight if
more important; if all jobs were ``equal'' they would have all equal
weights.  Furthermore, imagine we have a single classroom where we can
schedule these jobs.  We want to pick a set of jobs that we can assign
to the classroom.
\begin{itemize} 
\item First, this set of jobs has to be \emph{compatible}, or
  non-overlapping (so that they can be scheduled in the same
  classroom).
\item Second, we want to weigh in the weights: Of all possible
  choices, we want to find a subset of jobs (to schedule in the
  classroom) of maximum total weight.
\end{itemize} 

Here is the more abstract version of this problem: Given a set of
intervals $I_1, I_2, ..., I_n$ with their start times $s[1..n]$,
finish times $f[1..n]$, and values $v[1..n]$, find a subset of
compatible (non-overlapping) intervals of maximal total value:

$$\textrm{find } S \subseteq I \textrm{ such that } S \textrm{
  compatible and}  \sum_{i \in S} v_i
\textrm{ is maximized}$$


\vspace{.5cm}
As always, for simplicity, we'll start by computing \emph{only} the
maximal value of the subset.  Once we know how to do this, we'll
extend the solution to compute not only the value, but the actual
subset of jobs that achieve this value.
\begin{enumerate} 

\item {\bf Building intuition:} Consider a subset of activities $S$ that
  represents the optimal solution. An interval $I_k$ is either in $S$,
  or not.  When we come to deciding whether an activity is part of the
  solution or not, we have precisely two choices.  Now let's try to
  come up with a recursive formulation that uses this insight.

 

\item {\bf Notation I: } Coming up up with a suitable notation can be
  tricky. Here we are giving you the notation:
  
  Let us assume that the jobs are ordered by non-decreasing finish
  time $f_i$: $$f_1 \le f_2 \le f_3 .... \le f_n$$
  
  Define $p(j)$  to be the job with the largest index  less than $j$
  which is compatible with job $j$.  In other words, the largest index
  $k$ such that $f_k \le  s_j$.  If  no such job exists then  define
  $p(j) = 0$. 
 
  Note that none of the intervals $I_1, I_2,...I_{p(j)}$ intersects
  with $I_j$. 

  Draw a set of 8 activities, number them so that they are orderd by
  finish time, and show $p(j)$ for all activities.

\vspace{10cm}

\item Show how to compute all $p(i)$, $i=1..n$ in $On^2)$ time; what
  about in $O(n \lg n)$ time? What about in $O(n)$ time? Remember that
  we assume the activitoes are numbered in order of their finish
  times; you may also assume that you have a list of the activities
  sorted by their start times.

\vspace{10cm}

\item {\bf Notation II: } Let $S(i)$ denote the maximum weight of
  any set of compatible jobs, all of which finish by $f_i$.

  We want to compute $S(n)$.

  Assume we have computed $p(i)$, $i=1..n$.

  Give the recursive formulation for $S(i)$, including the basecase:


\vspace{10cm}


\item Write the recursive algorithm that computes $S(i)$. 
\vspace{10cm}


\item Analysis: Let $T(n)$ be the worst-case running time of computing
  $S(n)$. Write a recurrence relation for $T(n)$. 

\vspace{5cm}

\item Argue that $T(n)$ is exponential. 

\vspace{5cm}

\item  Describe a dynamic programming solution and analyze its running
  time.


\end{enumerate}


\end{document}
