1
$\begingroup$

This is the problem:

An art gallery hired you to put guards so they can monitor artworks in a hallway. The goal is to minimize the amount of guards needed in this hallway. Each guard has a range of 10 meters (5m on the right, 5m on the left with him being in the middle).

No matter where the artworks are put in the hallway we want the minimal amount of guards as possible.

My Greedy Algorithm:

Start at the beginning of the hallway.
Find the position of the closest artwork from the entrance.
Put the guard at position closest artwork + 5m ahead.
Eliminate all the artworks covered by the guard.
Re-do the process but this time start where the range of the previous guard ended

Now how do I write a proof for this? How do I prove that my algorithm is indeed optimal? Which mathematical proof techniques can I use?

$\endgroup$
1
$\begingroup$

You can achieve this per induction over the position of the last artwork. Note that in the optimal strategy the guard must be put 5 meter ahead of the left most artwork and not exactly at it.

In the induction step you have to consider an additional artwork and distinct two cases, whether it is covered by the last fixed guard or not. If it is, you do not have to add one and hence, the optimal can not be better. In case it is not, it is easy to show, that an optimal that woul have covered it should have used strictly more guards.

| cite | improve this answer | |
$\endgroup$
1
$\begingroup$

It doesn't matter in which order we place the guards, so we can assume that we place the guards in such an order that each guard covered the first artwork from the right that isn't covered yet (since there must be a guard covering that artwork).

The guard can be placed anywhere from 5m to the left of the artwork to 5 to the right. Wherever we place him, the guard can't cover more artworks to the right because there are none, but may cover ore artworks by placing him as far to the left as possible. Since covering more artwork is better, this gives the optimal solution.

You may try to find different rules where your greedy solution is wrong: An example: We add another rule that a guard must not cover a single artwork on his own (naybe watching a single artwork would be too boring and a single guard would fall to sleep). If he covers one artwork only, then another guard must stand with him. Now if the first guard covers 3 artworks instead of 2, that might be non-optimal because the next guard can cover one artwork only. A different algorithm would be needed.

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

Let us prove your greedy algorithm is optimal in the sense of the least number of guards returned by simple reasoning.

Consider all "closest artwork"s found by your greedy algorithm. The algorithm ensures that each neighboring pair of them is over 10 meters apart. So any two of them are over 10 meters apart, which means one guard can monitor at most one of them. So we need as many guards as the number of all "closest artwork"s found. Since the algorithm adds one guard only when it locates one "closest artwork", it must be optimal.

| cite | improve this answer | |
$\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.