I need a very fast algorithm for the next task. I have already implemented several algorithms that complete it, but they are too slow for the performance I need. It must be fast enough so that the algorithm can run at least 100,000 times per second on a modern processor. It will be implemented in C ++.
I work with ranges / ranges, a structure that has a start and an end coordinate on a line.
I have two vectors (dynamic arrays) of spans, and I need to combine them. One vector is src and the other is dst. Vectors are sorted by the initial coordinates of the range, and spans do not overlap within the same vector.
The spaces in the src vector must be combined with the spans in the dst vector, so the resulting vector is still sorted and has no overlap. I.e. if overlaps are detected during the merger, the two spans merge into one. (The merging of the two spans is simply a matter of changing the coordinates in the structure.)
Now there is another catch, the spans in the src vector should be “expanded” during the merge. This means that the constant will be added to the beginning and another (large) constant in the final coordinate of each interval in src. This means that after expanding src extensions, they may overlap.
So far, I have come to the conclusion that it cannot be fully executed in place, some temporary storage is required. I think this should be done in linear time by the number of src and dst elements summarized.
, , .
, , , :
src dst, . . , , "" "", , , . ( ) dst .
. , , src dst . , dst, .
, O ((m + n) * log (m + n)) O (m + n) . , dst , .
/ .
, / /, , , .
: , . - 4 30 , dst , src dst.