Influence of the tie-break rule on the end-vertex problem

End-vertices of a given graph search may have some nice properties, as for example it is well known that the last vertex of Lexicographic Breadth First Search (LBFS) in a chordal graph is simplicial, see Rose, Tarjan and Lueker 1976. Therefore it is interesting to consider if these vertices can be recognized in polynomial time or not, as ﬁrst studied in Corneil, K¨ohler and Lanlignel 2010. A graph search is a mechanism for systematically visiting the vertices of a graph. At each step of a graph search, the key point is the choice of the next vertex to be explored. Graph searches only differ by this selection mechanism during which a tie-break rule is used. In this paper we study how the choice of the tie-break in case of equality during the search, for a given graph search including the classic ones such as BFS and DFS, can determine the complexity of the end-vertex problem. In particular we prove a counterintuitive NP-completeness result for Breadth First Search solving a problem raised in Corneil, K¨ohler and Lanlignel 2010.


Introduction
A search is a mechanism for systematically visiting the vertices of a graph.For graph searches, we will use the terminology and notation defined in [7] which are now quite standard, and we will consider that every graph search S will output its visiting-ordering σ, that is to say the order in which the vertices of the graph are visited by the algorithm.We will call σ an S-ordering.Considering a search will therefore mean here considering the set of all possible orderings produced by this search.
At each step of a graph search, the key point is the choice of the next vertex to be explored.Graph searches only differ by this selection mechanism during which a tie-break rule is used.As an example, for a Generic Search any neighbour of the already visited vertices is eligible.Any other graph search we are interested in (BFS, DFS, LDFS,...) is a specialisation of the Generic Search, and therefore inherits its behaviour with respect to connectivity.Since any generic search traverses the connected components of a graph one by one in any order, if we want to know whether or not a vertex t can be the last vertex of some search S on some graph G, it is enough to consider the end-vertex problem on the graph induced by the connected component of G that contains t.Therefore, in the following, G = (V, E) will always denote a connected graph with n vertices and m edges.
In this paper we focus on the vertices that appear as the last vertex of various searches.Such a vertex often has nice properties with many uses in graph algorithms.Let us give a few examples.
• If the graph is chordal, any last vertex of a LBFS is simplicial and this is used to recognize chordal graphs in [16,18].Similarly for LDFS, since it is a MNS (Maximal Neighbourhood Search) we know from [17] that it provides a simplicial elimination scheme for chordal graphs.
• If the graph is a cocomparability graph, any last vertex of a LBFS, can be used as a source (resp.sink) in some transitive orientation of its complement (which is a comparability graph by definition).This result was first proved in [14].This is used in a transitive orientation algorithm for comparability graphs [12].
• For arbitrary graphs, any last vertex of a LBFS belongs to a moplex [3].Furtehrmore for arbitrary graphs, using [19] the last vertex of a LDFS belongs to a moplex M (a subset which is both a clique and a module).Furthermore the vertices of M appear consecutively in the LDFS ordering.
• For BFS, the last vertex is also important as it can be used as a heuristic to design fast algorithms for diameter computations [8].
• For DFS, we have no example of application in which finding the last vertex of a DFS is involved.But the question were asked in [6], and for sake of completion we have studied its complexity.
It seems natural to ask if one can recognize or compute the end-vertices of these searches.This problem was first studied in [6].Let us state it more formally.

Beginning-end-vertex problem for a search S:
Input: A graph G = (V, E), and 2 vertices s and t.Question: Is there σ an S-ordering of V such that σ(1) = s and σ(n) = t?
End-vertex problem for a search S: Input: A graph G = (V, E), and a vertex t.Question: Is there σ an S-ordering of V such that σ(n) = t?
A graph is a bipartite graph if it contains no odd cycle.It is weakly chordal if it contains no induced cycle of length greater than four, and chordal if it contains no induced cycle of length greater than three.Alternatively, a graph is chordal if it is the intersection graph of subtrees of a tree.A chord xy in an even cycle C is odd, when the distance in C between x and y is odd.A graph is strongly chordal if it is chordal and every cycle of even length at least 6 has an odd chord.A graph G is a split graph if both G and G are chordal.A graph is a path graph if it is the intersection graph of paths in a tree.
In [6], it was proven that it is NP-complete to determine if a given vertex could be last in a LBFSordering.For basic searches such as BFS and DFS the question was left open.The purpose of this paper is to discuss the complexity of the end-vertex problem for several searches, and for several classes of graphs.In particular we will prove NP-completeness of the end-vertex problem for both BFS and DFS.The results are summed up in the following table.Results in bold typeface are from the present paper.
The proof of many NP-completeness results follow from the NP-completeness result for a subfamily of graphs.For example for DFS, we prove that the problem is NP-complete for strongly chordal split graphs, and from that it follows the same for all superclasses, like, split, chordal, weakly chordal and the class of all graphs.For unknown cases, we write in italic and between brackets our conjectures if any.Even if a LDFS order is a special type of DFS, complexity results cannot be transfered from one to the other.Consider for example the class of split graphs, where the DFS end-vertex problem is NP-complete whereas the LDFS version is in P. Having said that, we cannot show that such a connection does not exist between BFS and LBFS.

End
The paper is divided in the following way.In the next section, we discuss the problem for generic search and generic layered search.Sections 3 and 4 are devoted to BFS, LBFS, DFS, LDFS.The last section contains the conclusion and a discussion on open problems.We will not always define precisely each of these searches.The reason for that is that we will use characterizations of points conditions of the orderings produced by these searches, called 'four points condition'.The reference for these results is [7], let us recall it here.
Theorem 1.1 (Four points conditions) Let G = (V, E) be a graph.Let < σ be a total order on the vertices of G. Define a triple of vertices (a, b, c) to be a characteristic triple if a < σ b < σ c, ab ∈ E and ac ∈ E.
• < σ is a BFS-ordering if and only if for every characteristic triple (a, b, c), there exists d such that d < σ a, db ∈ E.
• < σ is a LBFS-ordering if and only if for every characteristic triple (a, b, c), there exists d such that d < σ a, db ∈ E and dc ∈ E.
• < σ is a DFS-ordering if and only if for every characteristic triple (a, b, c), there exists d such that a < σ d < σ b and db ∈ E.
• < σ is a LDFS-ordering if and only if for every characteristic triple (a, b, c), there exists d such that a < σ d < σ b, db ∈ E and dc ∈ E.
We will use this theorem in this paper very often, and we will refer to it as the 'four points condition'.
Using the classification of graph searches defined in [7], the most basic graph search is the Generic Search.It is the search that at each step visits any vertex that has a previously visited neighbour.(See algorithm 1.): In this section, we will prove that the end-vertex and the beginning-end-vertex problems for the generic search can be solved in linear time.To do so, we will first give a characterization of the end-vertices of generic search: We will need the following proposition: Proposition 2.2 Let G = (V, E) be a connected graph.σ is a generic-ordering of G if and only if every vertex σ(i), i > 1 has a neighbour in σ(1 . . .i − 1).
Proof: Immediate from the definition. 2 Proof of Theorem 2.1: By assumption, we can assume that G is connected.Assume, by contradiction that t is an articulation point of G, and that there exists σ a generic-ordering of G such that t is last in σ.
Conversely, assume that t is not an articulation point of G. Take any generic-ordering Since articulation vertices can be computed in linear time [13], we immediately have: Corollary 2.3 The end-vertex and the beginning-end-vertex problems for the generic search can be solved in linear time.

Layered Searches
A layered search is a search that at each step, selects a vertex among the unselected vertices that are at minimal distance from the source vertex.Hence, the end-vertices of such searches are simply the vertices that are furthest from some other vertex.Since it is polynomial to compute all pairs of distances, the endvertex problem is polynomial for the generic layered search.Several implementations of layered searches, such as BFS or LBFS, have been introduced using different tie-break rules to choose the next vertex to be visited.In the following, we will see how these rules influence the complexity of the end-vertex problem.

Breadth First Search BFS
Here, we will follow the definition of BFS given in [11], that is a graph search in which the vertices that are eligible are managed with a queue (note that it differs for example from the definition given in [5], where BFS stands for what we call here layered search).This is the most common implementation of a layered search.The main result of this section is the fact that even for the class of bipartite graphs, the end-vertex problem for BFS is NP-complete.After that we prove that the same holds for weakly chordal graphs, that is graphs that do not contain any hole of length at least 5 (recall that a hole is an induced cycle).The main open question is about chordal graphs, so we prove at the end of this section that the problem is polynomial for a subclass of chordal graphs, called split graphs.

Bipartite graphs : NP-complete
Theorem 3.1 Given a bipartite graph G and a vertex v of G, it is NP-complete to decide if there exists an execution of BFS on G such that v is the end-vertex.
To prove Theorem 3.1, we will first prove the following theorem: Theorem 3.2 The beginning-end-vertex problem for BFS is NP-complete on bipartite graphs.
To do so, we use a reduction from 3-SAT.To this purpose, we use a family of auxiliary graphs.Definition 3.3 For every n ∈ N we define a graph G n , which has one special vertex r n called the root.It is constructed recursively as follows : • G 0 is the graph with one vertex r 0 .
• G n is constructed from G n−1 by first adding three vertices : the new root r n , and its two neighbours y n and y n , that are also adjacent to r n−1 .Finally we attach a path of 2n − 1 new vertices to y n (respectively y n ) and label its end-vertex x n (respectively x n ).
The following properties are straightforward from the definition.Proposition 3.4 G n is a bipartite graph that has (2n+1)(n+1) vertices that all are at distance at most 2n from r n .There are 2n + 1 vertices at distance exactly 2n from r n , and these are x 1 , x 1 , x 2 , x 2 , . . ., x n , x n and r 0 .
The following proposition is central to the reduction and concerns the order that we obtain on those 2n + 1 vertices when we do a BFS starting at the root.Proposition 3.5 Consider an order on the vertices of G n given by an execution of a BFS starting at r n .For each 1 ≤ i ≤ n at most one of x i and x i is before r 0 .Moreover each of the 2 n choices of one among x i and x i for each i, can be obtained as the set of vertices that appear before r 0 for some BFS order of Fig. 1: The graph G2.
Proof: We prove this by induction on n.For n = 0 there is nothing to prove.Assume the result is true for G n−1 .Starting at r n , the BFS either continues with y n then y n , or the converse.On the next layer, the vertices at distance two from r n , there are three vertices : r n−1 and the two neighbours of y n and y n on their path of size 2n − 1 (call these y n and y n ).On this layer, it is easy to see that r n−1 can never be last.Moreover y n (or similarly y n ) is chosen after r n−1 , if and only if on the last layer of the graph, x n is after any of the descendants of r n−1 (and in particular r 0 ).So the property we are trying to prove is true for i = n and by choosing appropriately the order on these three elements of the second layer, we can decide to have either x n or x x before r 0 in the order.Note also that the order on the 2n − 1 descendants of r n−1 on the last layer, is exactly given by a BFS order on G n−1 so the induction hypothesis permits us to conclude the proof. 2 We are now ready to prove Theorem 3.2.
Proof of Theorem 3.2: The proof uses a reduction from 3-SAT.Given F = (x 1 . . .x n , c 1 . . .c m ) an instance of 3-SAT in which x i , 1 ≤ i ≤ n are boolean variables and c j , 1 ≤ j ≤ m are clauses.We construct a graph G F by taking the graph G n along with m + 1 new vertices c 1 , . . ., c m and t.Each vertex c i corresponds to the clause of the same name in F and has neighbours in G n exactly the vertices x i or x i that appear in it.Finally the vertex t has only one neighbour which is r 0 .Note that these m + 1 vertices are the only vertices at maximum distance 2n + 1 from the root r n .We now claim that there exists a BFS execution on G F starting at r n and ending at t if and only if F is satisfiable.For any execution of BFS, we associate a truth assignment of the variables in F thanks to Proposition 3.5 as follows: we know that at most one of x i and x i is before r 0 in this order, and we choose this one to be the true literal.If both appear after r 0 , then we choose arbitrarily one of the two.Note now that since t has only r 0 as a neighbour, a vertex c i in the last layer will be before t in the order if and only if one of its neighbours (i.e. one of the literals appearing in it) was chosen before r 0 on the previous layer.In other words, c i is before t if and only if the associated clause is true with the assignment described above, which proves the only if part of our claim.Conversely if F is satisfiable, then we use the second part of Proposition 3.5 to get a BFS that sorts all the true literals before r 0 among the vertices at distance 2n.Then the previous observation on the c i implies that t must be the last vertex, which concludes this proof.2 We are now ready to prove our main result.Proof of Theorem 3.1: This proof uses a reduction from the beginning-end-vertex for BFS.Given G = (V, E), s ∈ V, t ∈ V , an instance of the beginning-end-vertex for BFS, we build G , an instance of the end-vertex problem by adding a pendant path p of size d(G) + 1 (where d(G) is the diameter of G) to s.Now, every BFS that ends in t will have to begin at some vertex of p, and will visit s as the first vertex of G. 2 In fact using a slightly more complicated construction, it is even possible to prove the following stronger result.
Theorem 3.6 The end-vertex problem for BFS is NP-complete on bipartite graphs of maximum degree 3.
As it is very similar to the proof of Theorem 3.1, we will not write the proof of this result, we just give the construction of the subcubic bipartite graph that gives the reduction to 3-SAT.For every n ∈ N we define a graph G n , which has one special vertex r n called the root.It is constructed recursively as follows : • G 0 is the graph with one vertex r 0 .
• G n is constructed from G n−1 by first adding four vertices : the new root r n , and its two neighbours y n and y n .Both are also adjacent to the fourth vertex, r n−1 .We add an edge between r n−1 and r n−1 , and finally, we attach a path of 3n − 1 new vertices to y n (respectively y n ) and label its end-vertex x n (respectively x n ).
Now let F = (x 1 . . .x n , c 1 . . .c m ) be an instance of 3-SAT in which x i , 1 ≤ i ≤ n are boolean variables and c j , 1 ≤ j ≤ m are clauses.For each literal x i , let c(x i ) be the number of clauses in which x i appears.
Construct a graph G F the following way : start with graph G n defined above and to each vertex x i of the construction, we attach a tree T (x i ) such that: x i is the root of the tree, T (x i ) contains exactly c(x i ) leaves that are all at distance log(m) from x i , x i has at most 2 children, and no vertex of T (x i ) has a degree bigger than 3.
Finally, for every clause vertex c j such that c j contains the literal x, x , x , we make the vertex that corresponds to c j adjacent to one leaf of T (x), one of T (x ) and one of T (x ), in such a way that all the leaves of the T (x i ) have degree 2, and we attach a path of length log(c) + 1 to r 0 , and we call the other end of this path t.
Proof of Theorem 3.6: This new construction behaves similarly as the previous one and the proof directly follows. 2

Weakly chordal graphs : NP-complete
Definition 3.7 Let G = (V, E) be a graph.The distance layers of a BFS of G that starts at s are the sets is the distance between s and x in G.
Proposition 3.8 A graph G = (V, E) is weakly chordal if there exists s ∈ V such that every distance layer of a BFS starting at s induces a clique of G.
Proof: Since every distance layer of a BFS that starts at s induces a clique, no induced hole can contain more than two vertices of the same layer.Moreover, no induced hole H of G can span over more than two distance layers of some BFS of G that starts at s. Assume by contradiction that H spans over L s i−1 , L s i , L s i+1 .H must contain 2 vertices of L i , or else H ∩ L s i would be a 1-cutset of H (by definition there are no edges between any vertex of L s i−c and any vertex of L s i+c , for any c and c positive integers), but then H would contain a chord.In this case, no induced hole of G can contain more than 4 vertices, and thus G is a weakly chordal graph.
2 Definition 3.9 Let G = (V, E) be a graph, and let s be any vertex of G.The graph G + s is the graph G in which every distance layer of a BFS starting at s has been turned into a clique.More formally, Lemma 3.10 Let G = (V, E) be a graph, and let σ be any permutation of V such that σ(1) = s.σ is a BFS-ordering of G if and only if σ is a BFS-ordering of G + s .
Proof: First, assume that σ is a legitimate BFS-ordering of G.We will show that σ respects the four points condition for BFS on G + s .Consider a triple a, b, c such that a < σ b < σ c, ac ∈ E ∪ E + , and ab / ∈ E ∪ E + .ab / ∈ E ∪ E + implies ac ∈ E. Indeed, the distance layers of any BFS appear consecutively in the BFS-order, so if ac was an edge of E + , a, b, and c would belong to the same distance layer, which by definition, would imply that ab ∈ E ∪ E + .
In this case, the four points condition applied in G to the triple a, b, c implies the existence of d < σ a such that bd ∈ E, and so bd ∈ E ∪ E + .
Conversely, assume that σ is a legitimate BFS-ordering of G + s .We will show that σ respects the four points condition for BFS on G. Consider a triple a, b, c such that a < σ b < σ c, ac ∈ E, and ab / ∈ E. Since σ respects the four points condition for BFS in G + s , we have to distinguish two cases.
1. ab ∈ E + .In this case, by definition, a and b belong to the same distance layer.Since b is not the first vertex of σ, b must have a neighbour in G that belongs to the previous distance layer.In other words, there exists d < σ a such that bd ∈ E.
2. ab / ∈ E + .In this case, since σ is a legitimate BFS-ordering of G + s , there exists d < σ a such that bd ∈ E ∪ E + .If bd ∈ E, we are done, so assume bd ∈ E + .By definition, d, a, and b belong to the same distance layer, but then ab ∈ E + , a contradiction.

2
Theorem 3.11 The beginning-end-vertex problem for BFS on weakly chordal graphs is NP-complete.
Proof: The proof uses a reduction from 3-SAT.Consider any instance F of 3-SAT, and let G F be the graph defined in the proof of Theorem 3.2.Consider G + Fr n .By Theorem 3.2, F is satisfiable if and only if there exists σ a BFS-ordering of G F such that σ(1) = r n and σ(n) = t.By Lemma 3.10, the BFSorderings of G F that starts at r n are the same as the BFS-orderings of G + Fr n that start at r n .Since G + Fr n is weakly chordal by Proposition 3.8, we can conclude.2 Using the same construction as in Theorem 3.1 we have the following: Proof of Theorem 3.18: Note that since a split graph is chordal, the last vertex t of any LBFS order is simplicial.It is straightforward to check that in a split graph, this implies that there exists a bipartition (S, K), where t ∈ S. It implies in particular that D t ⊂ S, and N (t) ⊂ K.This will always be the case in the rest of the proof.
Let us prove first that the 3 conditions imply that t is the last vertex of some LBFS-ordering of G.  3), the labels of the vertices of S\D t and the label of t will all be equal, and will contain the numbers of the vertices of N (D t ).This will also be the case of the labels of the remaining vertices of K. Thus, it is possible to visit the vertices of K\N (t), then the vertices of N (t)\N (D t ).Since t does not dominate the vertices of S\D t , the vertices of S\D t either have a private neighbour in K, or are twins of t.For the first case, the labels of those vertices will receive the number of their private neighbour in K before any other update of the label of t, i.e. the label of t will be smaller than the label of these vertices, and so t and its twins will be visited after them.It remains to visit the twins of t before t.Since N (t) has already been visited, and since all these vertices belong to S, visiting a twin of t will not modify the label of any unvisited vertex, and since t and its twins have the same label at this point of the search, a LBFS can visit them in any order, including one that has t as end-vertex.
So now it remains to prove the converse direction, and thanks to Corollary 3.17 and the fact that every LBFS is a MNS, we only need to prove (3).Let us begin with two useful claims.
Claim 1 : there exists no triplet a < σ b < σ c with b ∈ S, c ∈ K such that ab ∈ E and ac ∈ E Assume such a triplet exists.Thus, the four points condition implies the existence of u < σ a such that ub ∈ E and uc ∈ E. But since b is in S which is a stable set, it implies that u is in K which contradicts uc ∈ E. Claim 2 : there exists no triplet a < σ b < σ c with a ∈ S, b ∈ K, and c ∈ K such that ab ∈ E and ac ∈ E Assume that such a triplet exists.Thus, the four points condition implies the existence of u < σ a such that ub ∈ E and uc / ∈ E. Since c ∈ K, this implies that u ∈ S, which implies that ua ∈ E. Now we get a contradiction by Claim 1 applied to (u, a, b).Now we are able to finish the proof.Assume by contradiction that there exists x ∈ S\D t , d ∈ D t , such that x does not dominate d.By definition of x, there exists k ∈ K such that k ∈ N (x) \ N (t).We choose k to be leftmost in σ with respect to this property.Define also We prove a sequence or facts regarding the respective positions of these 6 vertices in the order σ.
• d < σ k : indeed if not, we can apply the four points condition on (k , d, t) to get a neighbour of d, which is not a neighbour of t, contradiction.
• d < σ k : previous fact plus Claim 1 applied to (k, d, k ) • k < σ k : previous fact plus Claim 2 applied to (d, k, k )

Weakly chordal graphs : NP-complete
The proof will use a reduction from 3-SAT.Let I be an instance of 3-SAT.Assume, without loss of generality, that I contains at least 4 variables, and that no clauses contain a literal and its complement.We build a graph G associated with I.The variables will be represented by M , the complement of a matching, with every non-edge standing for a literal and its complement.Add 2 non-adjacent vertices u and v, both universal to M .Let t be only adjacent to v.For each clause c j , create a vertex adjacent to the literals c j contains.Proof: Any LDFS of G that starts at u must next visit a maximal (w.r.t.inclusion) clique of N (u).By construction, such a clique K is a subset of M .K cannot contain both a literal and its complement since their corresponding vertices are non-adjacent, and in order for K to be maximal, it must contain at least one vertex from each literal and its complement.Since |K| ≥ 4, no clause vertex is universal to K, and the same holds for any remaining literal vertex by construction.Since v is universal to K, the label of v is larger than any other unvisited vertex of G, and so v must be visited at this point.
Since t is only adjacent to v, its label is smaller than the labels of the vertices of M \K (since they are all adjacent to v and u), so the next visited vertex (that must be a neighbour of v) is x ∈ M \K.The remaining vertices of M \K will always have a larger label than the clause vertices, since they are all pairwise adjacent, and all adjacent to v, contrary to the clause vertices that may be adjacent to all the vertices of M \K that have been visited at some point, but that are non-adjacent to v by construction.2 Corollary 4.4 For every truth assignment f , there exists σ a LDFS-ordering of V such that σ(1) = u and that the vertices corresponding to the true literals of f appear after v in σ.
Proof: Let F be the set of the vertices corresponding to the true literals of f , and F be the set of the vertices corresponding to the false literals of f .F and F both induce a clique of G, so there exists a LDFS of G such that F = K. 2 Proposition 4.5 There exists a LDFS-ordering σ of V starting at u and ending in t if and only if f is satisfiable.
Proof: Consider any LDFS-ordering σ of V with σ(1) = u and σ(n) = t.We build a truth assignment I satisfying f by choosing for each variable x i of f , the literals that appear after v to be the true literals.By Proposition 4.3, we know that for every literal l and its complement, at most one appears after v.
If no literal corresponding to x i appears after v, we assign any value to x i .By Proposition 4.3, every clause vertex lies between v and t.In this case, by the four points condition, each triple v, c i , t implies the existence of a neighbour of c i between v and c i , i.e. a true literal for the clause c i .Conversely, assume that there exists I a truth assignment that satisfies f .Let F be the set of the vertices corresponding to the true literals of I, and F be the set of the vertices corresponding to the false literals of I.By corollary 4.4 and proposition 4.3, there exists a LDFS of G that first visits u, F , v, F .It only remains to prove that no c i can appear after t in σ.Assume by contradiction that c > σ t.Since I satisfies

Conclusion and Perspectives
We have proven a variety of results concerning the end-vertex problem for several graph searches, solving some problems raised in [6].The main open question that remains is the complexity on chordal graphs of the end-vertex problem for BFS, LBFS, and LDFS.
Moreover, in [6], a very simple linear time algorithm for the end-vertex problem for LBFS on interval graphs is presented.We do not know if this extends to path graphs or cocomparability graphs (i.e.complements of comparability graphs).Since it is proven in [9] that for recognition LBFS behaves the same on interval graphs and comparability graphs, let us conjecture that the end-vertex problem for LBFS is polynomial on both classes.
It could also be interesting to find a class of graphs for which BFS and LBFS behave differently for the end-vertex problem.

Proposition 4 . 3
Any LDFS of G that starts at u must next visit a maximal (w.r.t.inclusion) clique K of M , such that |K| = |M |/2 and that K contains exactly one vertex from each literal and its complement, then v, then M \K.