mercredi 15 juin 2016

how do i design an algorithm to find optimal solution of number of changes?

I have this assignment question and i have absolutely no idea how to get the right answer, does anyone know what the right answer for this would be?

A) An n-day conference is to be held at a University.

For each day of this conference, exactly one large meeting room is required, and it will be used throughout the day.

There are m meeting rooms at the university that are large enough for this conference. However, none of these rooms is available on each day of the n-day conference period.

Fortunately, at least one meeting room is available during each of the n days, so it is still possible to hold the conference at the university.

However, each time the conference is switched from one room to the next, much work has to be done, including moving new books on display, bulletin boards, job postings, etc. Thus, our goal is to choose the room assignments while minimizing the total number of room changes.

The task is to design an algorithm to find an optimal solution to this problem.

More precisely, the input to the algorithm is an m × n array A, in which A[i, j] = 1 if meeting room i is available for the conference on the j-th day of the conference, and A[i, j] = 0 otherwise.

There is at least one 1 in each column of the table.

Table 1 gives an example of the input table, in which m = 3 and n = 8.

Table 1

   m/n  1  2  3  4  5  6  7  8
   1    0  0  0  1  0  1  1  1
   2    1  1  1  0  0  1  1  1
   3    1  1  0  1  1  1  0  0 

The output is an array S[1..n], in which S[d] = r if and only if meeting room r is used for the conference on the d-th day. Hence, for an index i of the array with 1 ≤ i ≤ n−1, the inequality S[i] ̸= S[i + 1] means that a room change occurs on the (i + 1)-th day. The goal is to minimize the number of room changes. In the example above, one optimal solution is S = [2, 2, 2, 3, 3, 1, 1, 1], which requires two room changes. Note that the optimal solution need not be unique.

One possible greedy strategy is to choose the room with the largest number of available days, and then use all the days it is available for the conference.

Next, choose the room with the second largest number of available days (excluding the days already handled) and use all its available days, not including the days already handled.

Repeat this process. Following this strategy, the output array for the above example is S = [2,2,2,3,3,2,2,2] and two room changes are performed. Show that this strategy does not always give an optimal solution by constructing a counterexample. Explain why the solution is not optimal.

B)Design an efficient greedy algorithm for the problem described in Question A that always finds an optimal solution. When you justify the correctness of your algorithm, carefully prove that your greedy strategy always gives an optimal solution.

Aucun commentaire:

Enregistrer un commentaire