I have a set of ranges :
Range1 —- (0-10)
Range2 —- (15-25)
Range3 —- (100-1000) and likewise. I would like to have only the bounds stored since storing large ranges , it would be efficient.
Now I need to search for a number , say 14 . In this case, 14 is not present in any of the ranges whereas (say a number) 16 is present in one of the ranges.
I would need a function
bool search(ranges, searchvalue)
{
if searchvalues present in any of the ranges
return true;
else
return false;
}
How best can this be done ? This is strictly non-overlapping and the important criteria is that the search has to be most efficient.
there is a similar question which I asked considering C++ where we can use map or vector But how can it be best done on C# ?
You can define a class range and do a binary search on it:
it’s better keep list sorted in startup or using sortedlist