Quantcast
Channel: segments – 100% Private Proxies – Fast, Anonymous, Quality, Unlimited USA Private Proxy!
Viewing all articles
Browse latest Browse all 10

Calculating number of intersections of a horizontal line with line segments efficiently

$
0
0

I’m given an array $ A = [a_1, a_2, ….a_n] $ using which I construct $ n-1$ contiguous line segments by drawing a line from $ (i,a_i)$ to $ (i+1, a_{i+1})$ . Now, I’m given $ q$ queries in the form of $ x_1, x_2, y, l, r$ where $ l$ and $ r$ are the range for the array $ A$ and the rest indicate a horizontal line segment $ L$ from $ (x_1, y)$ to $ (x_2, y)$ . For each query, I want to find total intersections of $ L$ and the segments in the range $ l$ and $ r$ in $ O(n+q)$ or $ O(n + q\log{n})$ complexity.
I was able to arrive at a solution that works in $ O(nq)$ which simply traverses each range and calculates whether $ L$ intersects with the segments or not.
I believe, some pre-processing can be done on $ A$ which can reduce the complexity.
Any leads will be appreciated!

The post Calculating number of intersections of a horizontal line with line segments efficiently appeared first on 100% Private Proxies - Fast, Anonymous, Quality, Unlimited USA Private Proxy!.


Viewing all articles
Browse latest Browse all 10


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>