Thursday, 15 September 2011

algorithm - Given some integer ranges, finding a smallest set containing at least one integer from each range -



algorithm - Given some integer ranges, finding a smallest set containing at least one integer from each range -

how can find set of minimum number of integers such that, given ranges of integers, each range, set contains @ to the lowest degree 1 integer. example, if i'm given these ranges :

[0, 4], [1, 2], [5, 7], [6, 7], [6, 9], [8, 10]

then solution sets : { 1, 6, 8 }, { 2, 7, 9 }, { 1, 7, 8 } etc.

imagine draw ranges, ordered end value, draw meetings within day planner.

you can visually take numbers in greedy manner, such first 1 segment finishes first (in example, 2).

then erase segments contain number, , start over.

this algo yield solution { 2, 7, 10 }

0 1 2 3 4 5 6 7 8 9 10 ---- ------------- ^ ------- | ---- ---------- ^ ------- | ^ |

algorithm

No comments:

Post a Comment