If you assume that the point you want to query is evenly randomly selected along the bar, then you can have the EXPECTED constant time without a crazy memory burst as follows. If you split a bar into N equally spaced parts, where N is the number of source irregularly spaced segments that you have on your rod, and then write for each of N equal sized shapes that overlap from the original irregular segment (s), then for To complete the query, you first simply take the query point and do a simple round off to find out which uniformly distributed part it is in, then use this index to see which of your source segments intersects equally spaced portion, and then check each intersecting source segment to see if the segment contains your point (and you can use binary search if you want to make sure that the worst performance is still logarithmic). The expected runtime for this approach is constant if you assume that the query point is randomly selected along your rod, and the memory size is O (N), if your rod was originally cut into N irregular shapes, so there are no crazy memory requirements.
PROOF OF EXPECTED O (1) OPERATION TIME:
When you count the total number of intersection pairs between your original N irregular segments and N equally distributed parts that I propose to build, the total number is no more than 2 * (N + 1) (because if you sort all the end points of all regular and irregular segments , a new pair of intersections can always be charged to one of the end points defining either a regular or an irregular segment). Thus, you have a multi-set of no more than 2 (N + 1) of your irregular segments, distributed differently among the N regular segments that they intersect. The actual distribution of intersections between regular segments does not matter. When you have a single query point and calculate the expected number of irregular segments that intersect the regular segment containing the query point, each regular segment has a 1 / N probability selected by the query point, so the expected number of intersecting irregular segments to be checked is 2 * (N + 1) / N = O (1).
source share