|
|
| more useful options | |
| PerlMonks |
Re: searching a vector arrayby zek152 (Pilgrim) |
| on Jun 09, 2011 at 16:30 UTC ( [id://908955]=note: print w/replies, xml ) | Need Help?? |
|
I am not quite clear if this fulfills the requirements but if all you need to do is to see if a single value is covered you could implement a binary search tree. The binary search tree could be arranged based on the starting location. Then if the point you are considering is less than or equal to the starting point of a subinterval you go down the left branch. If it is greater than the starting value you check to see if it is less (or equalto) than the ending value. If so then the point is covered. If not then you continue traversing the tree in a recursive manner. if you make it to a null link then the point is not covered. Hopefully this made sense. The search complexity would be O(log(#subintervals))
Update: I didn't have time to finish the example. I also made a correction to the traversal algorithm (in italics)
I plan on working out an efficient algorithm for finding and removing subsets of subsets (removing (1,3] when (1,5] is a subset). I will post when complete.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||