Professional Documents
Culture Documents
Intervals
Intervals
com/discuss/study-guide/2166045/line-sweep-algorithms
Reason is if a new interval start is before previous end time that means a sure overlap.
While on the other hand if we sort by startTime, we dont know when this interval gonna end, there
will be overlaps.
Here are some additional points to consider:
Sorting by end time is a greedy algorithm. This means that it makes the best possible choice at
each step, without considering the future. As a result, it is usually more efficient than sorting by start
time.
Sorting by start time is a dynamic programming algorithm. This means that it makes a choice at
each step, based on the choices that it has made in the past. As a result, it is usually more robust to
errors in the input data.
For practice try to solve this problem , which can be solved in both DP as well as Greey Way and see
the difference
Questions