0% found this document useful (0 votes)
10 views

Geometric Seraching

Geometric search algorithms

Uploaded by

Shrishu Ranjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Geometric Seraching

Geometric search algorithms

Uploaded by

Shrishu Ranjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

GEOMETRIC SEARCHING

PROBLEM 1 (RANGE SEARCHING—COUNT). Given N points in the


plane, how many lie in a given rectangle with sides parallel to the coordinate
axes? That is, how many points (x, y) satisfy a < x < b, c < y < d for given
a, b, c, and d? (See Figure 2.1.)

Solution: It is clear that a single-shot range query can be performed in (optimal)


linear time, since we need examine only each of the N points to see whether it
satisfies the inequalities defining the rectangle. Likewise, linear space suffices
because only the 2N coordinates need to be saved. There is no preprocessing
time and the update time for a new point is constant.
Another Solution: we might replace the rectangle query by four subproblems, one
for each vertex, and combine their solutions to obtain the final answer. In this case
the subproblem associated with a point p is to determine the number of points Q(p)
of the set that satisfy both x < x (p), and y < y(p), that is, the number of points in
the southwest quadrant determined by p. (See Figure 2.2.)

The number N(P1P2P3P4) of points contained in rectangle P1P2P3P4 is given


by

N(P1P2P3P4) = Q(P1) — Q(P2) — Q(P4) + Q(P3)


PROBLEM 2 (POLYGON INCLUSION). Given a simple polygon P and a
point z, determine whether or not z is internal to P.
PROBLEM 3 (CONVEX POLYGON INCLUSION). Given a convex polygon
P and a point z, is z internal to P?
Plane-Sweep Technique:
Applications: Mostly used for intersection problem, triangulation and other order
problems.
Basic Technique: An imaginary vertical sweep line moves from left to right
across the objects.
Problem of Line Segment Intersection: Let L1, L2, L3,…,Ln be a set of n line
segments in the plane. We want to compute all their pair wise intersections.

Say, deployment of A Country Railway Network.

Problem: How many railway bridges are to be built in the crossing of rivers
and what is their locations?

L6

L5
L7

L3
L4
L1
L2

Brute Force Approach:


To check all pairs Li, Lj with 1 ≤ i <j ≤ n for intersection. It runs in O(n2) time.
Assumptions:
1: No line segment is vertical.
2: No two endpoints or intersection points have the same X-coordinate.
Y-structure: Stores active line segments ordered according to the y-coordinate of
their intersection with the sweep line.
L6
Type of line segments:
Dead: L1
L5
Active: L2, L3, L4, L5, L6 L7

Dormant: L7 L3
L4
L1
L2

L2, L3, L4, L5, L6 are active and are stored into Y-structure in this order.
• Y-structure is a balanced binary search tree. So, dictionary operations are in
O(log n) time.
• Leaves store the segments from left to right in descending order of y-
coordinates.
• Other node (root/intermediate) is the right-most leaf in its left-subtree.

L6 L4

L5 L6 L3
L7
L3
L5 L3 L2
L4 L6
L1 L2
L5 L4
X-structure: Contains all endpoints of line segments which are to the right of the sweep line.
Furthermore, it contains some of the intersections of the line segments to the right of the sweep
line.
The points in the X-structure are sorted according to their X-coordinate, i.e, the X-structure is a
heap.

5 8

2
3 7
1 6

Algorithm: (Line segment Intersection)


Y-structure Φ
X-structure  the 2n end points of the line segments sorted by X-coordinate
While X-structure ≠ Φ do
Let p be a point with minimal x-coordinate in the X-structure. Delete p from X-structure
If p is a left end point of the some segment Lj then
Search for p in Y-structure and insert Lj into the Y-structure
Let Li , Lk be the two neighbors of Lj in the Y-structure; insert (Li , Lj) and (Lj, Lk)
into the X-structure if they exist;
[Delete (Li, Lk) from the X-structure]
Endif
If p is a right end point of some segment Ljthen
Let Liand Lkbe the two neighbors of Lj in the Y-structure;
Delete Lj from the Y-structure.
Insert (Li, Lk) into X-structure if the intersection is to the right of sweep line.
Endif
If p is (Li, Lj) then
Li, Lj are necessarily adjacent in the Y-structure;
Interchange Li, Ljin the Y-structure.
Let Lh , Lk be the two neighbors of Li, Ljin the Y-structure.
Insert (Lh, Lj) and (Lj, Lk) into X-structure if they are to the right of sweep line.
[Delete (Lh, Li) and (Lj, Lk) from the X-structure;]
Output p
Endif
End While
Time Complexity: O(n log n) as sorting is the dominating computation.
An Illustration:
7 9
c
2 6

4
5
a
1 b
8

(3) (5) (6) (7) (8) (9)


(2)
(1) (4
)
IntitializationY : Φ & X: 1, 2, 3, 7, 8, 9
1) Y: a & X: 2, 3, 7, 8, 9
2) Y: ab & X: 3, 4, 7, 8, 9
3) Y: cab & X: 4, 6, 7, 8, 9
4) Y: cba & X: 5, 6,7, 8, 9 & Output: 4
5) Y: bca & X: 6, 7, 8, 9 & Output: 4, 5
6) Y: bac & X: 7, 8, 9 & Output: 4, 5, 6
7) Y: ba & X: 8, 9 & Output: 4, 5, 6
8) Y: a & X: 9 & Output: 4, 5, 6
9) Y: Φ & X: Φ & Output: 4, 5, 6
Determine whether any pair of line segment intersects

 Problem: Given a set of segments on a plane, determine whether any two line
segments intersect.
 Assumption 1: No input segment is vertical.
 Assumption 2: No more than two input segments intersect at a single point.
 Ordering segments: Order the segments that intersect a vertical sweep line
according to the y-coordinate of the points of intersection.

Algorithm Segment Intersection

Step 1. T = Φ
Step 2. Sort the endpoints of segments in S from left to right, breaking ties by
putting points with lower y-coordinates first.
Step 3. For each point p in the sorted list of end points do
(a): If p is the left end point of a segment S then
INSERT (T, S)
If (ABOVE (T, S) exists and intersect S or (BELOW (T, S)
exists and intersect S then
return TRUE.
(b): If p is the right end point of a segment S then
If both ABOVE (T, S) and BELOW (T, S) exist and ABOVE (T, S)
intersects BELOW (T, S) then
returnTRUE
DELETE (T, S)
Step 4. Return FALSE.
Time Complexity:
Step 1 takes O(1) time.
Step 2 O(n log n ) time.
Since there are 2n event points, for loop takes at most 2n iteration. Each iteration
take of (log n) time.
Therefore the for loop takes O(n log n) time.
Hence overall time is O(n log n).

An Illustration

a d e

c
f

a a a d d e
e
b c a c d
d
b c b c
b
b b
Exercise 1: Apply Plane sweep algorithm to determine whether any two line
segments intersect in the following graph.

L3

L2 L6
L5

L1

L4

You might also like