algorithm - range splitting problem -


folks,

have heard of problem quite time back. thought of posting it, views of doing using construct or other efficient means(specialized trees may be)

given set of ranges in pairs (5,18) (12,23) (15,30)

split them possible subranges seen overlapping other ranges in set. (5,11) (12,14) (15,18) (19,23) (24,30)

thanks all, appreciate that...

rajan...

ps aa standard problem, if yes, tu know name

chuck range endpoints list, mark them start/end-points.

[(5, s), (18, e), (12, s), (23, e), (15, s), (30, e)] 

sort them position, breaking ties putting start-points before end-points.

[(5, s), (12, s), (15, s), (18, e), (23, e), (30, e)] 

then can work out ranges iterating through list, keeping track of how many start- minus end-points we've processed far. if see start point, that's start of new range output. if our count positive, have end current range first though. if see end point, end current range.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -