首页 > 其他 > 详细

marzullo's algorithm

时间:2014-11-14 12:09:27      阅读:248      评论:0      收藏:0      [点我收藏+]

given several intervals, how to find a interval which is a intersect of the most number of the given intervals?

Method:

Step1: Represent each returned interval in the following form [start, +1] , [end, -1]
Step2: You now have a list of tuples, the first element of which is a time. Sort these tuples by the time, irrespective of whatever is the second element. So you would have [t(i), val(i)], [t(i+1), val(i+1)], ... where val(i) = ±1. 
Step3: initialize two vars count = 0 and max =0
Step4: Now run through the sorted tuples and set count = count + val(i)
            Compare if count > max then 
                                set max = count
                                set answer = [t(i), t(i+1)]
Step5: Return answer

marzullo's algorithm

原文:http://www.cnblogs.com/miaoz/p/4096752.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!