An_Empirical_Comparison_of_Backtracking_Algorithms
An_Empirical_Comparison_of_Backtracking_Algorithms
L
b
Fig. 5. Illustrating the proof of the theorem. An Empirical Comparison of Backtracking Algorithms
CYNTHIA A. BROWN AND PAUL W. PURDOM, JR.
REFERENCES
[11 W. E. Snyder and D. A. Tang, "Finding the extrema of a region,"
IEEE Trans. Pattern Anal. Machine Intell., vol. PAMI-2, pp. 266- Abstract-In this paper we report the results of experimental studies
269, May 1980. of zero-level, one-level, and two-level search rearrangement backtracking.
[2] M. I. Shamos, "Geometric complexity," in Proc. 7th ACM Symp. We establish upper and lower limits for the size problem for which one-
Theory of Comput., May 1975, pp. 224-233. level backtracking is preferred over zero-evel and two-level methods,
[31 D. P. Dobkin and L. Snyder, "On a general method for maximiz- thereby showing that the zero-level method is best for very small prob-
ing and minimizing among certain geometric problems," in Proc. leins. The one-level method is best for moderate size problems, and the
20th Annu. Symp. Foundations Comput. Sci., San Juan, Puerto
Rico, Oct. 1979, pp. 9-17. two-evel method is best for extremely large problems. Together with
[4] D. McCallum and D. Avis, "A linear algorithm for finding the con- our theoretical asymptotic formulas, these measurements provide a
vex hull of a simple polygon," Inform. Process. Lett., vol. 9, pp. useful guide for selecting the best search rearrangement method for a
201-206, Dec. 1979. particular problem.
[5] J. Jacobsen, "Biomedical computer analysis of cells," in Proc. 1 7th
Annu. Conf Eng. in Med. Biol., 1964, p. 117. Index Terms-Backtracking, constraint satisfaction, search algorithms,
[6] M. A. Fischler, "Fast algorithms for two maximal distance prob- tree search.
lems with applications to image analysis," Pattern Recog., vol. 12,
pp. 35-40, 1980.
[7] G. T. Toussaint, "Pattern recognition and geometrical complex- I. INTRODUCTION
ity," in Proc. 5th Int. Conf. Pattern Recog., Miami Beach, FL, An important task of computer scientists is devising general
Dec. 1980, pp. 1324-1347. algorithms that can be used to solve any problem from a large
[8] D. Avis, G. T. Toussaint, and B. K. Bhattacharya, "On the multi- set of related problems. Such sets of problems can be divided
modality distances in convex polygons," Comput. Math. Appl., into two classes, sometimes called "easy" and "hard." The easy
to be published.
sets are those for which each problem in the set can be solved
within a time which is a polynomial function of the problem
size. An example of such an easy set is the computation of the
shortest path between two nodes in a graph. An individual
problem in the set consists of a graph whose arcs have nonnega-
tive labels and a distinguished pair of vertices. There are well-
Comments on "A Counterexample to a Diameter known general methods for solving any problem in this set in a
time proportional to the square of the number of nodes in the
Algorithm for Convex Polygons" graph [ 7 1. For naturally occurring easy problem sets, the de-
W. E. SNYDER AND D. A. TANG gree of the polynomial time bound is usually no greater than
three, so rapid solution of large problems is possible.
A hard problem set is one for which the best known algorithm
In our paper [ 1 ] we described an algorithm which efficiently takes more than polynomial time for some sequence of prob-
found the diameter of arbitrary regions, convex or concave, lems in the set. (For some hard problem sets, there are solution
simple or not, filled (boundary not identified) or not. In our methods with small average time.) Many important hard prob-
enthusiastic desire to describe this very general and very effi- lem sets are NP complete. Garey and Johnson [8] give a thor-
cient algorithm, we described, for completeness, some more ough discussion of the NP complete class and list many NP
simple algorithms to handle some of the more simple and complete problem sets.
"uninteresting" (to us) cases, such as convex polygons. An examination of the problems listed by Garey and Johnson
Unfortunately, one of those "more simple" cases was in shows that most of them have a natural representation as a
fact not so simple, and Bhattacharya and Toussaint' have very predicate of the form
accurately pointed out a condition under which one of the
simple techniques we described fails. We are very grateful to p1 A Ri(w,x * * *, Wv) (1)
them for that observation. It should be noted, however, that I < i< m
this flaw does not propagate to our general algorithm, which
converges to the diameter for arbitrary regions. where each R is a relation that is simple in the sense that it
As one further note, it has been our experience that it is depends on only a few of the variables and each w has a finite
unreasonable to assume the boundaries of regions in digital
Manuscript received March 25, 1981; revised November 3, 1981. This
Manuscript received November 16, 1981. work was supported in part by the National Science Foundation under
The authors are with the Department of Electrical Engineering, North Grant MCS 7906110.
Carolina State University, Raleigh, NC 27607. The authors are with the Department of Computer Science, Indiana
1B. K. Bhattacharya and G. T. Toussaint, this issue, pp. 306-309. University, Bloomington, IN 47405.
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DO ESPIRITO SANTO. Downloaded on April 03,2025 at 12:06:42 UTC from IEEE Xplore. Restrictions apply.
IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. PAMI-4, NO. 3, MAY 1982 311
TABLE I
THE CALCULATED AND MEASURED PERFORMANCE OF
ZERO-LEVEL BACKTRACKING
3 Literals Per Term
Var. Terms Cal. Nodes 4.72v3 8exp(.628v314) Measured Nodes Cal. Solutions
TABLE II TABLE IV
THE MEASURED PERFORMANCE OF THE FAST ONE-LEVEL THE MEASURED PERFORMANCE OF THE SIMPLE LEVEL-1
BACKTRACKING ALGORITHM BACKTRACKING ALGORITHM
3 Literals Per Term 3 Literals Per Term
Var. Terms Runs Binary Nodes Unary Nodes Evaluations Solutions
0
64 512 100 1615.+87. 18501.+899 0
144 1728 11000 185.4±1.1 3937.±24. 119644.±675. 0 81 729 100 2520.+139. 34088.+1712. 0
169 2197 11000 260.7±1.6 6047±.36. 197455.±1109. 0
100 1000 100 3945.+262. 61052.+3715. 0
196 2744 1000 365.1±8.7 9179.±217. 319591.±6943. 0
121 1331 100 6021.+415. 105477.+6632. 0
225
256
3375
4096
1000
1000
526.±10.
708.+15.
14240.±282.
20570.+438.
527996.±9860.
810792.+16297.
0
144 1728 100 9025.+486. 177123.+8641. 0
12568.+683. 274116.+13853. 0
0
64 11000
512 47.51+.32
640.8+4.0 14730.+88. one literal in it is true or unknown. We keep a list for each
0
81 11000
729 67.63+.47
1034.1+6.8 26953.+166. literal. Each clause is on the list for one of the literals that
0
100 11000
1000 1618.+11.
94.27+.64 46999.+287. causes it to be true. Initially, when no variables are set, any
0
121 11000
1331 134.93+.95
2559.+17. 81931.+523. literal in a clause causes it to be true. When a variable is set or
0
144 1728
11000 3946.+29.
189.5+1.5 137759.+948. changed, one literal becomes false. The clauses on the list for
0
169 11000
2197 6083.+44.
267.8+2.0 229475.+1554.
367960.+8324.
that literal are examined. If a clause contains other literals that
0
196
225
1000
2744
3375
1000
9098.+228.
369.9+9.5
518.+12.
13763.+324. 595712.+13221.
cause it to be true, then the clause is moved to the list for that
0
literal. If all the literals in a clause are false, then the predicate
0
256 4096
1000 20172.+495.
710.+18. 923832.+21182. 0
4
1
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DO ESPIRITO SANTO. Downloaded on April 03,2025 at 12:06:42 UTC from IEEE Xplore. Restrictions apply.
314 IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. PAMI-4, NO. 3, MAY 1982
TABLE V With s = 4, the same holds true for problems with 25 or more
THE MEASIJRED PERFORMANCE OF LEVEL-2 BACKTRACKING variables.
3 Literals Per Term Table V gives preliminary measurements on the two-level
algorithm published in [ 1 8 1. It appears to be possible to speed
up this algorithm by at least a factor of two. We plan to publish
Var. Terms Runs Total Nodes Evaluations Solutions
more extensive measurements after we have investigated this
1 1 100 3.00+0 4.48+.09 1.74+.04 possibility, and after we have developed a theoretical analysis
4 8 100 17.16+.05 150.4+6.0 5.28+.23 for two-level algorithms. Even without improvement, the two-
9 27 100 61.1+3.1 1418.5+7.4 13.44+.79 level algorithm is preferred for very large problems.
16 64 100 67.5+7.2 3435.+34. 8.76+2.7 Our theoretical work [ 21, [ 191 suggests that the number of
25 125 100 51.5+3.8 6107.+54. 1.54+.52
binary nodes for all the algorithms we measured (except per-
haps the two-level) is asymptotically of the form a1 Va2 exp
36 216 100 57.3+3.1 11803.+76. 0.01+.01
(a3 va4 ). For one-level backtracking, the number of unary nodes
49 343 100 70.9+3.2 21217.+117. 0
must be between zero and v times the number of binary nodes,
64 512 100 89.4+4.3 42143.+224. 0 and the number of evaluations must be between one and v
81 729 100 115.1+5.1 63582.+350. 0 times the number of nodes (between one and v2 times the
100 1000 100 128.1+5.9 70672.+474. 0 number of binary nodes). All four constants, a1, a2, a3, and
121 1331 100 161.6+5.4 120407.+597. 0 a4, are needed to reliably predict the actual number of nodes
144 1728 100 182.4+7.0 166134.+842. 0 for large values of v. We attempted to determine these constants
169 2197 100 234.0+8.3 314029.+1265. 0 by doing a least squares fit to our data using STEPIT [3 1. We
196 2744 100 256.+10. 428160.+1816. 0 found that it is difficult to do extrapolations with data of the
225 3375 100 297.+11. 567570.+2194. 0 type we have gathered. It is presently impractical to obtain
256 4096 100 343.+11. 772527.+2660. 0 much data for problems larger than the ones we studied. The
asymptotic formula is not valid for small problems. Statistical
4 Literals Per Term
fluctuations make it difficult to achieve high accuracy for any
data point. With a limited range of v and with inaccurate data,
many sets of values for a1, a2, a3, and a4 give nearly equally
Var. Terms Runs Total Nodes Evaluations Solutions
good fits: the collinearity problems are severe. For s = 3, our
1 1t 100 3.00+0 4.74+.007 1.87+.03 data are sufficient to determine two parameters when the
4 8 100 24.52+.04 219.5+4.2 9.21+.26 other two are fixed. In a few cases, it may be adequate for
9 27 100 286.1+7.8 5580.+128. 88.8+3.1
three, but in no case can all four be determined. For s = 4, we
have not extended our measurements to large enough v to
16 64 100 3393.+151. 65270.+3476. 1022.+56.
obtain reliable asymptotic fits.
25 125 100 34329.+1655. 728498.+30133. 10442.+592. The upper part of Table VI shows the results of fitting a3
36 216 100 204709.+15998. 5927770.+304356. 62927.+5764. and a4 when a1 and a2 are held fixed. (They are set to the
49 J 343 100 516182.+55303. 27663834.+1509539. 148034.+19859. natural values of one and zero, respectively.) For any of the
algorithms, the values of a3 and a4 should be the same whether
This is the method published in [18]1. Refimements can probably re- binary nodes or evaluations are being measured because these
duce the number of predicate evaluations by a factor of two. quantities are related polynomially. The variation in the fitted
values gives one indication of the inaccuracy of the fitting pro-
mance of basic backtracking algorithms. We plan future studies cess. For zero-level backtracking, the theoretical value of a4 is
of predicate analysis methods. 0.75, so the fitted value is low by 0.15. For the Analyzed algo-
VI. RESULTS
rithm, the theoretical value of a4 is 0.50, so the fits are low by
0.11-0.14. Thus, although the fits to our quite extensive mea-
Tables I-V give the results of the measurements. Table I surements give a rough indication of the upper exponent, the
shows the performance of the zero-level algorithm as measured error is large compared to the range of values (zero to one)
and as calculated from the formulas in [2]. The theory for permitted by a naive analysis.
zero-level backtracking is quite complete; the measurements The middle part of Table VI gives fits for a2 and a3 with a4
were done to provide a test for the statistical methods that set to its theoretical value and a1 set to one. (For the Fast and
were used on the other cases. For zero-level backtracking, the Simple algorithms, we use the theoretical value from the Ana-
number of nodes and the number of predicate evaluations lyzed algorithm.) For zero-level backtracking, the theoretical
are identical. value of a3 is 0.730, so the fitted value is low by 0.20. For the
Tables II-IV give the measured performance of the Fast, Analyzed algorithm, theory gives 0.1 82 < a3 < 0.320 (for a >
Analyzed, and Simple algorithms. For the first two algorithms, s/2). All fits for the various one-level algorithms were in this
the number of binary nodes, unary nodes, and predicate evalua- range, although the values for the various cases spanned most
tions were measured. For the Simple algorithm "total" nodes of the range. The measurements were consistent with a3 =
were measured, where total nodes is defined to be 2 * (binary 0.320, but not with a3 = 0.1 82 (except for the Simple algo-
nodes + unary nodes) + 1. This definition corresponds to the rithm, for which we do not have much data).
one used in [181. We suspect that the true value of a3 for one-level backtrack-
The number of predicate evaluations gives a good indication ing is equal to the upper limit. The lower part of Table VI
of the relative speed of the various methods. Even with our shows the results of fitting a1 and a2 with a3 and a4 set accord-
very rapid predicate evaluation methods, over 90 percent of the ing to this conjecture. The resulting formulas are probably the
time was spent evaluating predicates. The measurements indi- most reliable for predicting the performance for large v. For
cate that the Fast algorithm is indeed the fastest of the three. zero-level backtracking, the theoretical value of a2 is 8, so the
The differences, however, are not large, and they increase only fit is low by 0.12.
slowly with problem size. For large problems, there are many The various fits for one-level algorithms suggest that the num-
more unary nodes than binary nodes, and there are many more ber of unary nodes is proportional to v"2 * (binary nodes).
evaluations than nodes. For s = 3 and problems of 16 variables Tables II and III clearly indicate that the Fast algorithm is bet-
or more, the one-level methods are much faster than zero-level. ter than the Analyzed, but Table VI gives little indication of the
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DO ESPIRITO SANTO. Downloaded on April 03,2025 at 12:06:42 UTC from IEEE Xplore. Restrictions apply.
IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. PAMI-4, NO. 3, MAY 1982 315
TABLE VI
VARIOUS LEAST SQUARE FITS TO THE MEASURED NUMBER OF BINARY
NODES, UNARY NODES, AND EVALUATIONS FOR VARIOUS BACKTRACKING
ALGORITHMS ON PROBLEMS WITH THREE LITERALS PER TERM
Algorithm Binary Nodes Unary Nodes Evaluations Range
level zero exp(1.41v'601) 25-64
x2 = 2.16
fast exp(.763v'387) exp(l.75v'313) exp(3.20v 261) 100-2561
x2 = 10.5 X2 = 5.40 X2 = 5.23
fast 2.27V-.113 exp(.320v 1/2 ) 3.29v- 651 exp(.320v 1/2 l30exp(.320v 1/2 )
9.32v 130 49-256
x2 = 1S.5 X2 = 14.0 X2 = 41.2
analyzed 2.19v'124exp(.320vl/2) 3.16v-661exp(.320vl/2) 8.52vl.l76exp(.320vl/2) 49-256
x2 = 90 2 5.13 X2 = 12.1
functional form of the improvement. It is likely that some level algorithms, including the Fast algorithm. We have shown
slowly growing function (such as log v) is involved. that the Fast algorithm is faster than the Analyzed algorithm.
Fig. 4 is a graph comparing the performance of the zero-level, Our measurements indicate that the number of unary nodes is
Fast, and two-level algorithms. Curves for the other one-level roughly v 1/2 times the number of binary nodes, and the num-
algorithms would be too close to the curve for the Fast for con- ber of evaluations is roughly v times the number of binary
venient display. The scales were chosen so that the function nodes. Most of these results would have been extremely diffi-
a1 va2 exp (a3 va4) would approach a straight line for large v. cult to obtain using theoretical techniques.
On the other hand, these experimental studies are quite lim-
VII. CONCLUSIONS ited in their ability to establish the asymptotic behavior of any
The experimental studies reported in this paper supplement method. When choosing or developing an algorithm for a prac-
our theoretical results. We have established an upper and lower tical problem, both the theoretical asymptotic studies and the
limit for the size problem for which the one-level search re- results of measurements on problems of reasonable size should
arrangement algorithms are preferred over zero-level and two- be considered. The results in this paper combined with those
level methods. We have shown that our theoretical results are in [21 and [191 should be of help in selecting the most appro-
compatible with the measured performance of the various one- priate basic backtracking algorithm for a particular problem.
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DO ESPIRITO SANTO. Downloaded on April 03,2025 at 12:06:42 UTC from IEEE Xplore. Restrictions apply.
316 IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. PAMI-4, NO. 3, MAY 1982
3xlO I I .. I
3xJ06
3 x4O
3X104
3000 [
1000 r
300 r
/ O-Level -
//
c
100 Fast
2- Level
o 50 I,
//
//
w 30 /
20 .-
4 9 16 25 36 49 64
.
The methods in [161 and [171 can then be used to estimate [13] "The consistent labeling problem: Part II," IEEE Trans.
,
how long the chosen method will take to solve the problem. Pattern Anal. Mach. Intell., vol. PAMI-2, pp. 193-203, 1980.
In the future, we hope to perform theoretical analyses and [14] R. M. Haralick and G. L. Elliot, "Increasing tree search efficiency
practical measurements on two-level backtracking and on vari- for constraint satisfaction problems," Virginia Polytech. Inst.,
Blacksburg, Rep., 1979.
ous predicate analysis techniques. Together with our present R. M. Karp, "Reducibility among combinatorial problems," in
[15]
results, these will provide a rational basis for selecting an algo- Complexity in Computer Computations, R. E. Miller and J. W.
rithm to solve a large problem. Thatcher, Eds. New York: Plenum, 1972, pp. 85-103.
[16] D. E. Knuth, "Estimating the efficiency of backtracking pro-
REFERENCES grams," Math. Comput., vol. 29, pp. 121-136, 1975.
[1] J. R. Bitner and E. M. Reingold, "Backtrack programming tech- [17] P. W. Purdom, "Tree size by partial backtracking," SIAM J. Com-
niques," Commun. Ass. Comput. Mach., vol. 18, pp. 651-655, put., vol. 7, pp. 481-491, 1977.
1975. [18] P. W. Purdom, Jr., C. A. Brown, and E. L. Robertson, "Backtrack-
[2] C. A. Brown and P. W. Purdom, Jr., "An average time analysis of ing with multi-level search rearrangement," Acta Informatica, vol.
backtracking," SIAMJ. Comput., vol. 10, pp. 583-593, 1981. 15, pp. 99-114, 1981.
[3] J. P. Chandler, "STEPIT," Quantum Chem. Program Exchange, [19] P. W. Purdom, Jr. and C. A. Brown, "An analysis of backtracking
Dep. Chem., Indiana Univ., Bloomington. with search rearrangement," SIAM J. Comput., to be published.
[4] A. K. Chandra, D. C. Kozen, and L. J. Stockmayer, "Alternation,"
J. Ass. Comput. Mach., vol. 28, pp. 114-133, 1981.
[5] S. A. Cook, "The complexity of theorem-proving procedures," in
Proc. 3rd Annu. ACM Symp. Theory of Computing. New York:
Ass. Comput. Mach., 1971, pp. 151-158.
[6] M. Davis and H. Putnam, "A computing procedure for quantifica- A Method for Finding Pairs of Antiparallel Straight Lines
tion theory," J. Ass. Comput. Mach., vol. 7, pp. 201-215, 1960.
[7] E. W. Dijkstra, "A note on two problems in connexion with ANN SCHER, MICHAEL SHNEIER, AND AZRIEL ROSENFELD
graphs," Numer. Math., vol. 1, pp. 269-271, 1959.
[8] M. R. Garey and D. S. Johnson, Computers and Intractability: A
Guide to the Theory of NP- Completeness. San Francisco, CA:
Freeman, 1979. Abstract-A method of pairing antiparallel straight lines is presented
[9] J. Gaschnig, "Performance measurement and analysis of certain and discussed. The pairing is based on the distance between the lines,
search algorithms" Ph.D. dissertation, Carnegie-Mellon Univ., the amount by which they overlap, and on whether or not other lines
Pittsburgh, PA, 1979. are interposed. Examples are shown of applying the method to high-
[10] A. Goldberg, P. Purdom, and C. A. Brown, "Average time analyses resolution aerial photographs. Results indicate that cultural features
of simplified Davis-Putnam procedures," submitted to Inform.
Processing Lett.
[111 R. M. Haralick, L. S. Davis, A. Rosenfeld, and D. L. Milgram, Manuscript received February 4, 1980; revised November 4, 1981.
"Reduction operations for constraint satisfaction," Inform. Sci., This work was supported by the Defense Advanced Research Projects
vol. 14, pp. 199-219, 1978. Agency and the U.S. Army Night Vision Laboratory under Contract
[12] R. M. Haralick and L. G. Shapiro, "The consistent labeling prob- DAAG-53-76C-0138 (DARPA Order 3206).
lem: Part I," IEEE Trans. Pattern Anal. Machine Intell., vol. The authors are with the Computer Vision Laboratory, Computer
PAMI-1, pp. 173-184, 1979. Science Center, University of Maryland, College Park, MD 20742.
Authorized licensed use limited to: UNIVERSIDADE FEDERAL DO ESPIRITO SANTO. Downloaded on April 03,2025 at 12:06:42 UTC from IEEE Xplore. Restrictions apply.