Slowing Down Sorting Networks To Obtain Faster Sorting Algorithm

Slowing Down Sorting Networks to Obtain Faster Sorting Algorithms
Richard Cokt
Courant Institute of Mathematical sciences
New York University
toarmwdght). -Let C-be the comparisonanrespoadmg
*
peratorc. Ifcisessignedweigbtwwecoasidacto
have ban essigaedweight w also.
ABSTRACT
w-
a tedmique for using a p
a
l
l
e
l algorithm
for one problem to amstruct an effiaent serial algorithm for a
secoad problem. We give a gmeral method that rrims afaccor
'k adversary is obliged to resolve sufficiently many of
theweignted cornparispas so that the sum oftheweights
of the resolved ampmums is at least WR.
The game end,*the
sol'tiscomplete. maim ofthe
sortrz is to end the g a m quickly. Aturn amsists of ome move
of eerh player; we show the sorter CBll end the game in
O(logn+f(n)) turns. By 'sortiag on the network' we mean that
(2)
of O(l0gn) time (or more) for many applications of this tecbaique.
the sorter must resolve exactly those c o m p k m s that arise
whsn the network is used, and must follow the
of the
mnpsrisoaS created by the network (that is, if an output of
*
cunpnratorD is an input to amparator C , thmthe
at D must tm resolved M m the a m p i s o i x
1. I n i d d b n
We solve a somewbat unusual sorting problem optimaUy;
it is deacribedinsectilm2. Tbesortingproblemwasmotivated
by and derived from its application. "he application is an
i m p r o v m dMegiWs ingenious tectnrique p4l]W b k h we4
an eftidaa parallel a l g w i h for one problan to produce an
effident serial algorithm for a second jmblem. Some ofthe
ideas invdved in this tedmique were first presented in F16].
T h e ~ i d c a o f M e g i d d o ' s ~ q u e i s 8 1 ) f o n o w suppoPe
s.
a cutah problem A is solved in Tp timeunits on aP-pm%mr
enrmptsd).
wbesl playins the game, we assign wcigb to the colllparators accord@ to the follawiag rule. An active canparator
at depth j in the network is given weight 4-j. We prove the
fon0wiOginvariant.
Iamrm 1: At the start of the t+lst turn the active weight is
boundedby (3/4y-nn,for k 2 0 .
pllodt At the start oftbe first turn we haved2 active canparaton at depth 1, and all other comparators art inactive. So initieny the iwaSiant holds. For the tlvarirrnt to bold it is
dent to show that at earfr turn the active weight is rsduad by
m a d b . AlsosupposeaserialalgorithmforpblmAnmning in time T,auld b applied to desisniag a serial algorithm
for problauB with a Mmiag time of O(cT,), where essentially
the alpithm for problemB carries out earn step of the dgontbm for A, taking time C per step. By using the pardel alpritlnn forA 88 a serial algo&hmwewould obtain a serial alpritbmforB numingintimeO(cT$). Megiddoshowcdthath
many cases problem E can actually be solved in time
O(rnpl0gP), if P is not too large. ow; cantribubioa is to
reduce this time to O(CTp) in many cases. We d e s a f i
M e e i d d o ' s ~ a n d t h e i m p a o v e m m t i n d o n 3 . using
t h e i l n p m m ty we trim the Mmiag times of s e v d dgorithm9, whi&wedacribcin section4.
atleastonequarter. Wemwshowthis.
coasider an activecmpamor Fofwcight w , and=
poeethe-l=Pdw * coanperisonCisresolved.l[beaC
casea to be active, and up to two a q y a t o n ,
of weight
w/4, may become active. So the rcaolut~onof C reduces the
acdveweightbyatleastwR. LettheactiveweightbeW. In
one turn, we are@laraDtedthatthe comperisoPls resohyby
the adversary hsve coaibined weight at least WR. 'Ihus, m one
turn, the active weight is reduad from W to at amst 3W/4.
we MIW sbow that this pmcess tcmhata l - e m d l y
quidrly.
Lemmm 2: For kaS(i+1Rlogn), during the k+l* turn there
amno active ampatom at depth).
pllodt At the start d t h e k+lst turn thetotal a c t i v c w
~
is bnmded by (3/4YV+Ur'gl").d2 (by lanma 1). we note
(3/4)5 < 1/4. so w < (1/4y+"'s".d2 = (Y4y.m. wd 811
setive comparator at depur j herp weight (My. So tbac is no
sumcompmatar. 0
The game eaQ afta O(f(n)+lop) turns.
Raro After 5y(n)+l12logn) turns thae are no active amparatow(bylaMur2). 'Ibstis,alltheLxmprmm
*
-
255
0272-5428~84/0000/0255$01.00 1984 IEEE
@
computation and finding medians of sets of comparisons. The
resolved, so the sorting is complete. Hence the game ends after
O(f(n)+logn) turns. 0
: Lemma 1 depends on the fact that the outdegree of
ator is boundedby two. Lemalla 1 still holdswhea
e bound of two by any constant bound, if we
the weights appropriately. When we have arbitrq
out-dew it appears unlikely that lemma 1 holds.
overheads for running the parallel algorithm are O(P(n)T(n)).
In fact, as Megiddo o k e d , we can use a parallel algorithm
which runs in time T(n) in Valiant’s model M so long as the
overheads can be performed efficiently in a serial simulation.
To find the median comparison we use the fast median algorithm [AHU, pp.97-991, numing in time O(P(n)), yuming
ordering two comparisons takes time O(1). Snceeachtunewe
halve the size of the set of unresolved mmparisans, the time
taken to find all log(P(n)) medians that we need is elso
O(P(n)). So over T(n) parallel time steps we take time
O(P(n)T(n))to find medisns.
’bus the total running time of the algorithm for problem
3.
In general terms, figiddo’s technique provide8 a way to
search a partiaUy ordered space, of polynomial (or superpolynomid) size, witbut d
y constmcting the space (the polynomial may be large). Instead an implicit binary search of the
space is made. We use a sorting algorithm to guide this searrh
(Megiddo’s technique is not restricted to sorting algori-).
’ZLplCaly, a sorted order corresponds to a region of the space
being sewdpxi. So resolving a cornpetison in the sort
correspondsto reducing the size of the space in which a solution
is known to lie. As might be expected, a single canperiscm is
expensive; but surprisingly, for some probla, several amparisohs can be batched relatively cheaply. This leads Megiddo
to use a parallel sating algorithm to guide the sear&, for in the
semdhg algorithm he can batch the
that are performed simultaneoudy in the parallel algmthm.
More precisely, suppose we have a fast parallel algorithm
for one problem, problem A say, whim is used to construct a
fast serial algorithm for a second problem, problem B my.
Further, suppose problemA is sorting and pmblemB has the
following unusual features.
Problem B am be solved by ‘sortixlg‘ but
‘amparison’ & expensive, that is it takes time C(n) rather than
B
is
O(P(n)T(n) + T(n)C(n)logn).
Typically,
P(n)=O(nlogn),
T(n)=o(logn)
[PI, or P(n)qO(n),
T(n)=(logn) [AKS]. (In the latter m e the constant IS very
large.) When C(n)=O(n) (O(n1ogn) rwpec.) each of thae
sorting algorithms gives an algoritbm for problem B runningin
timeO(nlog2n) (O(nlo$n) respec.).
Our improvement is to trim a factor of logn from thew
running times. We use the network of [AKS];instead of paforming the comparisons as described above, we play the game
a b e d in section 2. We have to provide an adversary,whicb
we do as follows. When the adversary is required to resolve a
weighted half of the comparisons, we resolve the weighted
median comparison,which by (2) above immediately resolves a
weighted half of the comparisons. (Fiiding a weighted median
of n item takes O(n) time[RI.) It is easy to see the time taken
to play the game, apart from the CompariSQns, is O(n1ogn).
@he [AKS] network can be built in determiastic time
O(n1ogn) [AKS,Gc;I the constant is rather large, however.)
And since the depth of the [AKS]network is O(logn) we need
--
peaform only O(logn) comparisons. So for C(n)=O(n) we
time O(1). Typically C(n) is O(n) or O(nlogn),
If we &der m of these comparison^', Cl, Cm,we am
order the comgarisoas,C,(l)S . * * SC+p in &efollowingsense. (WethinkofacompariscmCasbehgthe
question ‘is c1<c27’, which has answer e i k ’yes’ OT
‘no’.) An answer of ’yes’ to Cry) farces C,(l),...,C,y-lto
)
have answer ’yes’,while an answer of ’no’ to CTU)form
C,y+l ,...,C,,) to have answer ‘no’. Also we can determine
rehave & of two compariscms fairly m y ,
typically in time O(1).
Megiddo does not describe his technique as applying to such
problems for it is more general, and in fact so is our impe
ment. Nonetheless, we use this formulation both for simplicity
and h u s e many of the problems we consider have this form.
NW we desaribe how Megiddo solves problem B and then we
explain OUT imprcwement.
: Megiddo’s technique is more general than OUT
unprovment. That is, there are problem to whi& Megiddo’s
tedmique can be applied, but to whi& our improvement cannot
be applied.
!Suppow we were to use a standad efficient sorting algorithm (running time O(n1ogn)) to solve B . Then we would
obtain an algorithm with runuing time O(nlognC(n)).
Megiddo’s idea is to use a parallel sorting algorithm, using P(n)
peessun and parallel time T(n).
Stepofthe
parallel algorithm we have up to P(
to resolve.
...,
have a running time of O(nlogn), and for C(n)=O(nlogn) a
running timeof O(nl0g2n).
In several of the applia%ms problem A is not sorting;
instead it it the problem of finthe minirnum or of finding
the median. Here Megiddo would use algorithms having
OQoglogn) [v,svJ and O((l0glo&In)t) [crl parallel steps,
respectively, and using O(doglogn) and O(n) pmceasots,
respectively.
lhese yield
running
times
of
O(C(n)loglognIo n R)
and
O(C(n)(logIogn) Iogn n(loglogn)2), respectively, for problem B . Instead,by using a sorting algorithm we achieve a running time of O(C(n)logn + nlogn) for problem B, in bath
cases. (Note: we are making no assumptions about the size of
C(n), though for all problems considered so far C(n) 2: O(n).)
In practice another appmachcanbetaken. nere are probabilistic parallel algorithms, running in constant time on O(n)
pmceasots, for f
i the minimum and the median [ReJ.
Using these,and applying Megiddo’s tedmique, we would solve
problem B in O(C(n)logn+n) probabilistic time. ’be W t m t
is mucb smallex than the one for the algorithmdescribedinthe
previouS paregraph, and in addition the algorithm is d k ably simpler. (I
am indebted to hbgiddo for drawing this to
my attention I &dlrefer to this as Megiddo’s probabilistic
impr0V-t.)
the
f ++
--
4.
Instead of waluatiq them one by
themsdiapt
”his immediately resolves half the comparisons. We
We discuss several algorithms to wbich we have applied
improvements.
nley
Bty:
drawn
from
[M1,M2,M3,M’B,csr].
To give the m d m a better under*s
of the mothod we describe one algorithm in &etail:
log(P(n)) tima (=O(logn) typically) and we thereby
reeolve d P ( n ) ampadms. So we wbieve a numing time of
O(T(n)C(n)logn) plus overheads for running the paranel
these
256
Chsi& the f i t ?la comgarisons in the algorithm for
finding the farthest pints fromp; they determine at most n
finding the weighted I-center (problem 1, below). Our descrip
ti0118 of the other algoriare brief. TO fully underetaad
& of these algorithms the rearter should refer to the
solution (given in the -ate
refemme).
pointsonL. Webeginabinarymtodeterminebetween
whirh two of these pointsp lies; actually, we just perform the
first two steps ofthis search. so we either findp orwe &er.
mine that p lies in a segment not holding 3n/4of these points.
In the latter case we resolve at least n/4 of the ampmims,
and therefore determine that at least n/4 points are not amoq
the farthest points from p . This takes time O(n). We nuw
seek the farthest point(s) from aamg the leanaining at most
3n/4points; so the total running time is O(n).
To determine on which side of a circle C the center lies,
we instead show how to solve the more general problem of
determining on which side of a closed cwcular arc C the center
lies. Adosed circular arc is the perimeter c[msistiDg ofthe arc
and the straight line pining its two endpoints (the botrnding
line). We maintain the following invariant.
Ether we have determind on wfdm side of the dosed
cirarlar arc C the center lies, or we have determured
'
a
subarcC'ofcsuchthatthecenterliesonthesamesi&
1) wdghtul Eldidam 16mter RQbklIl w,mM31. In this
problem we are given a set X of n points (a,&,), i = l , 8, in
the plane, e g ~ ha with positive weight w,, and we seek a point
(xa)
so
as
to
d(x,y) =
max(wl[(x-~~,)~
+ (y-bJZ]lR: i = l ,...,n}. Me$iddo gives two
so1utions: one with running 0(n@ogn)~~oglogn)3
W,mI,
aad one with running time O(nlop2.) Fa]; we improve the
latter solution, obtaining a running time of O(n1ogn). Megiddo
obtain a probabilistic algorithm with
sad
...
time O(n1ogn).
our so~utionis based on integrating the ideas of W,M3];
the only new part is in theuse of OUI improvement describedin
the previous section. Nonethelap, we thiak it worth spellins
out the algorithm to aid the reader in understaading these tach.
mw.we describe the solution in four stages. First, a
to determine whether a given point is thecenter.
!&?anda, method, which given a line L, deterrmnes
'whether
the center is on L,to the left of L,or to the right of L. 'Ibitd,
a mahod, which given a &de C, detenmines whether the
is on c, inside c or outside c. And fourth, amethod to
findthecenter.
if ( x y ) is the center we complte the
To dewmum
*
poiat(!) i n x fasthest from ( x y ) . If this is a unique poiat then
(x,y) is not a center (for by moving
towarQ this
point we reduce the maximurn distaace from the candidate
center).
there are several farthest points, ( x j ) is a center if
and on~yif there is no straight lineL through (x,y) suchthat alI
the farthest points lie strictly to one side of L. If thge is such a
ofCandofC'.
Initially c' = C. We aim to either obtain a subarc S=C' on
whim the farthest point(s) is (are) unique (S may be a single
point), or to find on which side of the closedckular arc the
center lies. We show how to do tbis in time O(n1ogn) and, if
the first case holds, how to deteraline on which side of s the
center h.
w e start by determhing on which side of tbe bouding
line for C' the center lies. If it is on the opposite side to the
circular arc we have answered the query;otherwisewe coatirme.
As above, we seek the farthest point(@ in X from some point
on S. We use the same treebased parallel algorithm as above.
b L , then the cutter is on the same side o f L as the farthat
points. lhis test can be carried out in timeO(n).
To determine on which side of a lineL the center lies we
Ea& amqxuim of two pointspl andp, determines a M e
Cu,suchthatp,isthefarth~pointononesideofCl2,andp2
is the farther point on the other side of .
,
C C12intemcts C'
in at most two points, determining at most three subarcs on C';
the subarc to which we restrict our attention detennines the
result of the comparison.
Let D = qrs be a drcular arcamtahg S. We show how
to dctennine either on which side of D the center lies or whicb
of the subarcs qr and rs contains S. Let L, andl;, betheinfinite lines supporting the bounding lines for qr and rs, respectively. We determine on which side of L, and L, the center
lies, in time O(n). 'Ihere are four possible outcomes, & of
whidl implies one of the following (seefig.2):
(a) the cent er is outside^
(b) thecenterisinsideD
(c) qr amtaixm s
(a) rsamtainss.
We nea show how to resolve mu2 of m (zW2) complais0118 in time O(n). "he m comparisolrs determine up to 2m
points on the aTc c'. Let q ancl s be the Qldpoints of c',and
let r,, r2, and r3 be the quartiles and the median of the 2m
points (when C' is traversed from one endpoint to the o w ) .
By applying the method of the previous paragraph twice we
either determine on which side of C' the center lies or we
detamine which subarc among qr,, r,r2, r f 3 , r3s contab S. In
the latter CBSes the subarc C" containing S holds only nJ2 of
the 2m points; so on C" (and hence on S) the outcome of at
leest nu2 of the mmparisons is detemuned
*
. Wenowma
OUI attentionto C".
seekthepointp on,L.rnhimaq d b ) . Ifpisnottbecenter
there are two possibllltles. one, the farthest point@ fromp is
(are) on the same side of L,in whidl case the center is on that
side a b . h,
the farthest points fromp areonbothsiWof
L (seefig.1). SincepisthepointonLmhimiz&thefunction
d( ), there are farthest points to both sides of J , the perpew&
ular t o L throughp. Let K be a line throughp such that the
farthest points are on the same side of K (there is such aline
since p is not the center). Without loss of generality, assume
the fasthest points are all above K and that K s
m
l downwsrd
as shown in Q.1. Let q be a farthest point, below J . "%e
center is no farther frm q than isp; that is, the center lies in a
cirde with center q , radius qp. But the center also lies above
we deduce the center is to the light of L (see fig.1).
So we seek to find the point(s) inX farthest fromp. To
do this we use a parallel algorithm the natural tree based
w
h
t
m running in time OQogn). When ampring two
Polntspl d p 2 we determine adrde (or if they have the same
weight a straight line) s u d ~thatp, is the farhex point on one
side of the drde audp, is the farther point on the other side.
Ihecirdeintemm L in at most two points, determiningthTee
~
t
s TO
. determine whim of p i andp, is farther fromp
we have to decide on whim segmentp lies.
Next, we describe how to &t&Whetbcrp
is to the
left or the right of a point q o n L . We determine the farthest
potrt(s) at q. If q is not the center let K be the perpendicular
to L m a : if the farthest point(s) lie stridy to one side of
K,p lie^ on this side aleo, otberwiseprq. 'Ibis teat takesO(n)
--
time.
251
ame similar to that of section 2, in O(logn)
turns
a amstant number of 'comparisons', we
eitheJ. d e w on which side of C the center lies, or we find a
subarc s of c, together with the farthest pOint(s) froan s, such
that the m t e r is on the same side o f S and of C, and the
farthest points from any point onS are the same. In t h e m e r
case if the farthest point is at the center of c wededucettre
centex is inside C; otherwise, letp be the point ons n+nizhg
the function d( ). It can be found in a further O(n) tune. Let
L be the tangent toS atp. We claim the center cannot lie outside S and between the tangent and the semi-infiate extension
of the bounding line for S, which touches the tangent (see
on whidl side o f L the center lies,
of the dwular arc the centex lies.
(nlogn).
p l o a d t d clslm: & q m e the center lies between S and the
tangent. LetKbethelinepiaiagthecentertop. Wenote
that as we traverse K from the center towardsp the value of
the fulletion d ( ) is strictly ilmashg. But ir avwsess befm
r y h i n g p ; tbis contradictsp being the minimum of the fulD
t~on
d( ) on S. D
P Pow in tbe ccntcr in 2 l)hemkm [csyl.. A
a set of n points has the property that any l
m
tbrrmgh it has at least rnnl-1 points to ~ t h e rside. [cxq
fugtsolvetheproblemB,ofdetenniniagonwhi~sideofa
straight line the center lies, in tinre O(nlog%). Their solution
uses a parallel sorting algorithm, with C(n)=O(nlogn). Our
method improves the O(nlo$n) to a time of O(nlog2n). [Csy]
nest solve B,, a second sorting problem; the solution u ~ e sa
parallel santing aIgorithmwithB, used to resolvecomparisolls.
We save rmDthet tactar of Ooogn). So we solve Bz in time
O(nlog%) tathed than O(nl$n).
B, dominates the NMljng
-,
P k
9
it has at least fn/41-1
points to either side. The algonthm IS similar to the one ebove. [csy1first solve t h e w
lemB,of'
on which side of a plane the center W,
their solution uses n parallel sorting algorithms, running in
parallel, with C(n) = O(n3ogn). Using essentiany the soIution
for problem (2) they achieve a running rime of O(n34n);
the improvements described in (2) we reduce this to
O(n d n ) . [csr]also solve B,, R second sorting problem; we
gn) here, too. So we redwe the n d n g
""s
FhaUy, we describe how to find the center. Again, we
seckthefartheatpointsfromthecenter. Weusethesame
trebbesed dgorithm as above. When cornparinstwo points we
obtain a &de C (if the points have the same weight, a straight
he), and to resolve the comparison we have to determk m
wbkb side of the circle the center lies.
We show how to resolve n/4 a m q nR c o m p ~ ea,&
ah a horizontal strip in
no two circle boundsrieg
intersect. We achieve this by 'sorting' the d e boundaries.
We divide each &de into its left and right halves (by splitting
to O(&og%).
P r o b NI. A pi~allefsorting alge
the edges of the graph with ewh colllpariscw costing O(E1og"v) ( a compraison consists of finding a
minimum spanning tree Viilidl can be done in time O(Elog*V)
Megiddo obtains a running time of o(E@~v)~o$v)
aad OUT impmvemeat yields a naming time of O(ElogVlog v).
(in fact, in
a bwnd of O(E(logv)zlogbg
that timethe best algorithm fm the minimum
in tiane O(EloglogV).)
@A
Protbm
A pallel sorting algorithm is
used, with each armpan'son
O(n1ogn). So Megiddo
obtains a running time of
) and our improvement
m).
m]
the && with the vertical diameter). 'Ihenwe 'sort' the n semicircles using the [AKS] network. How do we -''
twa
dcircles? Let L, and L, be the horizontal lines through the
interseaions of the two semicircles,if any. A comparisoa
w].
reduQs to
on which side of L, andLz thecenter
lies. So a comparison takes O(n) time. U h g Megiddo's techand our improvement we 'sort' the d & e s in time
O(n1ogn). When we have f d the sorted or* we will also
have found the requiredhorizontal strip.
By determining for two left semicircle boundaries on
whidi side the center lies we can determh to which side
(kftkight) of 3n/8 left boundariesthe center lies (out of n/2 left
boundaries); with two more computations we can determine to
whim side of 3n/8 right boundaries the center lies. Together,
these determine for at feast n/4 &des whethg the ceslted is
inside or outside of them. Each c o m p a r i s o n m m to
such a &e is thereby resolved. So we deterinine that at least
d 4 points are not among the farthest points, in time O(n1ogn).
we continue the search among the remabg Rt most 3d4
we find the farthest points in time O(n1ogn).
w].
Theproblmis
to find a cyde in a network with edge costs and edge times,
such that the ratio of the total cost to the total time of the
edges on the cycle is minimized We improve h4egiddo's
N0.2
p.8581. He uses a parallel algorithm to
find the mirrimum of V items, each comparijson
O(T)
time. 'Ibis algoxithm is iterated Ooogv) tunes, tdmg tme
O ( V 3 ~ ~ ~ + ~ ( l o g ~ ) 2 1 0 goverall,
l o g v )where o(v3iqv) is the
tulle fm computations other than comparisons. Instead we use
a sorting algorith to find the minimum; : o m with our
improvement of Megiddo's tmhniqw this reduces the running
timeto O(v31ogv+Ev(logv)~.
We could apply h4egiddo's probabilistic improvement
instead to obtain a probabilistic algdthm for this problem, having the same nmhg time as above, but witha W e r a m -
W,
w.
a v e n the farthest points, in time O(n) we deteiminethe point
@distant from them; it is the center. 'Ihus, we find the
ein time O(n1ogn).
2) The HpmShmhvkh lIli3Qre.mtn 2 Mmensions [CmJ.In the
discrete ham sandwirb theorem we are given a set of n blue
points and a set of n red points, and we are to find a straight
line dividing both sets into equal sized halves. The algorithm in
[csyl uses a parallel algorithm for f i i medians, with
C(n)=O(n). So it runs in time O(nlogn(logn)?.
Our
improvement yields a running time of O(n1ogn). If the two
sts can be separated by a straight line the problem can be
solved in linear time w4].
.
Stamt.
8) k - l b l h
--k
P ~ K BP ~I B
. ~'Ihe problem
is: given a tree T with n edges and a m e g a t i v e weight associatedwith each vertex, delete k edges of T so as to maxim&
the weight of the lightest of the resulting subtrees (formed by
the remsiniagedges). Megiddo solves the partitioning problem
for a path in time O(nlog2n); his solution requires n binary
semcks to be done in parellel on R set of n items, where earh
takes time O(n). 'While this is not a sorting dgo.
ntlrm, we can still apply the method of section 2 and obtain a
game that requites us to make just O(logn)
usiag this game we solve the partitiproblem for a path m
.-
258
solely the a u k ' s respoapibility.
time O(n1ogn). Ihe partitioning problem for a tree is solved
reausively, upine the salutioa to the path partitionhg problem
to put the pieces tog&,
Megiddo obtains a running time of
Bcdaanar
k Aho, J. Hcpmft, J. ullmrm, Ibe Design and
Analysis of complter Algorithm, Addison Wesley,
O(nlog%); OUT i m p r o v of
~ the path partiticmjag algorithm
hthe n&ng time to O(n*n).
D.Johasoa has found an alternative solution to the patb
peatitioning problem running in time O(n1ogn) [Ms]; this also
yields an O(nlog%) solution to the tree partitioning problem.
9) pccntcr problmg pml]. see prn] for the problem
&finition. Their solution is built on a wuching problem
desaibed in the appendix of N I . It has two phases: a sorting phase and a series of n binary searches running in paraUd.
For botb of thGse the ampubom take O(n) time. We apply
the method of d o n 2 to the sorting phase and the improve
ment desceibcd in (8) above to the binary searches, this teduces
their running time of O(nlop2n) for the suu&ing problem to
O(n1ogn). As in (8), the continuovs p e n m problem is solved
recursively, using the solution to the seading problem to put
thepieastogethr. Again,Megiddoobtainsarunniugtimeof
o(nlog%) for finding the continrcorrs pcenm; our improvemem
to the algorithm for the seardhg problem reduces this to
O(nlOg2n).
Remark V i [vi] has found a method for doingn binary
rreerches in parall& it is as follows. Let L be the list of item
b d q Jearched and let M be a sorted list of the item being
sougM. M and L are merged using Valiant's parallel algorithm
M. It rum in O(log1ogn) parallel step. One could apply
Megiddo's tedmique to this algorithm, but not OUT improve
ment. For both problems 8 and 9 this would yield slightly
1974.
M. Ajtai, J. Komlos, E. t3mmmd1., An O(nl0gn)
sorting N ~ ~ w oSIGACT,
I~,
1983,pp.1-9.
RCole, U Sbarkr, C. Yap, On k-hulls and Related
problrms, SICK, 1984.
M. Fredmen a d R. Ta~jan,Eibonacd Heaps and
their Uses in Improved Network 9ptimizetion
rithms, manuscJpt.
0. w
bfz and z. w, Explicit c4mstruction of
Linear size superamcentratars, Foes, 1919,
pp.364-370.
N. Megiddo, Applying Parallel Canputatkm Algaridnus in the &&n of Serial Algclritbms, JACM, 30,
4(1983), PP.852-865.
N.M&ld~, The Weighted Euclidean I-Center Roblem, Math. O p e . Res., 8,4(1983).
N. Megiddo, Linear Time Algorithms for Lineaa Rog
~ in R3m
Snd W t e d El.oblrms, SlAM J . Cmp a . 12(1983), ~p.759-776.
N. Megiddo, Partitioning with M Iines in the
mane, marmsaipt.
N.Wgidrb, private cammunication.
N. Megiddo, combinatorial Optimkation
slowadgorithm5.
with
Rational Objective Functiohp, Maah. Oper. Res.
4. phrthcommrkl
We amment now on the efiiciency of the algorithm
dwcribcdabove. Inallthe problemsaboveweneedtousethe
sorting algorittun based on the [AKS]network. This hes a v q
laTge amstant making these algorithms imprectical. However,
we could implement the [AK!JJ network probabilisticany aad
then the constants bearmelessumeesonable, while theonlmof
thecxpcckdrumriagtimeisuncbanged. Inaddition,whena
median is required, as a rule an approximation to the median
will suffice, 80 if we are using a probabilistic algorithm we can
take a random item instead. This may not improve the otda
of the runtime,but in practice it will result in a simplet aad
more efficient algorithm. Also, we could apply Megiddo's ptobabitistic i m p f o v ~ t *
unfortunately, we cannot apply out impnrvemart to tbe
sorting algdtbms of Valiant M or preparata [PI for these do
not yield sorting networks of small enough depth. An & a t
pard4 sorting algorithm (O(4 proassors, o(lW4 Nfm"1g
time), with bounded fanout, would enable all the algondnus
W b c d above to be implwneated more effiaently.
We believe that other searrbing problems, parhlarly
those with a gmmed& flavor, will beaefit from epplyias tbssc
techniques.
4(1979), pp.414-424.
N. M~giddoesld AT&, N ~ wb u l t s 011 the Camplcxity of p&&
Problems, ,%&UJ. C-,
12,
4(1983).
N. Megiddo and E. zemel, An O(n1ogn) Randomhing Algorithm for the weighted Eudidcan l-anter
Problem, M a n d p t , !Stanford W v d t y .
F. Preparata, New Fa~alldSortiag sdremes, lEEE
ItonS. Canput.,G27(1978), pp.669-673.
A Reisra, ALinurr Setecdm Algorithm for Scts of
Elementswith Weights, ZPL 7(1978), pp.159-162.
R Reischuk, A Fast Probabilistic Sorting Algorithm,
FOCS,1981,pp.212-219.
L. ValiImt, Parallelism in amparbm probkms,
SUM J. Compnt.,4(1975), pp.348-355.
U.V i ,private ammunication.
Molarlcdsemme
It is a pleasure to scknowledge the c o n v d o n s I had
with Mima sbarir at the start of this work. He contributed to a
pmhe definition of the problem. Also, I am grateful to cad^
of zbi V
i and N i i Megiddo far arrrfunyreadiqs the
pqw nad mnk+ sIl&gpt&3 wtdcb led to ooaoidcrabk;
improvements in the presealtation. Any lmmhing emom w
259
L
% k
\
260