You are on page 1of 6

A N E X P E C T E D - C O S T ANALYSIS O F B A C K T R A C K I N G A N D

NON-BACKTRACKING ALGORITHMS
C.J.H. McDiarmid G . M . A . Provan
Department of Statistics Department of Computer and Information Science
University of Oxford University of Pennsylvania
Oxford England 0 X 1 3TG Philadelphia PA 19104-6389 USA
email: MCD@vax.oxford.ac.uk email: provan@cis.upenn.edu

Abstract outcomes w i t h prohibitively high costs).


Let us review briefly the model and results of Karp
Consider an infinite binary search tree in which and Pearl [1983]. They consider an infinite search tree
the branches have independent random costs. in which each node has exactly two sons. The branches
Suppose t h a t we must find an o p t i m a l (cheap- have independent (0, l)-valued random costs X, w i t h
est) or nearly o p t i m a l path f r o m the root to p = P(X = 0). 1 T h e problem is to find an optimal
a node at depth n. K a r p and Pearl [1983] (cheapest) or nearly o p t i m a l path f r o m the root to a
show t h a t a bounded-lookahead backtracking node at depth n.
algorithm A2 usually finds a nearly optimal
The problem changes nature depending on whether
path in linear expected time (when the costs
the expected number 2p of zero-cost branches leaving
take only the values 0 or 1). From this suc-
a node is > 1, = 1 or < 1. When 2p > 1 a sim-
cessful performance one might conclude that
ple uniform cost breadth-first search algorithm Al finds
similar heuristics should be of more general
an optimal solution in expected time O(n); and when
use. B u t we find here equal success for a sim-
2p = 1 this algorithm takes expected time 0(n2). When
pler non-backtracking bounded-lookahead algo-
2p < 1 any algorithm that is guaranteed to find a solu-
r i t h m , so the search model cannot support this
tion w i t h i n a constant factor of o p t i m a l must take expo-
conclusion. If, however, the search tree is gen-
nential expected time. However, in this case a "bounded-
erated by a branching process so that there
lookahead plus partial backtrack" algorithm A2 usually
is a possibility of nodes having no sons (or
finds a solution close to optimal in linear expected time.
branches having prohibitive costs), then the
This successful performance of the backtracking algo-
non-backtracking algorithm is hopeless while
r i t h m A2 for the difficult case when 2p < 1 seems to
the backtracking algorithm still performs very
suggest that similar backtrack-based heuristics should
well. These results suggest the general guide-
be of more general use for attacking N P - h a r d problems.
line t h a t backtracking becomes attractive when
This paper shows that a simple non-backtracking
there is the possibility of "dead-ends" or pro-
bounded-lookahead algorithm .43 performs as success-
hibitively costly outcomes.
fully as the backtracking algorithm A 2 , on the basis of
this search model. Similar comments hold if we allow
1 INTRODUCTION more general finite random costs on the branches.
However, there is a qualitative difference if we allow
Many algorithms considered in operations research, com- nodes to have no sons (or allow branches to have infinite
puter science and artificial intelligence may be repre- costs) so that there are "dead-ends". We extend K a r p
sented as searches or partial searches through rooted and Pearl's work by considering search in random trees
trees. Such algorithms typically involve backtracking generated by a branching process, where the branches
but t r y to minimize the time spent doing so (e.g. [Bit- have independent random finite costs X. (This model
ner and Reingold, 1975; Brown and P. W. Purdom, 1981; includes the case of infinite costs—nodes would just pro-
Brown and P. W. P u r d o m , 1982; Dechter, 1990; Haralick duce fewer sons). In this extended model, let m be the
and E l l i o t t , 1980; K a r p , 1976; K n u t h , 1975; Nudel, 1983; mean number of sons of a node, let po be the probability
P. W. P u r d o m , 1983; Stone and Stone, 1986]). Indeed t h a t a node has no sons, and as before let p = P(X — 0).
for some problems it may be best to avoid backtracking Our results concerning algorithms Al and A2 are nat-
[de Kleer, 1984]. ural extensions of K a r p and Pearl's results. Thus the
T h e paper extends work of [Karp and Pearl, 1983], uniform cost algorithm Al finds an o p t i m a l solution in
and gives a probabilistic analysis of backtracking and linear expected time if mp > 1 and in quadratic expected
non-backtracking search algorithms in certain trees w i t h time if mp = 1. If mp < 1 then any algorithm w i t h a
random branch costs. We thus cast some light on the constant performance guarantee must take exponential
question of when to backtrack: it seems that backtrack-
1
ing is valuable j u s t for problems w i t h "dead-ends" (or We have swapped p and 1 — p from the original paper

172 Automated Reasoning


expected time, but the backtracking algorithm A2 finds [Karp and Pearl, 1983]. A l g o r i t h m A\ is a uniform cost
a nearly optimal solution in linear expected time. breadth-first search algorithm and w i l l be analyzed for
However, the performance of the non-backtracking al- the cases mp > 1 and mp = 1, when there are many
g o r i t h m A3 depends critically on the parameter po. Sup- zero-cost branches and search is easy. A l g o r i t h m A2 is
pose that mp < 1, so t h a t o p t i m a l search is hard. If a hybrid of local and global depth-first search strategies
Po = 0, so t h a t as in the K a r p and Pearl model there are and w i l l be analyzed for mp < 1. A l g o r i t h m A3 consists
no dead-ends, then a l g o r i t h m A3 usually finds a nearly of repeated local o p t i m a l searches, and will be analyzed
o p t i m a l solution in linear expected time; that is, it per- also for mp < 1. Note that A\ is an exact a l g o r i t h m ,
forms as successfully as the backtracking algorithm A2. whereas A2 and A3 are approximation algorithms.
However, if po > 0 then a l g o r i t h m A2 usually fails to find
a solution. Thus our model suggests t h a t backtracking For each algorithm Aj, we let the random cost of the
becomes attractive when there is the possibility of dead- solution found be C * J ' ( = if no solution is found), and
ends. the random time taken be T AJ . We measure time by the
number of nodes of the search tree encountered.
In the next section we give details concerning the
search model and the algorithms Al,A2 and AZ, and T h e three algorithms are as follows:
then in section 3 we present our results. Section 4 briefly
A l g o r i t h m Al: At each step, expand the leftmost
discusses the effect of noise on the algorithmic perfor-
node among those frontiers nodes of m i n i m u m cost. T h e
mance. In section 5 we make a few comments on proofs.
algorithm halts when it tries to expand a node at depth
n. T h a t node then corresponds to an optimal solution.
2 MODEL A N D ALGORITHMS
We suppose that the search tree is the family tree of a
branching process. For an i n t r o d u c t i o n to the theory of
such processes see for example [Harris, 1963; A t h r e y a
and Ney, 1972; K a r p and Pearl, 1983]. Thus the search
tree has a root node, at depth 0. Each node at depth n
independently produces and is joined to a random num-
ber Z of sons at depth (n+ 1). We shall assume that the
mean number m of sons produced satisfies 1 < m <
Thus the expected number of nodes at depth n is m n
and grows exponentially w i t h n.
T h e K a r p and Pearl model is the special case when
each node always has exactly two sons. On the other
hand our search model here is a special case of the more
complicated model considered in [ M c D i a r m i d , 1990], Figure 1: Operation of algorithm A2: The triangles rep-
namely an age-dependent branching process of C r u m p - resent local depth-first searches for L)-sons.
Mode type [Crump and Mode, 1968]. For such a model
the implications concerning backtracking are j u s t the
same. A l g o r i t h m A2: A l g o r i t h m A2 has three parameters:
Let q denote the extinction probability for the branch- d, L, and a. An ( L)-regular path is a path which con-
ing process, that is the probability that the search tree sist of segments each of length L and cost at most aL
is finite. Since m > 1 it follows t h a t q < 1. Let p 0 be (except that the last segment may have length < L ) . A2
the probability a node has no sons. Clearly q > 0 if and conducts a depth-first search to find an L)-regular
only if po > 0, and these conditions correspond to the path from a depth d node to a depth n noae. In other
existence of "dead-ends" in the search tree. words, A2 is a depth-first strategy which stops at regular
We suppose t h a t the branches have independent non- intervals of L levels to appraise its progress. If the cost
negative random costs X w i t h finite mean. A simple increase from the last appraisal is at most a L , the search
translation allows us to assume w i t h o u t loss of generality continues; if that cost increase is above a L , the current
t h a t small costs can occur; t h a t is, for any > 0 we have node is irrevocably pruned, the program backtracks to
P{X < > 0. T h e distinction between zero and non- a higher level, and the search resumes. If it succeeds in
zero costs turns out to be i m p o r t a n t . We let p = P(X =
reaching depth n,A2 returns the corresponding path as
0) 0. a solution: if it fails, the search is repeated from another
T h e cost of a path is the sum of its branch costs. We depth d node. If all the nodes at depth d fail to root
want to find an o p t i m a l (cheapest) or nearly o p t i m a l
an (a,L)-regular path to a depth n node, A2 terminates
path f r o m the root to a node at depth n, for large n. Let
w i t h failure.
C* denote the random o p t i m a l cost of such a p a t h , where
C* = if there is no such p a t h . T h u s P(C„ q A l g o r i t h m A3: The simple bounded-lookahead or
as n The interesting case is when the search "horizon" heuristic is a staged-search algorithm which
tree is infinite, and we shall usually condition on this avoids backtracking. It has one parameter L. Starting
happening, so that almost surely C n is finite. at the root it finds an optimal path to a node at depth
We shall discuss the performance of three algorithms, L, makes that node the new starting point and repeats.
If L is a constant clearly A3 takes linear expected time.
A1,A2 and A 3 , the first two of which are taken from

McDiarmid and Provan 173


174 Automated Reasoning
McDiarmid and Provan 175
[ B r o w n and P. W. P u r d o m , 1981] C. A. B r o w n and
P. W. P u r d o m , Jr. . An average case analysis of
b a c k t r a c k i n g . S1AM J. Computing, 10 (3):583-593,
1981.

[ B r o w n and P. W. P u r d o m , 1982] C A. B r o w n and


P . W . P u r d o m , Jr.. A n e m p i r i c a l comparison o f
backtracking algorithms. IEEE Trans. PAMI, 4,
1982.

[ C r u m p and M o d e , 1968] K.S. C r u m p and C . J . M o d e .


A general age-dependent b r a n c h i n g process. Jour-
nal of Mathematical Analysis and Applications, 24,
1968.

[de Kleer, 1984] J. de Kleer. Choices w i t h o u t backtrack-


i n g . Proc. AAAI, 79-85, 1984.

[Dechter, 1990] R. Dechter. Enhancement Schemes


6 CONCLUSIONS for C o n s t r a i n t Processing: B a c k j u m p i n g , Learning
and Cutset D e c o m p o s i t i o n . Artificial Intelligence,
T h i s paper has studied the performance of b o t h back- 41(3):273-312, 1990.
t r a c k i n g a n d n o n - b a c k t r a c k i n g tree search a l g o r i t h m s in
finding a least-cost root-leaf p a t h in r a n d o m trees w i t h [Dechter and M e i r i , 1989] R. Dechter and I. M e i r i . Ex-
r a n d o m non-negative costs. T h e investigations extend p e r i m e n t a l E v a l u a t i o n of Preprocessing Techniques
the w o r k of K a r p and Pearl in several ways, but in par- in C o n s t r a i n t Satisfaction. In Proc. IJCAI, 271—
ticular t h r o u g h the i n t r o d u c t i o n of dead-ends. T h i s anal- 276, 1989.
ysis suggests the f o l l o w i n g conclusions:
[Hammersley, 1974] J. M. Hammersley. Postulates for
1. W h e n the possibility of "catastrophe" (dead ends or subadditive processes. Annals of Probability, 2:652-
p r o h i b i t i v e costs) can be ignored then backtracking 680, 1974.
methods do n o t seem a t t r a c t i v e , and a far simpler
approach like t h a t of the "horizon heuristic" .43 is [Haralick and E l l i o t t , 1980] R. M. Haralick and G. L.
preferable. E l l i o t t . Increasing tree search efficiency for con-
s t r a i n t satisfaction problems. Artificial Intelligence,
2. W h e n catastrophe looms then a backtracking
m e t h o d like K a r p and Pearl's bounded-lookahead 14:263-313, 1980.
plus p a r t i a l backtrack a l g o r i t h m A2 does seem an [Harris, 1963] T. E. Harris. The Theory of Branching
attractive option. Processes. Springer-Verlag, B e r l i n , 1963.
T h i s conclusion lends some m a t h e m a t i c a l s u p p o r t to [ K a r p , 1976] R. M. K a r p . T h e probabilistic analysis
certain e m p i r i c a l studies w h i c h show t h a t , under given of some c o m b i n a t o r i a l search a l g o r i t h m s . In J. F.
conditions, b a c k t r a c k i n g a l g o r i t h m s do not p e r f o r m as
T r a u b , editor, Algorithms and Complexity, pages 1-
well as n o n - b a c k t r a c k i n g a l g o r i t h m s . Examples are the
19, Academic Press, 1976.
e m p i r i c a l analysis of [Dechter and M e i r i , 1989; Haral-
ick and E l l i o t t , 1980] in binary constraint satisfaction [ K a r p and Pearl, 1983] R. M. K a r p and J. Pearl.
problems, and the analysis of [de Kleer, 1984] in reason Searching for an o p t i m a l p a t h in a tree w i t h ran-
maintenance systems. d o m costs. Artificial Intelligence, 21:99-116, 1983.

[ K i n g m a n , 1975] J . F . C . K i n g m a n . The First B i r t h


References
P r o b l e m for an Age-Dependent B r a n c h i n g Process.
[ A t h r e y a and Ney, 1972] K . B . A t h r e y a and P.E. Ney. Annals of Probability, 3:790-801, 1975.
Branching Processes. Springer-Verlag, B e r l i n , 1972.
[ K n u t h , 1975] D. E. K n u t h . E s t i m a t i n g the efficiency of
[Bitner and R e i n g o l d , 1975] J. R. B i t n e r and E. M. backtrack programs. Mathematics of Computation,
Reingold. Backtrack p r o g r a m m i n g techniques. 29:121-136, 1975.
Communications of the ACM, 18:651-655, 1975. [ M c D i a r m i d , 1990] C . J . H . M c D i a r m i d . Probabilistic
[Bramson, 1978] M. D. B r a m s o n . M i n i m a l displacement Analysis o f Tree Search. I n G . R . G u m m e t t and
of b r a n c h i n g r a n d o m walk. Z. Wahrsch. Varw. Ga- D.J .A. Welsh, editors, Disorder in Physical Sys-
biete, 45:89-108, 1978. tems, pages 249-260, O x f o r d Science P u b l i c a t i o n s ,
1990.
3
I t is also easy to prove a weaker version of this result
using only an easy part of theorem 4 and the subadditivity [Nudel, 1983] B. N u d e l . Consistent labeling problems
of the sequence E[C n ]. and their a l g o r i t h m s : expected complexities and

176 Automated Reasoning


theory-based heuristics. Artificial Intelligence,
21:135-178, 1983.
[Provan, 1985] G. M. Provan. A Probabilistic Analysis
of Search Algorithms in Uniform Trees. Mathemat-
ical I n s t i t u t e , University of Oxford, Unpublished D.
P h i l , qualifying dissertation, 1985.
[P. W. P u r d o m , 1983] Jr. P. W. P u r d o m . Search re-
arrangement backtracking and polynomial average
time. Artificial Intelligence, 21:117-133, 1983.
[Stone and Stone, 1986] H. Stone and J. Stone. Effi-
cient Search Techniques: An Empirical Study of the
N-Queen$ Problem. Technical Report T R T C 12057
(#54343), I B M T . J . Watson Research Center, 1986.

You might also like