Optimal Solution
11.5.4 Optimal Solution
In this section we describe an optimal parallel algorithm for computing the convex hull. The algorithm is designed to run on an EREW SM SIMD computer with N =
processors,
z 1. As before, each point
of S = {p,,
... , is
given by its Cartesian coordinates and we continue to assume for clarity of presentation that no two points have the same x or y coordinates and that no three points fall on a straight line. A high-level description of the algorithm is first presented.
Let XMIN and XMAX denote, as before, the points with minimum and maximum x coordinates, respectively. As Fig.
11.13 illustrates, consists of two parts: an upper convex polygonal path from XMIN to XMAX (solid lines) and a lower one from XMAX to XMIN (broken lines). Given these two polygonal paths, they can
be concatenated to yield The algorithm is given in what follows as procedure EREW CONVEX HULL. It takes the points of S as input and returns a list
of the vertices of
in the order in which they appear on the convex hull of S.
XMIN
Figure 11.13 Upper and lower convex polygonal paths.
11.5 A Construction Problem
EREW C O N V E X H U L L ( S , Step 1 :
(1.1) xmin index of XMIN in (1.2) xmax index of
X M A X in S.
Step 2: list of vertices on the upper convex polygonal path from to Step 3:
list of vertices on the lower convex polygonal path from to Step
followed by list
This procedure as described is rather vague and requires a good deal of refinement. We can dispose immediately to steps 1 and 4. Step 1 can be implemented using procedure PARALLEL SELECT, which, as we know from chapter 2, uses processors and runs in
time. There are two operations in step 4: deleting the first and last elements of
and linking the remaining ones with Both can be performed in constant time by a single processor. This leaves us with steps 2 and 3. Clearly, any algorithm for step 2 can be easily modified to carry out step
3. We therefore concentrate on refining step 2.
Finding the Upper Hull. An algorithm for constructing the upper convex polygonal path (upper path, for short) can be obtained by making use of the following property: If a vertical line is drawn somewhere between
and so that it does not go through a convex hull vertex, then this line crosses exactly one edge of the upper path. The algorithm first places a vertical line L dividing S into two sets
and of approximately the same size. The unique edge of the upper path intersecting L is now determined as shown in Fig. 11.14. This edge is called a bridge (from
to The algorithm is then applied recursively to
It is interesting to note here that like procedure SEQUENTIAL CONVEX HULL this algorithm is based on the divide-and-conquer principle for algorithm design. However, while procedure SEQUENTIAL CONVEX HULL divides, conquers, and then merges, this algorithm divides (into
and
merges (by finding the bridge), and then conquers (by recursing on
and
and
Ideally, in a parallel implementation of this idea, the two recursive steps should
be executed simultaneously since each of the two subproblems and has the same structure as the original problem S . Unfortunately, this is impossible since the number of available processors is not sufficient to provide a proper recursive execution of the algorithm. To see this, note that each of
and contains approximately
points and thus requires processors. This is larger than the processors that would be assigned to each of
if the two recursive steps were to be executed simultaneously. Therefore, we resort instead to a solution similar to the one used in the case of EREW SORT in chapter
and
4. Let k = First,
2k - 1 vertical lines L,, L,, . . . ,
are found that divide S into 2k subsets
i = 1,
2, . .. , 2k of size
each. These subsets are such that
and
uu
Computational Geometry Chap. 11
Figure 11.14 Bridge.
In the next step, edge (a,, of the upper path that crosses vertical line
i = 1,
2,. .. ,2k - 1, is obtained. (Here both and are elements of we use a and b instead
of p to avoid multiple subscripts.) The algorithm is now applied recursively and in parallel to
processors per subset. The same is then done for
S,, ... , using
... , S,,. The algorithm is given in what follows as procedure UPPER
HULL. The procedure takes the set S and two points p, and p, as input. It produces the upper path from p, to p, as output. Initially, it is called from procedure EREW CONVEX HULL with =
and p, =
procedure UPPER HULL ( S ,
p,)
if 2k
then find the upper path from p, to p, using SEQUENTIAL CONVEX HULL
else
find 2k-
1 vertical lines
L,,. ..,
that divide into
( 2 ) for i =
1 to 2 k - 1 do
find edge (a,, of the upper path intersecting line
end for
(3) {Construct upper path for
(3.1) if p, = a,
then p, is produced as output else UPPER HULL (S,, p,, a,)
11.5 A Construction Problem (3.2) for j = 2 to k do in parallel
if
then
is produced as output
else if
then UPPER HULL
end if end if end for
(4) {Construct upper path for
(4.1) for j= k + 1 to 2k - 1 do in
if
then
is produced as output
else if
then UPPER HULL
end if end if end for (4.2) if
is produced as output else UPPER HULL
Step 1 can be implemented using procedure PARALLEL SELECT. Steps 3 and
4 are recursive. It remains to show how step 2 is performed. The following procedure BRIDGE (S, A) takes a set S of n points and a real number A as input and returns two points
and where is the unique edge of the upper path intersecting the vertical line
whose equation is x = A.
procedure BRIDGE (S, A)
Step 1: The points of S are paired up into couples (p,, p,) such that The ordered pairs define
straight lines whose slopes are
Step 2: Find the median K of the set { s , ,
Step 3: Find a straight line Q of slope K that contains at least one point of S but has no point of S above it.
Step 4: if Q contains two points of S, one on each side of return these as (a,, b,) else if Q contains no points of then for every straight line through (p,, p,) with slope larger than or equal to K
else if Q contains no points of then for every straight line through (p,, p,) with slope less than or equal to
end if end if end if.
300 Computational Geometry Chap. 11
now describe how this procedure is implemented in parallel and analyze its running time, which we denote by
Step is performed in parallel by assigning different subsets of S of size n z to the
processors, each of which creates pairs of points (p,, p,) and computes the slopes of the straight lines they form. Step 1
thus requires O(n z ) time. Step 2 can be implemented using procedure PARALLEL SELECT in O(n z ) time. Step 3 is executed by finding the (at most two) points
maximizing the quantity This quantity can be obtained for all values o f j by having each processor compute it for the points in its assigned subset of S. The maximum of these quantities is found using procedure PARALLEL SELECT. Hence step 3 also runs in O(n z ) time. Finally, in step 4, determining whether Q contains the required edge can be done by one processor in constant time. Otherwise, the value of
time using procedure BROADCAST. Each processor compares K to the
is broadcast to all
processors in
slopes it has computed in step 1 and updates S accordingly; this requires
time. Step 4 therefore runs in O(n z ) time. Since one-quarter of the points are discarded in step 4, the complexity of step 5 is
Thus, for some constant
whose solution is = O(n z ).
Analysis. We are now in a position to analyze procedure EREW CONVEX HULL. As mentioned earlier, steps 1 and 4 run in O(n z ) and
time, respectively. Let h, and
be the number of edges of the upper and lower convex polygonal paths, respectively. We denote the running times of steps 2 and 3 by
h,) and respectively. Thus, the running time of procedure EREW CONVEX HULL is given
h,) + h,) +
for two constants and From our discussion of procedure UPPER HULL, we have
where h,, h,, and are the number of edges on the upper path associated with and
respectively, and
is a constant. Therefore
and similarly
log
It follows that = O(n Z log h), where h =
+ Thus the procedure's running
time not only adapts to the number of available processors, but is also sensitive to h, the number of edges on the convex hull. In the worst case, of course, h = n, and
11.5 A Construction Problem = O(n z logn). Since
the procedure has a cost of
= O(n log n),
which is optimal in view of the log n) lower bound derived in section 1 Since log n for all z and sufficiently large n, optimality is achieved when N
n.
Example 11.3
Assume that four processors are available on an EREW SM SIMD computer. We apply procedure EREW CONVEX HULL to the set of points in Fig. 11.13. Since n = 16 and N =
= 2. In step 1, and are determined. In step
4, N = yields x =
0.5. Furthermore, k =
2, procedure UPPER HULL is invoked to find the upper path. Procedure UPPER HULL begins by placing 2k - 1 three) vertical lines L,, L,, and
as shown in Fig. 11.15. The bridge crossing each vertical line is now computed by procedure BRIDGE. This is shown in Fig. 11.16. Since
dividing the set into four subsets
and
procedure UPPER HULL is called recursively to obtain the upper path from
4, the path is found sequentially (and the recursion terminates). Similarly, since b , = a,, there is no need to
to a,. Given that
with Continuing in this fashion,
is found equal to a,, and the upper path from to is
Figure 11.15 Dividing given planar set into four subsets.
Computational Geometry Chap. 11
Figure 11.16 Finding three bridges.
obtained sequentially. This yields the upper path from to depicted in Fig. 11.13. In step 3, the lower convex polygonal path is found in the same way, and the two paths are linked to produce the convex hull as shown in Fig. 11.13.