1

This is an intriguing question given by my friend for which I want to find an optimal solution:

Each week, you can choose to work ONLINE $(ON)$ or in person $(WR)$ in your department's office. If you attend work online in week $i$, you will spend $ON_i$ hours; otherwise, if you attend work offline in the department, you will spend $WR_i$ hours. However, if you work online in week $i$ and convert to offline mode in week $i + 1$ or vice versa, you will have to spend an additional $H$ hours to transfer from online to offline since you will need to go to the office to request a change of mode. The amount of time it takes to switch is fixed, i.e. $H$ hours.

Create a schedule for working for $n$ weeks, with each week consisting of either online $(ON)$ or offline $(WR)$ attendance. The sum of the time we spent on each of the $n$ months, plus $H$ hours changeover time for each time you switch ways of attending work, equals the total credit hours of a plan. In either mode, the plan can commence.

Given the value of switching time H, and sequence of values $\{ON_1, > ON_2, . . . , ON_n\} and \{WR_1, WR_2, . . . , WR_n \}$, devise an optimal minimum credit hour schedule.

To solve this question, according to me, we can create a greedy algorithm and I came up with the following greedy algorithm:

for i = 1 to n
if ONi < WRi
   Output “Online in Month i”
else
   Output “Offline in Month i”
end

I would like to know if there is any other, that is a better algorithm that takes as input n, H and sequences $\{ON_1, > ON_2, . . . , ON_n\} and \{WR_1, WR_2, . . . , WR_n \}$, and returns the required credit hour optimally.

kiv
  • 339
  • 2
  • 7

0 Answers0