The special part comes in because there is an upper limit, and a lower limit. If the value is above the upper limit, I know that all values higher than this don't need to be calculated, they can all be set to MAX. Any value below the lower limit will be set to MIN, and all values less will be set to MIN. No need to get the actual value.
Given an array of 100 elements, what is the fastest way to find the window of values to process, while skipping the ones we don't need to process? The result is a sorted array, with MIN values up to the start of the window, and MAX values after the end of the window. How to find the minimum set of values to process that are in the window?
I doubt there is any Perl module to do this.
Basic algorithm would be something like:
Start at the middle. Run the process on the middle element. If the value is below the minimum, all the array up to that value can be set to MIN, no process needs to be run for those elements. If the value is above the maximum, all the array after that can be set to MAX, no process needs to be run for those elements. If the value is between minimum and maximum, then store the value in the array.
Repeat this until you find all the values between the minimum and maximum, and try to run as few processes as possible.
If the min and max are 1 and 10, for example, and the final array looks like 0,0,0,...1,2,3,4,5,10,101,102,103... How do I process only the 1,2,3,4,5,10 entries and skip as many of the others as possible?
The runtime savings is the goal. There are 100 elements per array, and 12 arrays per set, and 5,000 sets.
any help appreciated, thanks, Bill P
In reply to Special binary search by olepi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |