Discrete Applied Mathematics 136 (2004) 197–215www.elsevier.com/locate/dam
A linear algorithm for the Hamiltoniancompletion number of the line graph of a cactus
Paolo Detti
a
, Carlo Meloni
b
a
Dipartimento di Ingegneria dell’Informazione, Universita di Siena, Via Roma, 56, I53100 Siena, Italy
b
Dipartimento di Elettrotecnica ed Elettronica, Politecnico di Bari, Via E. Orabona, 4 I70125Bari, Italy
Received 25 June 2001; received in revised form 1 November 2002; accepted 19 February 2003
Abstract
Given a graph
G
= (
V;E
)
;HCN
(
L
(
G
)) is the minimum number of edges to be added to itsline graph
L
(
G
) to make
L
(
G
) Hamiltonian. This problem is known to be
NP
hard for generalgraphs, whereas a O(

V

) algorithm exists when
G
is a tree. In this paper a linear algorithm for nding
HCN
(
L
(
G
)) when
G
is a cactus is proposed.
?
2003 Elsevier B.V. All rights reserved.
Keywords:
Algorithms; Hamiltonian path; Hamiltonian completion number; Cactus; Line graph
1. Introduction
In this paper a graph
G
=(
V;E
) is called Hamiltonian if it has a Hamiltonian path,and the problem of nding the minimum number of edges which need to be added to
G
to make it Hamiltonian is considered. This problem is known in literature as the problem of nding the
Hamiltonian completion number
of a graph and will be denotedas
HCN
(
G
). In particular, we investigate the problem restricted to a particular classof graphs, called
line graphs
. The line graph
L
(
G
) of
G
= (
V;E
) is a graph having

E

nodes, each node of
L
(
G
) being associated to an edge of
G
. There is an edge between two nodes of
L
(
G
) if the corresponding edges of
G
are adjacent. Lineartimealgorithms exist for recognizing a line graph
L
(
G
) and obtain its
root
graph
G
[15,20].
Given a graph
G
=(
V;E
), a
trail
is a sequence
w
:= (
v
0
;e
0
;v
1
;e
1
;v
2
;e
2
;:::;e
k
−
1
;v
k
),where (
v
0
;v
1
;v
2
;:::;v
k
) are nodes of
G;
(
e
0
;e
1
;e
2
;:::;e
k
−
1
) are distinct edges of
G
,
Email addresses:
detti@dii.unisi.it (P. Detti), meloni@deemail.poliba.it (C. Meloni).
0166218X/$see front matter
?
2003 Elsevier B.V. All rights reserved.doi:10.1016/S0166218X(03)004414
198
P. Detti, C. Meloni/Discrete Applied Mathematics 136 (2004) 197–215
and
v
i
and
v
i
+1
are the endpoints of
e
i
for 0
6
i
6
k
−
1. The trail is a
path
if itsnodes (
v
0
;v
1
;v
2
;:::;v
k
) are distinct. In other words, a trail is a path that can pass moretimes for the same node. A path or a trail may consist of a single node.A
dominating trail
D
T
in
G
is a trail such that each edge of
G
has at least oneendpoint belonging to it (i.e., a dominating trail
covers
all the edges of
G
). Notethat a dominating trail may not exist. A
dominating trail set
is a collection of edgedisjoint trails that altogether cover all the edges of
G
. A
minimum dominatingtrail set
(
MDTS
) is a dominating trail set of minimum cardinality.Harary and NashWilliams [11] link the problem of nding
HCN
(
L
(
G
)) and
MDTS
showing that the line graph
L
(
G
) of a graph
G
has a Hamiltonian path if and only if
G
has a dominating trail. As consequence, if
HCN
(
L
(
G
)) =
k
then the cardinality of
MDTS
of
G
is
k
+ 1.Particular special conditions on
G
have been found that ensure the existence of aHamiltonian path on
L
(
G
) [24], and therefore
HCN
(
L
(
G
))=0. Agnetis et al. [1] showedthe
NP
hardness of the problem of nding
HCN
(
L
(
G
)) even when
G
is bipartite, and proposed, for this case, a heuristic approach.When
G
is a tree or a forest the problem may be solved in linear time [9,14,17,21,22],
while an approximate algorithm for the weighted version of the problem was proposed by Wu et al. [26].When
G
is an interval graph [18], a circulararc graph [4], a block graph [23,25,27],
a bipartite permutation graph [23] or a cograph [16], it was shown that there exist
polynomial time algorithms for nding
HCN
(
G
).Raychaudhuri [19] presented a O(
n
5
) algorithm for nding
HCN
(
G
) when
G
is theline graph of a tree, while Agnetis et al. [2] proposed a linear algorithm for this case.
For Cactus graphs
C
=(
V;E
), i.e. graphs such that every edge is part of at most onecycle in
C
, Hedetniemi et al. [12] proposed a linear algorithm for nding a minimumdominating set (i.e., a minimum cardinality subset
V
∗
⊆
V
such that every vertex in
V
\
V
∗
is adjacent to at least one vertex in
V
∗
). However, literature does not reportany specic algorithm for nding
MDTS
or
HCN
(
L
(
G
)) on cactus graphs.The study of line graphs is strongly related to important graph invariants, i.e. the
interval number
, the
total interval number
and the
Wiener index
[10,13,19]. Moreover,
nding a
MDTS
or
HCN
of line graphs is often required in routing, sequencing, graphsearching and in updating data structures [1,8]. In particular, the case of cactus graphs
has several applications in ecient organization of control and data structures [6,7].
In this paper, a linear algorithm for nding the
Hamiltonian completion number
of the line graph
L
(
C
) (as well as a
MDTS
of
C
) of a cactus
C
is proposed. In Section 2some notations, denitions and elementary graph transformations are considered. Thesetransformations will play an important role in the theoretical foundation presented inSection 3. In Section 4 an algorithm for nding
MDTS
is reported.
2. Notations and elementary graph transformations
A
cut vertex
in a graph
G
is a vertex whose removal results in a disconnectedgraph. A block in a graph
G
is a maximal connected subgraph having no cut vertices.
P. Detti, C. Meloni/Discrete Applied Mathematics 136 (2004) 197–215
199
A cactus is a graph in which each block is either an edge or a cycle. Thus, a tree is acactus in which each block is an edge. An endblock of a cactus is a block containingat most one cut vertex. A cactus may be recognized in linear time [5].
Throughout the paper we use the following notation. Given a node
i
of the graph
G
, we call
ad
(
i
) the set of nodes adjacent to
i
in
G
, and
(
i
) the cardinality of
ad
(
i
)(i.e., the degree of
i
). Clearly, when
i
is a leaf,
ad
(
i
) contains a single node
j
. In thiscase we write
ad
(
i
) =
j
(instead of
ad
(
i
) =
{
j
}
). Given an endblock
B
= (
V
B
;E
B
) of
G
, we indicate as
cv
(
B
) the unique cut vertex of
B
. If
Q
is a block of
G
, let
cv
(
Q
) be the set of the cut vertices of
Q
.Starting from a cactus graph
C
= (
V;E
), our approach repeatedly applies some elementary operations which reduce the size of the graph, until an empty graph is reached.To describe these transformations, we refer to the notation proposed by Agnetis et al.[2], in which two marking functions
:
V
→ {
0
;
1
}
and
:
E
→ {
0
;
1
}
have been introduced. A node
i
(an edge
e
) such that
(
i
) = 1 (
(
e
) = 1) is called
marked
. Markingan edge means that we want to nd a trail set which does
not
need to dominate thatedge of the current graph. Marking a node means that at least one element of the trailset
must
pass through that node of the current graph. In the following, the problem of nding a
minimum constrained dominating trail set
(
MCDTS
) is dened.
Denition 1.
Given a triple (
C;;
), a
constrained dominating trail set
c
is a collection of disjoint trails
{
t
1
;t
2
;:::;t
r
}
such that: (i)
c
dominates all the edges of
C
which are not marked; (ii) for each marked node
i
, a trail
t
∈
c
containing
i
exists.A
minimum constrained dominating trail set
(
MCDTS
) is a constrained dominatingtrail set of minimum cardinality. Such a cardinality will be denoted as
S
(
C;;
).Finding
HCN
(
L
(
C
)) can therefore be reformulated as the problem of nding
S
(
C;;
), where
C
=(
V;E
) is the srcinal cactus,
(
i
)=0
;
∀
i
∈
V
and
(
e
)=0
;
∀
e
∈
E
.In the following some elementary transformations, employed in the proposed algorithm, are presented.
Denition 2.
Given a triple (
C;;
), let the edge
B
= (
i;j
) be an endblock of
C
, i.e.node
i
is a leaf, and
j
is the cut vertex of
B
. By an
edgeshrink
of the endblock
B
wemean the transformation from (
C;;
) to the triple (
C
′
;
′
;
′
) dened as follows:
C
′
= (
V
′
;E
′
) = (
V
\
i;E
\
(
i;j
));
′
(
q
) =
(
q
)
;
∀
q
∈
(
V
′
\
j
);
′
(
j
) = 1;
′
(
e
) =
(
e
)
;
∀
e
∈
E
′
:
In other words, given an edge endblock
B
= (
i;j
), the
edgeshrink
transformationremoves the leaf
i
and the edge (
i;j
) from the graph and marks the node
j
. A similar operation may be dened for cycle endblocks.
200
P. Detti, C. Meloni/Discrete Applied Mathematics 136 (2004) 197–215
Denition 3.
Given a triple (
C;;
), let
B
= (
V
B
;E
B
) be a cycle endblock of
C
, and
cv
(
B
) be the unique cut vertex of
B
. By a
cycleshrink
of the endblock
B
we meanthe transformation from (
C;;
) to the triple (
C
′
;
′
;
′
) dened as follows:
C
′
= (
V
′
;E
′
) = (
V
\
(
V
B
\
cv
(
B
))
;E
\
E
B
);
′
(
q
) =
(
q
)
;
∀
q
∈
(
V
′
\
cv
(
B
));
′
(
cv
(
B
)) = 1;
′
(
e
) =
(
e
)
;
∀
e
∈
E
′
:
This operation removes a cycle endblock
B
= (
V
B
;E
B
), deleting from
C
all edgesin
E
B
, and the nodes in
V
B
\
cv
(
B
) and marks
cv
(
B
). In other words, a
cycleshrink
operation collapses the cycle endblock in a single marked node. Note that, a path
p
=(
n
1
;:::;n
k
) on a triple (
C
′
;
′
;
′
) resulting from the application of some
cycleshrink
operations corresponds to a trail on the srcinal triple (
C;;
).Another elementary operation is described by the following denition.
Denition 4.
Given a triple (
C;;
)
; C
=(
V;E
), let (
i;j
)
∈
E
. The transformation thatcollapses the edge (
i;j
) in a single marked node, is called an
edgecollapse
of theedge (
i;j
).In the rst phase of the algorithm, the transformations
edgeshrink
and
edgecollapse
are employed in the following function.
function
preprocessing
((
C;;
))
beginwhile
(a leaf
i
such that
(
i
) = 0 exists in
C
)
edgeshrink
(
i;ad
(
i
));
while
(an edge (
i;j
)
∈
E
′
exists such that (
(
i
)
6
2)
and
(
(
j
)
6
2))
edgecollapse
(
i;j
);
end
Function
preprocessing
consists of an iterative procedure, in which rst all leaves
i
not marked are removed from
C
, and
(
ad
(
i
)) is set to 1. In fact, given a leaf
i
not marked, marking the node
ad
(
i
) means that a trail
t
must pass in
ad
(
i
). Hence,the edge (
i;ad
(
i
)) will be dominated by
t
, regardless if
i
belongs or not to
t
. In thesecond part of the function, an edge (
i;j
) is collapsed in a single marked node if
i
and
j
have both degree not greater than two. As consequence, if
C
is a path, this functiontransforms
C
in a single marked node. In Fig. 1, a cactus graph with marked nodes,and the resulting cactus after function
preprocessing
has been applied, are reported. Note that an optimal solution for the problem of nding
MCDTS
on a triple (
C;;
)transformed by operations of Denition 3, and by function
preprocessing
is also optimalfor the srcinal triple.
P. Detti, C. Meloni/Discrete Applied Mathematics 136 (2004) 197–215
201
marked nodes
ba
Fig. 1. (a) A cactus and (b) the cactus after the preprocessing phase.
3. Theoretical results
In this section the theoretical foundations of the algorithm reported in Section 4 are presented. We refer to the triple (
C;;
)
; C
= (
V;E
), as the triple obtained applyingthe function
preprocessing
to the srcinal triple (
C
0
;
0
;
0
)
; C
0
= (
V
0
;E
0
), in which
0
(
i
)=0
;
∀
i
∈
V
and
0
(
e
)=0
;
∀
e
∈
E
0
. Note that in
C
, all leaves are marked. In thefollowing, we deal with the problem of nding
MCDTS
on (
C;;
).The basic idea of the algorithm is to iteratively
process
the endblocks of the cactus
C
. An edge endblock
B
=(
i;j
), with
j
=
cv
(
B
), is
processed
by the following function
visit
.
function
visit
((
C;;
)
;B
= (
i;j
))
begin
edgeshrink
(
B
);link
j
to
i
with a pointer.
end
This function removes the edge
B
= (
i;j
),
j
=
cv
(
B
), and the marked node
i
from(
C;;
), marks the node
j
, and links the cut vertex
j
with a pointer to the removednode. A pointer from
j
to
i
means that a trail passing in
i
there exists in
c
. In thefollowing, we say that a node
j
has a pointer if there exists a pointer from
j
to another node.Since pointers are possibly associated by
visit
to some nodes, we classify the end blocks of a cactus into two sets
EB
1 and
EB
2. The set
EB
1 contains the endblocks
B
=(
V
B
;E
B
) whose nodes in
V
B
\
cv
(
B
) have no pointer. The second set
EB
2 containsendblocks
B
= (
V
B
;E
B
), in which nodes with pointers in
V
B
\
cv
(
B
) exist.At each iteration of the algorithm, rst the endblocks in
EB
1 are processed, and thenthe endblocks in
EB
2 are considered. In the following, results concerning endblocksof the set
EB
2 are presented. The Lemma 5 allows to build the trails of a minimumcardinality dominating trail set linking up two adjacent pointers that are associated toa node of an edge or a cycle endblock in
EB
2.
Lemma 5.
Consider a triple
(
C;;
),
where
C
is a cactus not containing endblocksin the set
EB
1.
Let
B
= (
V
B
;E
B
)
be an endblock
,
let
n
1
∈
V
B
be a node having at