Algorithm for determining member-bound subintervals of an interval -


given list of items start , end times (e.g. start days , end days [up not including] in calendar month), minimum number of spanning intervals can constructed bounded members in 1 interval , members present in aforementioned intervals? think example make more clear (feels don't have right vocabulary describe problem):

input: [a,b,c,d,e]

a: 1,3 b: 2,4 c: 1,10 d: 5,7 e: 5,10 

output:

1-2: a,c 2-3: a,b,c 3-4: b,c 4-5: c 5-7: c,d,e 7-10: c,e 

if there gap i'd want know (say 4-5 wasn't covered item).

i've considered basic walks of each item , min-max considerations, bsts, , interval trees in particular kind of feel lost best approach here. thanks!

  • step 1: iterate on items, building list of entries of form { day 1, start of } , { day 3, end of }.
  • step 2: sort list day.
  • step 3: combine entries same day, giving entries { day 5, [ start d, start e ] }.

(note: since days in single month, know beforehand possible days — , there aren't many — can combine 3 of above steps 1 straightforward pass using bucket sort 31 buckets.)

  • step 4: iterate on combined entries, keeping track of items have started not yet ended, , generating desired output.

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -