Expected computation time for Hamiltonian path problem
SIAM Journal on Computing (1987)
Available from scitation.aip.org
or
Abstract
One way to cope with an NP-hard problem is to find an algorithm that is fact on average with respect to a natural probability distribution on inputs. We consider from that point of view the Hamiltonian Path Problem. Our algorithm for the Hamiltonian Path Problem constructs or establishes the nonexistence of a Hamiltonian path
Available from scitation.aip.org
Page 1
Expected computation time for Hamiltonian path problem
SIAM J. COMPUT.
Vol. 16, No. 3, June 1987
1987 Society for Industrial and Applied Mathematics
005
EXPECTED COMPUTATION TIME FOR
HAMILTONIAN PATH PROBLEM*
YURI GUREVICH" AND SAHARON SHELAHt
Abstract. One way to cope with an NP-hard problem is to find an algorithm that is fact on average
with respect to a natural probability distribution on inputs. We consider from that point of view the
Hamiltonian Path Problem. Our algorithm for the Hamiltonian Path Problem constructs or establishes the
nonexistence of a Hamiltonian path. For a fixed probability p, the expected run-time of our algorithm on
a random graph with n vertices and the edge probability p is O(n). The algorithm is adaptable to directed
graphs.
Key words, average case complexity, NP-hard Hamiltonian circuit, Hamiltonian path, probability,
random graphs, expected polynomial time, expected sublinear time
AMS(MOS) subject classifications. 05G35, 60C05, 68A10, 68A20
Introduction. One way to cope with an NP-hard decision problem iyR(x, y) is
to find an algorithm that is fast on average with respect to a natural probability
distribution on inputs. See in this connection Levin (1984) and Johnson (1984). A
similar approach can be taken if one is interested in exhibiting an object y that witnesses
R(x, y), and not only in the existence of a witness. We consider from this point of
view the following version of the Hamiltonian Path Problem: given a graph with
distinguished vertices Start and Finish, construct or establish the nonexistence of a
Hamiltonian path from Start to Finish. A Hamiltonian path from Start to Finish can
be defined as a linear ordering of all vertices such that Start is the first, Finish is the
last, and every pair of neighbors forms an edge. Without loss of generality, we restrict
our attention to the case when the vertices of the given graph form an initial segment
{0, 1,. , n 1} of natural numbers, Start 0 and Finish n- 1.
Let F(n, p) be the popular probability space of graphs with vertices 0, 1, , n 1
and the edge probability p (Erd/Ss and Spencer (1974)). The probability, assigned to
a particular graph G with vertices 0, 1,..., n-1, is the probability that G is the
outcome of the following experiment: For each pair {i,j} of distinct vertices, toss a
coin with the probability p of the head; declare {i,j} an edge if and only if the head
turns up. Let G,,,p be a random member of F(n, p).
In order to deal with instances of an arbitrary size, consider a function p(n) from
positive integers to the real interval [0, 1]. The spaces F(n, p(n)) can be combined into
one probability space S with respect to a probability distribution 8 on positive integers
(the meaning of 8(n) is the probability that a random graph has exactly n vertices);
however, this may not be necessary for the following reason. The expected run-time
* Received by the editors June 27, 1985; accepted for publication July 26, 1986.
"
Electrical Engineering and Computer Science Department, The University of Michigan, Ann Arbor,
Michigan 48109-2122. The work of this author was supported in part by National Science Foundation grants
MCS 83-01022 and DCR 85-03275.
Institute of Mathematics and Computer Science, The Hebrew University, 91904 Jerusalem, Israel.
The work of this author was supported in part by National Science Foundation grant MCS 81-01560. This
paper was written in the fall of 1984 when this author was a visiting professor in both the Department of
Electrical Engineering and Computer Science and the Department of Mathematics, The University of
Michigan, Ann Arbor, Michigan 48109-2122.
486
Vol. 16, No. 3, June 1987
1987 Society for Industrial and Applied Mathematics
005
EXPECTED COMPUTATION TIME FOR
HAMILTONIAN PATH PROBLEM*
YURI GUREVICH" AND SAHARON SHELAHt
Abstract. One way to cope with an NP-hard problem is to find an algorithm that is fact on average
with respect to a natural probability distribution on inputs. We consider from that point of view the
Hamiltonian Path Problem. Our algorithm for the Hamiltonian Path Problem constructs or establishes the
nonexistence of a Hamiltonian path. For a fixed probability p, the expected run-time of our algorithm on
a random graph with n vertices and the edge probability p is O(n). The algorithm is adaptable to directed
graphs.
Key words, average case complexity, NP-hard Hamiltonian circuit, Hamiltonian path, probability,
random graphs, expected polynomial time, expected sublinear time
AMS(MOS) subject classifications. 05G35, 60C05, 68A10, 68A20
Introduction. One way to cope with an NP-hard decision problem iyR(x, y) is
to find an algorithm that is fast on average with respect to a natural probability
distribution on inputs. See in this connection Levin (1984) and Johnson (1984). A
similar approach can be taken if one is interested in exhibiting an object y that witnesses
R(x, y), and not only in the existence of a witness. We consider from this point of
view the following version of the Hamiltonian Path Problem: given a graph with
distinguished vertices Start and Finish, construct or establish the nonexistence of a
Hamiltonian path from Start to Finish. A Hamiltonian path from Start to Finish can
be defined as a linear ordering of all vertices such that Start is the first, Finish is the
last, and every pair of neighbors forms an edge. Without loss of generality, we restrict
our attention to the case when the vertices of the given graph form an initial segment
{0, 1,. , n 1} of natural numbers, Start 0 and Finish n- 1.
Let F(n, p) be the popular probability space of graphs with vertices 0, 1, , n 1
and the edge probability p (Erd/Ss and Spencer (1974)). The probability, assigned to
a particular graph G with vertices 0, 1,..., n-1, is the probability that G is the
outcome of the following experiment: For each pair {i,j} of distinct vertices, toss a
coin with the probability p of the head; declare {i,j} an edge if and only if the head
turns up. Let G,,,p be a random member of F(n, p).
In order to deal with instances of an arbitrary size, consider a function p(n) from
positive integers to the real interval [0, 1]. The spaces F(n, p(n)) can be combined into
one probability space S with respect to a probability distribution 8 on positive integers
(the meaning of 8(n) is the probability that a random graph has exactly n vertices);
however, this may not be necessary for the following reason. The expected run-time
* Received by the editors June 27, 1985; accepted for publication July 26, 1986.
"
Electrical Engineering and Computer Science Department, The University of Michigan, Ann Arbor,
Michigan 48109-2122. The work of this author was supported in part by National Science Foundation grants
MCS 83-01022 and DCR 85-03275.
Institute of Mathematics and Computer Science, The Hebrew University, 91904 Jerusalem, Israel.
The work of this author was supported in part by National Science Foundation grant MCS 81-01560. This
paper was written in the fall of 1984 when this author was a visiting professor in both the Department of
Electrical Engineering and Computer Science and the Department of Mathematics, The University of
Michigan, Ann Arbor, Michigan 48109-2122.
486
Page 2
EXPECTED COMPUTATION TIME 487
of an algorithm on a random member of S with n vertices is bounded by some function
t(n) if the expected run-time of the algorithm on each G.,p(. is bounded by t(n).
There are several algorithms for the Hamiltonian Path Problem in the literature
that almost always (with probability 1 minus the reciprocal of a polynomial in n) work
fast on any G.,p(. where p(n) is sufficiently large to ensure a high probability of the
existence of a Hamiltonian path. Angluin and Valiant (1979) survey the previous
algorithms of that sort and give an elegant faster algorithm of their own; almost always,
their algorithm runs in time O(n(log n)2) on their Random Access Computer. Shamir
(1983) gives a further result of that sort; his algorithm is slower but the requirement
on p is weaker: p(n) >-_ n-l(loge n -I- c 1Oge 1Oge n) where c > 3. Bollobas, Fenner and
Frieze (1985) weakened the requirement on p(n) to the limit; almost always, their
algorithm runs in time O(n4/). The expected run-time of all these algorithms is
exponential with one exception, which is the Bollobas, Fenner and Frieze algorithm
in the case p(n)-> 1/2. (In the technical report of Gurevich and Shelah (1984) we wrote
that, to the best of our knowledge, there are no results in the literature on expected
run-time of algorithms for the Hamiltonian Path Problem. The Bollobas, Fenner and
Frieze paper appeared soon after that.)
We present here our algorithm HPA (Hamiltonian Path Algorithm) for the Hamil-
tonian Path Problem and estimate the run-time of HPA on G.,p in the case when p is
fixed and n is varied. The algorithm constructs or establishes the nonexistence of a
Hamiltonian path from Start to Finish. The exact form of input is not important; for
the sake of definiteness, we suppose that graphs are represented by the adjacency
matrices. It is important that a random access computer is used. It could be, for
example, the randomized Random Access Computer of Angluin and Valiant (1979).
THEOREM 1. There is a positive real number c satisfying thefollowing condition. For
any fixed probability p, the expected run-time of HPA on G.,p is chip+ o(n).
COROLLARY. For every p there is a constant d such that the expected run-time of
HPA on G.,p is bounded by dn/p.
The algorithm HPA is composed of three algorithms HPA1, HPA2 and HPA3.
First HPA1 is applied. If HPA1 fails to solve the given instance of the Hamiltonian
Path Problem, then HPA2 is applied. If HPA2 fails, then HPA3 is applied; HPA3
always succeeds. Let us comment briefly on each of the three algorithms.
The algorithm HPA1 is described in 1. It tries to construct a Hamiltonian path,
and definitely fails if the desired path does not exist. For a fixed p, the expected
run-time of HPA1 on G.,p is cn/p+ o(n) where c is an absolute constant. The constant
c is quite a modest number; its exact value depends on the machine model. For a fixed
p, the probability that HPA1 fails on G.,p is 2**(-O(x/-ff)).
The algorithm HPA2 is described in 2. It tries to construct or establish the
nonexistence of a Hamiltonian path. The idea is to take care of the troublesome vertices
(those with relatively small degree) first. The run-time of HPA2 on a graph with n
vertices is O(n2). For a fixed p, the probability that HPA2 fails on HPA1 (G.,p), assuming
that HPA1 has failed on G.,p, is 2 -3"+0(") where HPAI(G.,p) is the output of HPA1
on G.,p in the case that HPA1 fails on
The fastest (in the worst case) known algorithm for the Hamiltonian Path Problem
is the dynamic programming algorithm (Bellman (1960), Held and Karp (1962)) which
solves the Hamiltonian Path Problem in time 2". n (1) where n is the number of
vertices. We could adapt it as our third algorithm HPA3. A negative feature of the
dynamic programming algorithm is that it requires exponential space. Our third
algorithm HPA3, described in 3, solves the Hamiltonian Path Problem for graphs
with n vertices in time 22")< 2(I) and in space O(n); here 1og2 n. (This time bound
of an algorithm on a random member of S with n vertices is bounded by some function
t(n) if the expected run-time of the algorithm on each G.,p(. is bounded by t(n).
There are several algorithms for the Hamiltonian Path Problem in the literature
that almost always (with probability 1 minus the reciprocal of a polynomial in n) work
fast on any G.,p(. where p(n) is sufficiently large to ensure a high probability of the
existence of a Hamiltonian path. Angluin and Valiant (1979) survey the previous
algorithms of that sort and give an elegant faster algorithm of their own; almost always,
their algorithm runs in time O(n(log n)2) on their Random Access Computer. Shamir
(1983) gives a further result of that sort; his algorithm is slower but the requirement
on p is weaker: p(n) >-_ n-l(loge n -I- c 1Oge 1Oge n) where c > 3. Bollobas, Fenner and
Frieze (1985) weakened the requirement on p(n) to the limit; almost always, their
algorithm runs in time O(n4/). The expected run-time of all these algorithms is
exponential with one exception, which is the Bollobas, Fenner and Frieze algorithm
in the case p(n)-> 1/2. (In the technical report of Gurevich and Shelah (1984) we wrote
that, to the best of our knowledge, there are no results in the literature on expected
run-time of algorithms for the Hamiltonian Path Problem. The Bollobas, Fenner and
Frieze paper appeared soon after that.)
We present here our algorithm HPA (Hamiltonian Path Algorithm) for the Hamil-
tonian Path Problem and estimate the run-time of HPA on G.,p in the case when p is
fixed and n is varied. The algorithm constructs or establishes the nonexistence of a
Hamiltonian path from Start to Finish. The exact form of input is not important; for
the sake of definiteness, we suppose that graphs are represented by the adjacency
matrices. It is important that a random access computer is used. It could be, for
example, the randomized Random Access Computer of Angluin and Valiant (1979).
THEOREM 1. There is a positive real number c satisfying thefollowing condition. For
any fixed probability p, the expected run-time of HPA on G.,p is chip+ o(n).
COROLLARY. For every p there is a constant d such that the expected run-time of
HPA on G.,p is bounded by dn/p.
The algorithm HPA is composed of three algorithms HPA1, HPA2 and HPA3.
First HPA1 is applied. If HPA1 fails to solve the given instance of the Hamiltonian
Path Problem, then HPA2 is applied. If HPA2 fails, then HPA3 is applied; HPA3
always succeeds. Let us comment briefly on each of the three algorithms.
The algorithm HPA1 is described in 1. It tries to construct a Hamiltonian path,
and definitely fails if the desired path does not exist. For a fixed p, the expected
run-time of HPA1 on G.,p is cn/p+ o(n) where c is an absolute constant. The constant
c is quite a modest number; its exact value depends on the machine model. For a fixed
p, the probability that HPA1 fails on G.,p is 2**(-O(x/-ff)).
The algorithm HPA2 is described in 2. It tries to construct or establish the
nonexistence of a Hamiltonian path. The idea is to take care of the troublesome vertices
(those with relatively small degree) first. The run-time of HPA2 on a graph with n
vertices is O(n2). For a fixed p, the probability that HPA2 fails on HPA1 (G.,p), assuming
that HPA1 has failed on G.,p, is 2 -3"+0(") where HPAI(G.,p) is the output of HPA1
on G.,p in the case that HPA1 fails on
The fastest (in the worst case) known algorithm for the Hamiltonian Path Problem
is the dynamic programming algorithm (Bellman (1960), Held and Karp (1962)) which
solves the Hamiltonian Path Problem in time 2". n (1) where n is the number of
vertices. We could adapt it as our third algorithm HPA3. A negative feature of the
dynamic programming algorithm is that it requires exponential space. Our third
algorithm HPA3, described in 3, solves the Hamiltonian Path Problem for graphs
with n vertices in time 22")< 2(I) and in space O(n); here 1og2 n. (This time bound
Sign up today - FREE
Mendeley saves you time finding and organizing research. Learn more
- All your research in one place
- Add and import papers easily
- Access it anywhere, anytime
Start using Mendeley in seconds!
Readership Statistics
9 Readers on Mendeley
by Discipline
11% Humanities
by Academic Status
56% Ph.D. Student
11% Student (Master)
11% Other Professional
by Country
22% Germany
22% Russia
11% United Kingdom


