integer - Need unusual sorting algorithm -


i have list of approximately 5000 integer ranges (e.g. 30-50, 45-100, etc.) need put "sorted order." order needs based on list items range subsets of other items. example 10-12 range subset of 2-14. if list(1).low_value >= list(2).low_value , list(1).upper_value <= list(2).upper_value list(1) subset of list(2). complicate things, list items subsets of many list items.

i need create ordered list such list items @ lower indexes subsets of, or unrelated (e.g. ranges 1-2 , 3-4) to, items following in list.

thanks, mark

my first reaction sounds topological sort, ranges viewed nodes in graph, , edge considered exist range range b iff subrange of b.

i assume mean condition output list if appears before b, b not strict subset of (but it's fine if = b, , b disjoint, or , b overlap without 1 being subrange of other).

if width of range b (b.upper_value - b.low_value) @ least of range a, b cannot strict subrange of a. hence suffices sort list increasing width of ranges. can done in linear time (assuming fixed-size integers) computing widths , doing radix sort.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo