A greedy algorithm commits to a locally best available choice and then continues on the remaining problem without revising earlier choices. Correctness requires proving that such choices can belong to an optimal solution; local attractiveness alone is insufficient.
Kruskal's algorithm processes the edges of an undirected weighted graph in nondecreasing weight order. It accepts the next edge exactly when its endpoints lie in different components of the currently chosen forest, thereby preserving the absence of a cycle. This is greedy because it always chooses a cheapest available edge compatible with the forest constraint and never retracts an accepted edge.
The Kruskal safe edge argument explains why the choice works: if a minimum spanning tree extending the current forest lacks the chosen edge, adding that edge creates a cycle; an edge on that cycle crossing the same component boundary can be removed without decreasing connectivity. Such a crossing edge cannot be lighter than the chosen eligible edge, so the exchange does not increase total weight. The new minimum spanning tree includes the greedy choice. For a disconnected graph the same construction yields a minimum spanning forest rather than a single spanning tree.
Four closed intervals suffice:No time belongs to three intervals, so the maximum number of attendees at one meeting is two. Strategy 1 is allowed to choose , which meets and . The remaining intervals and are disjoint, requiring two further meetings. This run therefore uses three meetings.
However, times and meet everyone: and . One meeting is impossible because . Thus the optimum is two, while strategy 1 can use three. The counterexample deliberately uses an allowed tie between maximum-attendance choices: the instruction to pick “any” such time would require every tie choice to be safe.
Four availability intervals: a permitted maximum-attendance choice at 2.5 leaves two extra meetings, while the endpoints 1 and 4 suffice
. Details. The earliest end is , so strategy 2 first meets at , removing and . Among the remaining intervals the earliest end is , so it next meets at , removing and . This is the two-meeting optimum proved in part (b). The closed endpoints are essential: attendance at exactly an interval's endpoint is permitted.
Let be an interval whose earliest end triggers greedy meeting . After that meeting, every remaining interval starts strictly after : its end is at least , and otherwise it would contain and be removed. HenceThe witness intervals are therefore pairwise disjoint. Every feasible schedule needs a distinct meeting in each one, yielding a lower bound of . The greedy schedule uses exactly meetings and covers everyone, so it is optimal. This is an optimality certificate for the interval stabbing problem.
To follow the source's suggested contradiction explicitly, suppose a schedule with covered everyone. Since ends at , some , so . If and , then none of the first alternative meetings can hit , which starts after . A later meeting must hit it by its end , implying . Mathematical induction gives for . But starts after , later than every alternative meeting. It is uncovered, a contradiction. For a nonempty family is immediately uncovered. The source's hint starts at index zero without defining ; the proof above starts at the actual first meetings instead.
Sort once by nondecreasing end time, then retain the most recent meeting:When an interval is inspected, because of the sorted end order. Therefore the interval is already covered exactly when ; otherwise it is the earliest-ending uncovered interval and the algorithm chooses its end. This proves that the scan implements greedy strategy 2. The strict test
Meetings(intervals):
sort intervals by nondecreasing end
result = []
haveMeeting = false
for (s,e) in intervals:
if not haveMeeting or s > lastMeeting:
lastMeeting = e
append e to result
haveMeeting = true
return results > lastMeeting correctly treats equality as covered for closed intervals.The sorting costs comparisons, and the scan costs , with space for the output and constant scan state. Including an empty input, the overall bound is time, conventionally for . Additional sorting space depends on the selected sorting algorithm. Part (d) proves that the returned number of meetings is minimum.
Articles by others on the same topic
There are currently no matching articles.
