Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

algorithm - Finding maximal set of disjoint intervals - Priority to longer intervals

A maximal set of disjoint intervals is a standard algorithm question.

Basically given a set of overlapping intervals, (1,2),(2,6),(1,10),(6,13), we can choose (1,2),(2,6),(6,13). The standard algorithm sorts the lists of intervals by the second element in each interval and proceeds to choose the intervals in a greedy manner. Because we already have a list in increasing order of the second element, it ensures we maximize the number of intervals.

Now, this question has been modified to give priority to longer intervals. For example, given a list (1,2),(2,6),(1,10),(6,13), we'll choose the interval (1,10) and not the one we chose above.

Another example: (1,5),(2,7),(11,18), the answer in the modified question would be (2,7),(11,18) against (1,5),(11,18) we would get by proceeding in a greedy manner.

I need some help in modifying the original algorithm to fit the second question.

Thank you.

Reference: https://www.geeksforgeeks.org/maximal-disjoint-intervals/

question from:https://stackoverflow.com/questions/65875416/finding-maximal-set-of-disjoint-intervals-priority-to-longer-intervals

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...