0
$\begingroup$

Lets say we have plenty people to dress up entrees, but only one chef to cook them. Each entree $E_i$, takes $c_i$ time to cook and $d_i$ time to "dress up". The dressing up of entrees can occur while other entrees are being cooked and dressed up, but we can only cook one entree at a time. How would you go about creating an algorithm to schedule each entree $E_i$ in a manner that they all get finished in the shortest amount of time?

$\endgroup$
  • 1
    $\begingroup$ The "greedy" approach would appear to be to cook the one with the longest dressing time first. My gut says this is optimal but a proof escapes me... $\endgroup$ – Matthew C Oct 31 '19 at 22:30
  • $\begingroup$ cs.stackexchange.com/q/59964/755 $\endgroup$ – D.W. Oct 31 '19 at 22:37
  • $\begingroup$ I just wanted to mention that the statement of this problem seems contrived but I thought of a quite realistic way of phrasing this problem. There is one expensive piece of equipment at my university that many scientists need to conduct their research. The process for each scientist's experiment is to use the instrument for some time, and then go off on their own to do data analysis with the machine's output. The university might be interested in scheduling the uses of the instrument so that all experiments are finished, at the earliest time possible. $\endgroup$ – Matthew C Nov 1 '19 at 0:26
3
$\begingroup$

The link suggested by @D.W. above put into words exactly what I was looking for, an "exchange lemma" that proves the optimality of the greedy strategy. Here it is:

Suppose we cook in the order $1,2,\ldots, n$. Let $i \in \{1,2,\ldots,n-1\}$ be the smallest integer such that $d_i<d_{i+1}$. We claim that altering the order of the cooking of dishes $i$ and $i+1$, and changing nothing else, results in an equally good or better finishing time. Let us denote $ft(k)$ as the time when dish $k$ is finished under the original ordering (and all dishes are finished at time $\max\limits_{1\leq k\leq n} ft(k)$). We also denote by $ft'(k)$ the time when dish $k$ is finished under the altered ordering.

In general, we have $$ ft(k) = \sum\limits_{j=1}^k c_j + d_k $$ since we need to finish cooking dish $k$, which happens after $1,2,\ldots, k-1$, and then finally we dress it.

For the altered ordering we have \begin{align*} ft'(i+1) &= \sum\limits_{j=1}^{i-1} c_j + c_{i+1} + d_{i+1}\\ ft'(i) &= \sum\limits_{j=1}^{i-1} c_j + c_{i+1} +c_i + d_{i} \end{align*} (the funny ordering is just to emphasize the order in which the dishes are cooked).

The following three facts are easy to prove:

  1. $ft(k)=ft'(k)$ for all $k \neq i, i+1$
  2. $ft'(i)\leq ft(i+1)$
  3. $ft'(i+1)\leq ft(i+1)$

These three together imply that $\max\{ft'(i),ft'(i+1) \} \leq \max\{ ft(i),ft(i+1)\}$ and hence $\max ft'(k) \leq \max ft(k)$ which proves the greedy strategy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.