Greedy attempt [00QX]

We've previously studied greedy algorithms, which is definitely the thing to try first. For example, one possible greedy algorithm is shown below.

i \gets 1
\mathsf {while} i \leq n:
\mathsf {if} i < n and H_{i+1} > L_i + L_{i+1}:
Take week i off, choose H_{i+1} and continue with i \gets i + 2
\mathsf {else}:
Choose L_{i} and continue with i \gets i + 1

This algorithm basically looks ahead one week and decides if it’s worth taking a week off in order to land a higher-paying job. However, this strategy fails, because taking a high stress job at week h_{i} means that you cannot take week h_{i} off to take a job at week h_{i+1}. Thus, any strategy employing look-ahead by a constant factor will fail. Here is a counter-example to the greedy algorithm.

WEEK 1 2 3
low stress 2 2 1
high stress 1 5 10
  • The greedy algorithm chooses: 5 (week 2) + 1 (week 3) = 6
  • However, the optimal solution is to choose: 2 (week 1) + 10 (week 3) = 12