Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have many intervals of positive integer numbers that each of them has a score. I want to find a set of intervals that do not have any overlapping. I have these conditions for selecting overlapped intervals:
1.if two interval overlap then select an interval with high score.
2.if both have same score, select the first interval.

for example if we have these intervals(order is important):
[0,3],[5,9],[1,4],[12,15],[17,20],[13,16],[16,16],[22,24]    
score={1,5,0,12,17,13,20,22}


The result intervals are:
[0,3],[5,9],[16,16],[22,24]


I have to define intervals as follows:
C#
int[] intervalStart={0,5,1,12,17,13,16,22};
int[] intervalEnd={3,9,4,15,20,16,16,24};
int[] scores={1,5,0,12,17,13,20,22};

and excepted result is an array that consist of selected interval indexes:
C#
int[] result={0,1,6,7};


How to doing it and find this set?
Posted
Updated 11-Apr-16 10:40am
v3
Comments
Sergey Alexandrovich Kryukov 11-Apr-16 17:07pm    
You did not really formulate the problem. "I want to find a set of intervals that do not have any overlapping" has a trivial solution: make a set with only one member, one single correct interval. Will be no overlapping.

You did not formulated how input should be used in output, except just one rule. You did not define overlapping. In mathematics, "interval" is used for denoting an open set, but you use a notation for a closed set. As it makes formulation unclear, you have to clarify it. In other words, do [a, b] and [b, c] (a < b < c) overlap?

It's important to formulate the problem precisely, as in mathematics, not assuming anything.

The problem is quite trivial (it I understand the problem correctly; you still have to formulate it), but finding the fastest algorithm is somewhat harder. It's too bad that you did not show what you have tried. I'm not sure if many would volunteer to do your work for you.

—SA

1 solution

This is HomeWork, so you have to find how to do the program.

Hint: I think you will have to check every combination of interval and check if they meet the conditions.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900