Graph Searches and Their End Vertices

Graph search, the process of visiting vertices in a graph in a specific order, has demonstrated magical powers in many important algorithms. But a systematic study was only initiated by Corneil et al.~a decade ago, and only by then we started to realize how little we understand it. Even the apparently na\"{i}ve question"which vertex can be the last visited by a graph search algorithm,"known as the end vertex problem, turns out to be quite elusive. We give a full picture of all maximum cardinality searches on chordal graphs, which implies a polynomial-time algorithm for the end vertex problem of maximum cardinality search. It is complemented by a proof of NP-completeness of the same problem on weakly chordal graphs. We also show linear-time algorithms for deciding end vertices of breadth-first searches on interval graphs, and end vertices of lexicographic depth-first searches on chordal graphs. Finally, we present $2^n\cdot n^{O(1)}$-time algorithms for deciding the end vertices of breadth-first searches, depth-first searches, maximum cardinality searches, and maximum neighborhood searches on general graphs.


Introduction
Breadth-first search (BFS) and depth-first search (DFS) are the most fundamental graph algorithms, and the standard opening of a course on this subject. Their use can be found, sometimes implicitly, in most graph algorithms. In general, a graph search is a systematic exploration of a graph, and its core lies on the strategy of how to choose the next vertex to visit. Mostly greedy, graph searches are very simple but sometimes have magical powers. DFS has played a significant role in Tarjan's award-winning work, in testing planarity [19] and in finding strongly connected components [27].
Two other search algorithms, lexicographic breadth-first search (LBFS) [23] and maximum cardinality search (MCS) [28], were invented for the purpose of recognizing chordal graphs, i.e., graphs not containing any induced cycle on four or more vertices. On a chordal graph, both LBFS and MCS produce perfect elimination orderings (see definition in the next section) of the graph, which exist if and only if the graph is chordal. Albeit relatively less well known compared to BFS and DFS, LBFS and MCS did find important applications. LBFS is used in scheduling [24], and is the base of the recent linear-time algorithm for computing modular decomposition of a graph [29]. Tarjan and Yannakakis [28] also used MCS in testing acyclic hypergraphs. Nagamochi and Ibaraki [21] rediscovered MCS and applied it to compute minimum cuts of a graph and find forest decompositions; see also [22].
Simon [26] proposed an interesting way of using LBFS. It conducts LBFS more than once, and each new run uses previous runs in breaking ties; in particular, except the first, each run starts from the last vertex of the previous run. This generic approach turns out to be very useful, e.g., the extremely simple recognition algorithm for unit interval graphs [8]. See the survey of Corneil [7] for more algorithms using multiple runs of LBFS. Some of these results have a flavor of "ad-hoc": We do not fully understand the execution process of LBFS. The outputs of BFS and DFS are usually rooted spanning forests of the graph, while LBFS and MCS produce orderings of its vertices. To have a unified view of them, Corneil et al. [11] focused on the ordering of the vertices being first visited and conducted a systematic study of them. 1 This study motivates them to propose the lexicographic version of DFS, lexicographic depth-first search (LDFS), another very powerful graph search [9], and a very general search paradigm, maximum neighborhood search (MNS). They showed that all the aforementioned graph searches can be characterized by variants of the so-called four-vertex condition. These nice characterizations are however not sufficient to allow us to answer the ostentatiously naïve question: Which vertex can be the last of such an ordering? Corneil et al. [10] defined the end vertex problem and studied it from both combinatorial and algorithmic perspectives. Apart from a natural starting point of understanding the graph searches in general, end vertices of graph searches are of their own interest. Behind the original use of LBFS and MCS, in the recognition of chordal graphs, is nothing but the properties of their end vertices, which are always simplicial on a chordal graph [23,28,25,4]. Moreover, the success of multiple-run LBFS crucially hinges on the end vertices; e.g., an end vertex of a (unit) interval graph can always be assigned an extreme (i.e., leftmost or rightmost) interval [8,13]. Important properties and use of end vertices of other graph searches can be found in [9,17,12].
One may find it surprising, but the end vertex problem is NP-hard for all the six mentioned graph search algorithms [11,6,1]. The study has thus been focused on chordal graphs and its closely related superclasses and subclasses. After all, LBFS and MCS were invented for recognition of chordal graphs, and their properties on chordal graphs have been intensively studied. (This renders the stagnation on chordal graphs a little more embarrassing.) Moreover, most applications of LBFS and LDFS are on related graph classes. The most natural superclass of chordal graphs is arguably the weakly chordal graphs, and two important subclasses are interval graphs and split graphs. It has been known that on weakly chordal graphs, the end vertex problems for all but MCS are NP-complete, while only DFS end vertex is NP-complete on chordal graphs [11,6,1]. There are other polynomial-time algorithms for interval graphs and split graphs, most of which actually run in linear time. We complete the pictures for, in terms of graph searches, MCS and LDFS, and, in terms of graph classes, weakly chordal graphs and interval graphs. A summary of known results is given in Figure 1.  [6,1] DFS [6] all [10, 6, 1] P NPC Figure 1: A summary of the known complexity of the end vertex problem for the six graph search algorithms. For each graph class, the end vertex problem of graph searches listed to the left of it can be solved in polynomial time on this class, while those to the right are NP-hard. The complexity of the BFS end vertex and LBFS end vertex problems on chordal graphs are still open.
Blair and Peyton [5] and Galinier et al. [16] have shown that MCS of a chordal graph are closely related to its maximal cliques. Let G be a chordal graph. An MCS visits all vertices in a maximal clique of G before proceeding to another, and the next maximal clique is always chosen to have the largest intersection with a visited one. Therefore, for a minimum separator S of G, there is an MCS visiting the components of G − S one by one, with S visited together with the first component. If we turn to any component C of G − S, and consider its closed neighborhood, (which contains C and S,) then we have a similar statement. In other words, this property on minimum separators hold in a recursive way. For an MCS end vertex z, which is necessarily simplicial, we can find a sequence of increasing separators such that the first is a minimum separator of G and the last comprises all the non-simplicial vertices in N(z). An MCS ended with z has to "cross" these separators in order, and for each of them, visit the component containing z in the last. We have thus a full understanding of all MCS orderings of a chordal graph. As it turns out, this result is easier to be presented in the so-called weighted clique graph of G [5,16]. It enables us to show that if we run MCS twice, first starting from z, and the second starting from the end vertex of the first run and using the first ordering to break ties, then the second run ends with z if and only if z is an MCS end vertex. As usual, n denotes the number of vertices in the input graph. We then turn to LDFS on chordal graphs. Surprisingly, the characterization of Berry et al. [3] for end vertices of MNS on chordal graphs is also true for LDFS: A simplicial vertex z of a chordal graph G is an LDFS end vertex if and only if the minimal separators of G in N(z) are totally ordered by inclusion. We also show a simple algorithm for solving the BFS end vertex problem on interval graphs. We have to, nevertheless, leave open the BFS and LBFS end vertex problems on chordal graphs. Since both can be solved in linear time on split graphs, we conjecture that they can be solved in polynomial time on chordal graphs. It is extremely rare that a problem is hard on chordal graphs but easy on split graphs.
We also consider algorithms for solving the end vertex problems on general graphs. By enumerating all possible orderings, a trivial algorithm can find all end vertices of any graph search in n! · n O(1) time. On the other hand, with the only exception of BFS, the reductions used in proving NP-hardness of the end vertex problems are linear reductions from (3-)SAT. As a result, these problems cannot be solved in subexponential time, unless the exponential time hypothesis fails [20]. A natural question is thus which of them can be solved in 2 O(n) time. If we put them under closer scrutiny, we will see that these graph searches are somewhat different: When selecting the next vertex, MCS only needs to know which vertices have been visited, while the order of visiting them is immaterial. In contrast, the other graph searches are not oblivious and need to keep track of the whole visiting history. Therefore, it is quite straightforward to use dynamic programming to solve the MCS end vertex problem in 2 n · n 2 time. We also manage to show that a similar approach actually works for the BFS and DFS end vertex problems. Theorem 1.4. There are 2 n · n O(1) -time algorithms that solve the end vertex problems of the following graph searches: MCS, BFS, and DFS.

Preliminaries
All graphs discussed in this paper are undirected and simple. The vertex set and edge set of a graph G are denoted by, respectively, V(G) and E(G), and we use n = |V(G)| and m = |E(G)| to denote their cardinalities. For a subset X ⊆ V(G), denote by G[X] the subgraph of G induced by X, and by The degree of a vertex v is the number of neighbors it has, i.e., A set S of vertices is a u-v separator if u and v are not in S and they are not connected in G − S, and a u-v separator is minimal if no proper subset of S is a u-v separator. We say that S is a (minimal) separator if it is a (minimal) u-v separator for some pair of u and v, and it is a minimum separator of G if it has the smallest cardinality among all separators of G.
An ordering σ of the vertices of G is a bijection from V(G) → {1, . . . , n}. For two vertices u and v, we use u < σ v to denote σ(u) < σ(v). The end vertex of σ is the vertex z with σ(z) = n. Given a graph G and a vertex z ∈ V(G), the end vertex problem for graph search S is to determine whether there is an S-ordering of G of which z is the end vertex.
A graph is chordal if it contains no induced cycle on four or more vertices. A graph is chordal if and only if it can be made empty by removing simplicial vertices from the remaining graph one by one; the order of the vertices removed is called a perfect elimination ordering [15]. The greedy strategy of MCS is to choose an unvisited vertex with the maximum number of visited neighbors. On a chordal graph G, the last vertex of any MCS is simplicial, and thus the reversal of an MCS ordering is always a perfect elimination ordering [28].
To avoid unnecessary digressions, we consider only connected graphs. All the results can be easily generalized to general graphs.

Maximum cardinality search on chordal graphs
Another important characterization of chordal graphs is through its maximal cliques. A graph G is chordal if and only if we can arrange its maximal cliques as a tree such that for each vertex v ∈ V(G), maximal cliques containing v induce a subtree; such a tree is called a clique tree of G [14]. A chordal graph G has at most n maximal cliques [14], and for any pair of adjacent K i and K j on the clique tree, the intersection K i ∩ K j is a minimal separator of G.
Out of a chordal graph G, we can define a weighted clique graph C(G) as follows. It has vertices, where is the number of maximal cliques of G, and each vertex is labeled by a distinct maximal clique of G. To simplify the presentation, we will refer to vertices of C(G) as cliques; note that we are not going to use cliques of the graph C(G) in this paper. There is an edge between maximal cliques K i and K j , 1 i, j , if and only if K i ∩ K j is a minimal x-y separator for all x ∈ K i \ K j and y ∈ K j \ K i . We label this edge with K i ∩ K j , and set its weight to be |K i ∩ K j |. It is known that a tree on the maximal cliques of G is a clique tree of G if and only if it is a maximum spanning tree of C(G) [2,5,16], i.e., a spanning tree of C(G) with the maximum total edge weights. Proof. The if direction is from the definition of C(G). Now suppose that S is a minimal separator of G. According to Blair and Peyton [5,Theorem 4.3], any clique tree of G has two adjacent cliques whose intersection is S. Since this clique tree is a subgraph of C(G), there is an edge of C(G) with label S.
One can use Prim's algorithm to find a maximum spanning tree of G. (Although proposed for the purpose of finding a minimum spanning tree, Prim's algorithm can be easily modified to find a maximum one.) Starting from an arbitrary clique, it grows the tree by including one edge and one clique at a time, while the edge is chosen to have the largest weight among those crossing the partial tree that has been built, i.e., with one end in the current tree and the other not. In the same spirit of graph search orderings, we can define a Prim ordering to be the order maximal cliques of G being included (visited) by Prim's algorithm, applied to C(G).
Let π be an ordering of the maximal cliques of G. We say that an ordering σ of V(G) is generated by π if K u < π K v implies u < σ v, where K u and K v are the first maximal cliques in π containing u, and respectively, v. If π = K 1 , K 2 , . . . , K and c i = |K i \ i−1 j=1 K j | for 1 i , then σ can be represented as The following has been essentially observed by Blair and Peyton [5], who however only stated explicitly one direction. For the sake of completeness, we give a proof here. Here we show the if direction. Suppose that σ is generated by π. We may renumber the vertices in G such that σ = v 1 , v 2 , . . ., v n , and renumber the maximal cliques such that π = K 1 , K 2 , . . ., K . Let We show by induction that for each 1 i n, there is an MCS ordering of G of which the first i vertices are v 1 , . . . , v i ; in other words, among vertices v i , . . ., v n , vertex v i has the maximum number of neighbors in the first i − 1 vertices. It is vacuously true for i = 1. Now suppose that it is true for v p , we show that it is also true for v p+1 .
When v p+1 ∈ K 1 = K 1 , it is adjacent to all previous vertices and we are done. In the rest v p+1 ∈ K t for some t > 1. Let A = t−1 j=1 K j ; note that v p+1 ∈ A. For any q > p, let G q denote the the subgraph of G induced by v 1 , v 2 , . . . , v p , and v q . By the induction hypothesis, v 1 , v 2 , . . . , v p , v q is an MCS ordering of G q . Since G q is chordal, v q is simplicial in it. Therefore, N(v q ) ∩ A is a clique for all q > p; denote it by X q . We argue by contradiction that there must be 1 s < t such that X q ⊆ K s . We find an i with Of the first t − 1 maximal cliques, those containing K i ∩ X q and those containing X q \ K i are disjoint. Prim's algorithm always maintains a tree of visited cliques, and this tree is a subtree of a clique tree of G. Therefore, there is an x-y separator. But this is impossible because x and y are both in X q , hence adjacent.
On the other hand, v p+1 is adjacent to all vertices in K t . We can thus conclude that v p+1 has the maximum number of neighbors in {v 1 , . . . , v p }, and this completes the proof.
By Lemma 3.2, MCS orderings of a chordal graph G can be fully characterized by Prim orderings of its weighted clique graph C(G). In particular, the MCS end vertices are the private vertices of the cliques last visited by Prim's algorithm. Note that a vertex v is simplicial if and only if it belongs to precisely one maximal clique, namely, N[v], and a set of true twins can be visited in any order.

Corollary 3.3. Let z be a simplicial vertex in a chordal graph G. There exists an MCS ordering of G ended with z if and only if there exists a Prim ordering of C(G) ended with N[z].
Let S be a separator of G. We abuse notation to use C(G) − S to denote the subgraph of C(G) obtained by deleting all edges whose labels are subsets of S. The component of It is worth noting that C(G) − S cannot be mapped back to G. In Figure 2, for example, C(G) − {v 5 , v 6 } does not have edges among K 2 , . . ., K 5 , while edges Figure 2: A chordal graph G on 18 vertices (the left), and its weighted clique graph (the right), where all the omitted edge weights are 2. There are 10 maximal cliques Proof. By definition, the maximal cliques containing v are connected in any clique tree of G. Since a clique tree of G is a subgraph of C(G), these cliques also induce a connected subgraph in C(G). For any edge in this subgraph, its label contains v, hence not a subset of S. Therefore, these cliques induce the same connected subgraph in C(G) − S as in C(G).
For the second assertion, we may assume uv ∈ E(G): Both sides are trivially false when uv ∈ E(G). Suppose to the contradiction of the if direction that there is a path K 0 , . . . , (These p vertices may or may not be distinct.) Then ux 1 , x p v ∈ E(G), while x i and x i+1 are either the same or adjacent for all 1 i < p. We have thus a u-v path in G avoiding S, contradiction that S is a u-v separator.
We now consider the only if direction. Let u = x 0 , x 1 , . . . , x p = v be any u-v path in G. Note that for each 0 i p, maximal cliques containing x i induce a connected subgraph, while for each 1 j p, there is a maximal clique containing both x j−1 and x j . We can find a path in C(G) of which one end contains u and the other contains v. For each edge on this path, its label contains one of x i , 0 < i < p. Since maximal cliques containing u and v are not connected in C(G) − S, the label of at least one edge on this path is a subset of S. By the first assertion, at least one of x 1 , . . . x p−1 is in S. In other words, every u-v path intersects S. Therefore, S is a u-v separator. This concludes the proof.
We say that a minimum-weight edge e of C(G)-by Proposition 3.1, its label is a minimum separator of G,-is a critical edge for maximal clique K if one end of e is in the same component as K after all minimum-weight edges, including e, are removed from C(G). In other words, there is a path connecting K and e on which every edge has weight larger than e. In Figure 2, for example, K 6 K 7 is a critical edge for all cliques but K 9 , while K 8 K 9 and K 10 K 9 are critical edges for K 8 and K 10 respectively. The following fact explains "critical" in the name. Proposition 3.5. Let z be a simplicial vertex of a connected chordal graph G, and let S 1 , . . ., S k be the labels of all critical edges for N[z]. In any Prim ordering of C(G), cliques in the z-component of Being minimum separators of G, all of S 1 , . . ., S k have the same size; let it be t. Note that the weight of every edge in T is strictly larger than t; otherwise, we can find a path from N[z] to such an edge in T , and identify another critical edge for N[z] on this path.
Let π be any Prim ordering of C(G). We consider the first maximal clique K in T visited by π. If π(K) = 1, the edge leading to K has weight t. By Prim's algorithm, when K is visited, for each clique K with K < π K, all the edges between K and its unvisited neighbors have weight t. All edges between T and other components have weight t as well, while all edges inside T have weight > t. Therefore, the maximal cliques in T must be finished before a clique out of T is visited. This concludes the first assertion.
For the second assertion, suppose that S = S 1 = · · · = S k . We give a Prim ordering that visits cliques in T in the end. It starts from a clique not in T , and it suffices to show that all cliques out of T have been visited before the first in T . By the definition of C(G), in each component of C(G) − S, there is a maximal clique containing S. Therefore, by Proposition 3.4, there is an edge with label S between any two components of C(G) − S. In other words, the cliques not in T are connected in C(G). Since the edges connecting T and other components of C(G) − S have weight t, the minimum in C(G), Prim's algorithm can always choose another edge. Therefore, we can finish them before entering T .
Whether a simplicial vertex z can be an MCS end vertex turns out to be closely related to the critical edges for N[z]. We first present a necessary condition, which is not satisfied by v 14 and v 18 in Figure 2; we leave it to the reader to verify that they cannot be MCS end vertices. Proof. Suppose for contradiction that there are two critical edges e 1 and e 2 for N[z] with different labels. For i = 1, 2, let S i be the label of e i , and let C i denote the set of components of C(G) − S i not containing N[z]. We argue that for any U 1 ∈ C 1 and U 2 ∈ C 2 , they are different and there is no edge between them.
For i = 1, 2, by the definition of critical edges, there is a path from N[z] to e i ; let K i denote the end of e i that is closer to N[z] on this path. There must be some clique Since S 1 = S 2 and they have the same cardinality, we can find v 2 ∈ S 2 \ S 1 ⊂ K 2 . By Proposition 3.4, S 1 is not a z-v 2 separator. Thus, no maximal clique in U 1 contains v 2 . It follows that U 1 remains connected in C(G) − S 2 (note that S 2 is a minimum separator). For the same reason, U 2 remains connected in C(G) − S 1 . If there exists an edge between U 1 and U 2 , then this edge remains in at least one of C(G) − S 1 and C(G) − S 2 : It cannot have both labels S 1 and S 2 . But then U 1 and U 2 are connected in C(G) − S 1 or C(G) − S 2 , neither of which is possible.
We can thus conclude that components in C 1 ∪ C 2 are disjoint and there is no edge among them.
Let π be a Prim ordering of C(G) ended with N[z]. Assume without loss of generality that the first visited clique in these components is from U 1 ∈ C 1 , then we show that N[z] is visited before all components U 2 ∈ C 2 . Since there is no edge between U 1 and U 2 , before visiting U 2 , it must visit a clique from the z-component of C(G) − S 1 . After that, however, it will not visit any edge of label S 2 before finishing this component. Therefore N[z] cannot be the end clique, a contradiction. This concludes the proof.
In other words, if z is an MCS end vertex, then there is a unique minimum separator of G that is "closest to z" in a sense. This, although not sufficient, can be extended to a sufficient condition for MCS end vertices as follows. To decide whether a simplicial vertex z is an MCS end vertex, we can find the minimum separator S in Proposition 3.5 and focus on how the z-component of C(G) − S is explored. We have to start from a maximal clique not in it, and after that visit all maximal cliques in other components of C(G) − S before the z-component. In this juncture we may view the z-component as a separate graph and find all critical edges for N[z] with respect to this component. They also need to have the same label; suppose it is S , which is strictly larger than S. But this is not sufficient because we need to make sure that when S is crossed, it can reach a maximal clique not in the z-component of C(G) − S . In Figure 2, if we delete vertices v 16 and v 17 , (hence K 9 ,) then K 6 K 7 is the only critical edge for K 8 . The condition of Lemma 3.6 is vacuously satisfied, but v 14 is still not an MCS end vertex. (Now v 18 is.) Repeating this step recursively, we should obtain a sequence of separators with increasing cardinalities. Note that we only need to keep track of how these separators are crossed, while the ordering in each layer is irrelevant. This observation leads us to the following characterization, which subsumes Theorem 13 of Beisegel et al. [1]. For example, the sequence of critical edges for N[v 1 ] in Figure 2 are K 6 K 7 , K 2 K 5 , and K 1 K 2 , which correspond to minimal separators {v 11 }, {v 5 , v 6 }, and {v 2 , v 3 , v 4 }, respectively. Proof. We first show the if direction. We may denote the two ends of e i by K i and we visit all the other components of C(G) − S i before using the edge K i K i to enter the z-component, visiting K i . This is possible because of Proposition 3.5, and as such we produce a Prim ordering of C(G) that ends with N[z]. Now consider the only if direction, for which we construct the stated path by induction: We find the edges e 1 , e 2 , . . ., e k in order, and show that for each 1 i k, the first i edges can be extended to a path that ends with N[z] and satisfies both conditions. The first edge e 1 can be any critical edge for N[z], and it is on a path ended with N[z] because C(G) is connected. Now suppose that the first i edges, namely, e 1 , . . ., e i , have been selected, and we find e i+1 as follows. For each 1 j i, let T j denote the z-component of T j−1 − S j , where T 0 = C(G). If T i comprises the only maximal clique N[z], we are done.
Containing N[z], cliques in T i are last visited by Proposition 3.5. It is also a Prim ordering of the component itself. Therefore, Lemma 3.6 applies, and all the critical edges for N[z] in T i have the same label. Let S i+1 be this label, and let T i+1 be the z-component of T i − S i+1 . We argue that there must be a maximal clique K in T i − T i+1 containing S i ; otherwise, the first component visited in T i − S i+1 would be the z-component, and then N[z] cannot be the last visited clique. We can use edge K i K to replace e i ,-note that they have the same label,-and choose any edge between K and N[z] with label S i+1 as e i+1 . This concludes the inductive step and the proof.
The proof of the only if direction of Theorem 3.7 can be directly translated into an algorithm to decide Prim end cliques, implying a polynomial-time algorithm for the MCS end vertex problem on chordal graphs. This algorithm however has to take Ω(n 2 ) time because the size of C(G). We show a very simple algorithm below, which itself best reveals the spirit of graph searches. As long as we cross the separators in the order specified in Theorem 3.7, and make sure we finish other components before visiting the z-component, then it is the Prim ordering we need. On the other hand, a run of Prim's algorithm started from N[z] will cross the separators in the reversed order, and before crossing the ith separator S i , it has to exhaust the whole z-component C(G) − S i . For the inductive step, suppose that the induction hypothesis is true for all p with 1 i p < k, we show it is also true for p + 1. For 1 < i k, let T i be the component of T i−1 − S i containing z, and let T i be the subgraph induced by V(T i ) ∪ S i . Let v ∈ T p+1 be the vertex satisfying v < σ + u for all u ∈ T p+1 \ {v}. Then S p+1 ⊆ N(v) and x < σ + v for all x ∈ S p+1 . Since S p+1 is a minimum separator of T p , any other component of T p − S p+1 has a vertex adjacent to all of S p+1 . Such a vertex x would satisfy v < σ x because of Proposition 3.5 and Corollary 3.3, and then be chosen by step 1 before v. Now that all the vertices in G − N[z] and the non-simplicial vertices in N[z] have been visited, the only remaining vertices are true twins of z. Since σ(z) = 1, it has to be the last visited. This concludes the proof of the correctness.
We now analyze the running time. The only difference between the algorithm and the original MCS algorithm is step 1.2. We need to compare the σ-numbers of vertices in D. It needs to be done n times, and each time takes O(n) time, and hence the extra time is O(n 2 ). Together with the time for MCS itself, the total running time is O(n 2 + m) = O(n 2 ).
This algorithm can be called the MCS + algorithm. Unlike LBFS + [7], however, it is not immediately clear how to carry MCS + out in linear time.

Maximum cardinality search on weakly chordal graphs
A graph G is weakly chordal if neither G nor its complement contains an induced cycle on five or more vertices. Since the complement of each induced cycle on six or more vertices contains an induced cycle on four vertices, all chordal graphs are weakly chordal. To prove the NP-completeness of the MCS end vertex problem on weakly chordal graphs, we use a reduction from the 3-satisfiability problem (3-SAT), in which each clause comprises precisely three literals.
Given an instance I of 3-SAT with p variables and q literals, we construct a graph G as follows (see Figure 4 for an example). Let the variables and clauses of I be denoted by x 1 , x 2 , . . ., x p and c 1 , c 2 , . . ., c q , respectively. For each literal, (including those that do not occur in any clause,) we introduce a vertex; let L denote this set of 2p literal vertices. For each literal vertex, we add edges between it and other vertices in L, with the only exception of its negation. We also introduce a set C of q clause vertices, each for a different clause; they forms an independent set. For each ∈ L and c ∈ C, we add an edge c if the literal does not occur in the clause c. Therefore, each clause vertex has 2p − 3 neighbors in L. Finally, we add seven extra vertices a 1 , a 2 , u 1 , u 2 , b, y, z and edges a 1 a 2 , u 1 u 2 , yz, {b, z} × L and {a 2 , u 1 , u 2 , y} × (L ∪ C). Proof. We need to show that neither G nor G contains an induced cycle on five or more vertices. We proceed as follows: We identify a vertex v ∈ V(G) such that G contains an induced cycle on five or more vertices if and only if G − v contains an induced cycle on five or more vertices, and then consider G − v. The following properties are straightforward: (i) A vertex on any induced cycle on five or more vertices has degree at least two.
(ii) A simplicial vertex is not on any induced cycle on five or more vertices.
(iii) An induced cycle on five or more vertices cannot contain a pair of true twins or false twins, and when it contains one of them, this vertex can be replaced by the other.
(iv) If a vertex is on an induced cycle on five or more vertices, then it has at least two non-neighbors, and there is at least one edge among these non-neighbors.
We can reduce G to G − {a 1 } because d(a 1 ) = 1 and (i); then to G − {a 1 , u 2 } because u 1 and u 2 are true twins and (iii); to G − {a 1 , u 1 , u 2 } because u 1 and a 2 are false twins in G − {a 1 , u 2 } and (iii); to G − {a 1 , u 1 , u 2 , y} because the only two remaining non-neighbors of y, namely, a 2 and b, are not adjacent to each other and (iv); to G − {a 1 , u 1 , u 2 , y, a 2 } for the same reason; to G − {a 1 , u 1 , u 2 , y, a 2 , b} because z and b are false twins in G−{a 1 , u 1 , u 2 , y, a 2 } and (iii); and finally to G−{a 1 , u 1 , u 2 , y, a 2 , b, z} because the only non-neighbors of z, namely, C, are independent and (iv). The remaining graph is G[L ∪ C]. Suppose that there is an induced cycle H on five or more vertices. It must intersect both L and C, since each vertex in L has only one non-neighbor in it, and since C is independent. Let v ∈ C be a a 2 a 1 u 1 u 2 Figure 4: Construction for NP-completeness proof of the MCS end vertex problem on weakly chordal graphs. The 3-SAT instance has four variables and three clauses, vertex on this cycle. Its two neighbors on H have to be from L; and since they are nonadjacent to each other, they have to be x andx for some variable x. Since both x andx are adjacent to all other vertices in L, the other 2 vertices on H have to be from C. But this is impossible because C is independent. Now we consider G. It can be reduced to G − {a 1 } because a 1 has only one non-neighbor and (iv); then to G − {a 1 , u 2 } because u 1 and u 2 are false twins and (iii); to G − {a 1 , u 1 , u 2 } because u 1 and a 2 are true twins in G − {a 1 , u 2 } and (iii); to G − {a 1 , u 1 , u 2 , y} because y is simplicial in G − {a 1 , u 1 , u 2 } and (ii); to G − {a 1 , u 1 , u 2 , y, b} because z and b are true twins in G − {a 1 , u 1 , u 2 , y} and (iii); to G − {a 1 , u 1 , u 2 , y, b, a 2 } because the degree of a 2 is one in G − {a 1 , u 1 , u 2 , y, b} and (i); and finally to G − {a 1 , u 1 , u 2 , y, a 2 , b, z} because z is simplicial in G − {a 1 , u 1 , u 2 , y, b, a 2 } and (ii). The remaining graph is G[L ∪ C]. Suppose that there is an induced cycle H on five or more vertices. Since C is a clique, H contains at most two vertices from C. In other words, at least three vertices on H are from L, but this is impossible because each vertex in L has only one neighbor in L.
We can thus conclude that G is a weakly chordal graph.
We are now ready to prove Theorem 1.2.
Proof of Theorem 1.2. It is clear that the MCS end vertex problem is in NP, and we now show that it is NP-hard. Let I be an instance of 3-SAT, and let G be the graph constructed from I. We show that z is an MCS end-vertex of G if and only if I has a satisfying assignment. For the if direction, suppose that I is satisfiable, and we give an MCS ordering σ as follows. Let us fix a satisfying assignment of I, and let T be the set of variables that are set to be true. The starting vertex is a 1 , which is followed by a 2 ; visited after them are {x | x ∈ T } ∪ {x | x ∈ T }, (i.e., the literal vertices corresponding to true literals,) in any order. After these p + 2 vertices, each of y, z, u 1 , u 2 , b, and each of the unvisited literal vertices has p visited neighbors. On the other hand, each clause vertex has at most p visited neighbors: Each clause contains a true literal, and hence each clause vertex has at least one non-neighbor in the visited literal vertices.
Then σ(b) = (p + 3). Since b is adjacent to only literal vertices, the next vertex is one of them. On the other hand, since vertices L \ T form a clique, they have to be visited between p + 4 and 2p + 3, i.e., before others.
The remaining vertices are u 1 , u 2 , y, z, and clause vertices. Each of u 1 , u 2 , y, and z has 2p visited neighbors, while each clause vertex has only 2p − 2, because each clause is nonadjacent to three literal vertices. Let u 1 , u 2 , and y be visited next. After that, all the remaining vertices (z and all clause vertices) have the same number of visited neighbors, 2p + 1. There is no edge among these vertices, so they an be visited in any order. We have thus obtained an MCS ordering of G ended with z.
We now prove the only if direction. Suppose that σ is an MCS ordering of G with σ(z) = n. Since N(z) = N(b) ∪ {y}, visiting y before b would force z to be visited before b; therefore, b < σ y < σ z.
( ) Since d(a 1 ) = 1, it is easy to verify that {σ(a 1 ), σ(a 2 )} = {1, 2}; otherwise, σ must end with a 1 . The third vertex of σ has to be from N(a 2 ), i.e., L ∪ C. It cannot be from C because of ( ). Therefore, (1) For each variable, one literal vertex has more visited neighbors than b, z, y, u 1 , u 2 ; (2) clause vertices cannot be visited before b. There cannot be any variable x such that both x,x ∈ X, because xx ∈ E(G). We claim that assigning a variable x to be true if and only if x ∈ X is a satisfying assignment for I. Suppose for contradiction that some clause c is not satisfied by this assignment. By the construction of G, the clause vertex c is adjacent to all vertices of X. After visiting the first p + 2 vertices, c has p + 1 visited neighbors, ({a 2 } ∪ X,) while any other unvisited vertex in V(G) \ C has at most p visited neighbors. But then σ(c) = k + 3, contradicting ( ). Therefore, all clauses are satisfied, and this completes the proof.

Lexicographic depth-first search on chordal graphs
Berry et al. [3,Characterization 8.1] have given a full characterization of MNS end vertices on chordal graphs: A vertex z is an MNS end vertex if and only if it is simplicial and the minimal separators of G in N(z) are totally ordered by inclusion. Since LDFS is a special case of MNS, its end vertices also have this property. We show that this condition is also sufficient for a vertex to be an LDFS end vertex. Similar as DFS, LDFS visits a neighbor of the most recent vertex, or backtracks if all its neighbors have been visited. The difference lies on the choice when the vertex has more than one unvisited neighbors. Each unvisited vertex has a label, which is all its visited neighbors. When there are ties, it chooses a vertex with the lexicographically largest label. The following is actually a simple property of DFS.
is connected. If an LDFS visits all vertices in N(X) before the first vertex in X, then it visits vertices in X consecutively.

Lemma 5.2. A vertex z of a chordal graph G is an LDFS end vertex if and only if it is simplicial and the minimal separators of G in N(z) are totally ordered by inclusion.
Proof. The only if direction follows from that all LDFS orderings are MNS orderings [11] and the result of Berry et al. [3]. For the if direction, suppose that S 1 , . . ., S k are the minimal separators in N(z) and S 1 ⊂ · · · ⊂ S k . It is easy to see that for all 1 i k, each component of G − S i not containing z is a component of G − S k ; let C denote these components. We show an LDFS ordering σ of G as follows. It starts from visiting all vertices in S 1 , followed by components C ∈ C with N(C) = S 1 , visited one by one. In the same manner, it deals with S 2 . . . . S k in order. After that the only unvisited vertex are z and its true twins, of which it chooses z the last. We now verify that this is indeed a valid LDFS ordering. It is clear for S 1 . Since vertices in each component C ∈ C are visited after N(C), By Proposition 5.1, it suffices to show the correctness when it visits a vertex in N(z) and when it visits the first vertex of a new component C ∈ C. When such a decision is made, the label of an unvisited vertex is either ∅ or all visited vertices in N(z), i.e., the most recently visited separator. So it is always correct to select a vertex from N(z). When a vertex v in a component C is selected, the visited vertices in N(z) are precisely N(C), hence v does have the largest label.

Breadth-first search on interval graphs
Interval graphs are intersection graphs of intervals on the real line. An interval graph is always chordal, and in particular, it has a clique tree that is a path [15]. Corneil et al. [10] gave a very simple linear-time algorithm for deciding whether a vertex z is an LBFS end vertex of an interval graph, which is very similar to our algorithm in Figure 3. They conducted an LBFS started from z, and then another LBFS that uses the first run to break ties. They proved that z is an LBFS end vertex if and only if it is the last of the second run. As shown in Figure 5, however, this algorithm cannot be directly adapted to the BFS end vertex problem. z u s w Figure 5: A BFS started from z may end with s or w, but a BFS started from w has to end with u. (Note that a BFS started from s may end with z.) If a graph has one and only one universal vertex, then each of the other vertices is a BFS end-vertex, but not itself. If it has two or more universal vertices, then every vertex can be a BFS end-vertex. Therefore, we may focus on graphs with no universal vertex. Such an interval graph has at least three maximal cliques. Proposition 6.1 ([13]). Let G be a connected interval graph, and let K 1 , . . . , K p be a clique path of G. Let u ∈ K 1 and w ∈ K p be two simplicial vertices.
(i) Both u and w are LBFS end vertices.
(ii) For any vertex v ∈ V(G), one of u and w has the largest distance to v.
It is known that a vertex z of an interval graph G can be an LBFS end vertex if and only if it is simplicial and N[z] can be one of the two ends of a clique path of G [13]. However, a BFS may satisfy neither of the two conditions. In Figure 5, for example, vertex z is not simplicial but can be a BFS end vertex. When z is not in an end clique, it should be close to one. Actually, it should be at distance at most two to one of the u and w as specified in Proposition 6.1. However, a BFS end vertex might be at distance two to both u and w, as shown in Figure 6.
For a fixed clique path K 1 , . . . , K p of an interval graph G, we let lp(v) and rp(v) denote, respectively, the smallest and the largest number i such that v ∈ K i . 2 We use dist(u, v) to denote the distance between u and v.  Proof. Let G be an interval graph; we may assume without loss of generality that G is connected. We use the algorithm of Corneil et al. [13] to build a clique path for G, and take simplicial vertices v 1 , v 2 from the first and last cliques of the clique path. We call the procedure described in Figure 7 twice, first with u = v 1 , w = v 2 ; in the second call, we reverse the clique path, and use u = v 2 , w = v 1 . Suppose that the procedure is correct, then vertex z is a BFS end vertex if and only if at least one of the two calls returns yes. In the rest we prove the correctness of the procedure and analyze its running time. We start from characterizing the first vertex s of a BFS ordering σ with σ(z) = n and u < σ w, if one exists. Since u < σ w < σ z, we must have dist(s, u) dist(s, w) dist(s, z). On the other hand, Proposition 6.1 implies dist(s, z) max{dist(s, u), dist(s, w)} = dist(s, w). Therefore, a desired BFS ordering σ, if it exists, must start from a vertex s satisfying dist(s, z) = dist(s, w) dist(s, u).
( †) We argue that at least one of the following is true for z: • on any shortest s-u path, z is adjacent to the second to last vertex but no vertex before it.
• on any shortest s-w path, z is adjacent to the second to last vertex but no vertex before it.
Let P u be any s-u path and P w any s-w path. Since they together form a u-w path that visits all the maximal cliques of G, vertex z is adjacent to at least one of these two paths. If z is adjacent to a vertex on P u , then it has to be the last two; otherwise dist(s, z) < dist(s, u). Since u is simplicial, z is adjacent to its neighbor on the path if zu ∈ E(G). Therefore, z is always adjacent to the second to last vertex on this path. The same argument applies if z is adjacent to P w .
The correctness of step 1 follows from Proposition 6.1. For step 2, note that if v = z is a universal vertex, then v, u, w, . . . , z is such a BFS ordering. Steps 3 and 4 are justified by ( †). When the algorithm reaches step 5, X is not empty, and hence s is well defined. Let q = dist(s, z) = dist(s, w). Note that q 2 because s is not universal. Hence, z, w ∈ N(s).
We show the correctness of step 6 by contradiction. Suppose that rp(z) < lp(s) but there exists a BFS ordering σ with σ(z) = n and u < σ w. Let s be the first vertex of σ. Since s ∈ X, the selection of s implies lp(s) lp(s ). Then rp(u) = 1 rp(z) < lp(s) lp(s ), therefore, dist(s , u) 2. In this case, on any shortest s -u path, z is adjacent to the second to last vertex but no vertex before it. Hence, dist(s , z) = dist(s , u) = dist(s , w); let it be q . Since u < σ w, there must be some neighbor u of u at distance q −1 to s visited before neighbors of w. The vertex u cannot be universal, hence nonadjacent to w. But u is adjacent to z, which implies z < σ w, a contradiction. Therefore, step 6 is correct, which means rp(s) < lp(z) because s and z are not adjacent. Let s = w 0 , w 1 , . . . , w q−1 , w q = w be a shortest s-w path. Note that w q−1 ∈ N(z).
For step 7, it suffices to give the following BFS ordering, which starts with s = u. Of all vertices at distance i to s, 1 i q, the first visited vertex is w i . Note that every vertex is adjacent to w 1 , . . . , w q−1 . From rp(w q−1 ) = p it can be inferred that all vertices at distance q to s are adjacent to w q−1 . Since w q−1 is the first visited vertex at level q − 1, vertices at distance q to s can be visited in any order. Therefore, we can have a BFS ordering σ of G with u < σ w and σ(z) = n .
We now consider step 8, for which we show that there exists a BFS ordering σ with σ(s) = 1, σ(v) = 2, σ(z) = n, and u < σ w. Note that dist(w 1 , z) = dist(w 1 , w) = q − 1. Therefore v = w 1 ; otherwise step 5 should have chosen v because lp(v) < lp(s). For 1 i q − 1, vertex w i is always visited in the earliest possible time; in particular, σ(w 1 ) = 3. Since v is on a shortest s-u path, u is a descendant of v in the BFS tree generated by σ. On the other hand, since both dist(v, z) and dist(v, w) are larger than dist(v, u), either vertices z and w are not descendants of v, or they are at a lower level than u. In either case, we have u < σ w. When w q is visited, all the unvisited vertices are at distance q to s and adjacent to w q−1 . Thus, we can have σ(z) = n.
We are now at the last step. Note that the algorithm can reach here only when dist(s, z) = dist(s, w) = dist(s, u): The condition of step 8 must be true if dist(s, u) < q. Suppose for contradiction that there exists a BFS ordering σ with σ(z) = n and u < σ w but no vertex satisfies the condition in step 8. Let s be the starting vertex of σ. Since s ∈ X and by the selection of s, we have lp(s ) lp(s), which implies dist(s , u) dist(s, u). Note that s is adjacent to any s-w path, and hence its distance to w is at most q + 1. In summary, Let Y denote all vertices at distance q − 1 to u, and let Z denote all vertices at distance q − 1 to w. Note that Y is disjoint from Z: A vertex in v ∈ Y ∩ Z would be adjacent to s, and have the same distance to u, w, and z, but then it contradicts the selection of s because lp(v) < lp(s). Since no vertex in Y satisfies the condition of If dist(s , u) = dist(s , z) = dist(s , w) = q, then to have u < σ w, one vertex in Y ∩ N(s) must be visited before Z. But this would force z to be visited before w, because z is at distance q−1 to all vertices in Y ∩ N(s). Now that dist(s , w) = q + 1, if dist(s , u) = q, then at least one vertex v ∈ Y is adjacent to s ; it is in N(s) because lp(s) lp(s ). But then dist(s , z) 1+dist(v, z) = 1+q−1 = q < dist(s , w). Therefore, dist(s , u) = q + 1 as well. Each vertex in Y ∪ Z has distance at least two to s . Of vertices at distance two to s , one vertex in Y ∩ N(s) must be visited before Z, but then we have the same contradiction as in the first case of this paragraph. Therefore, step 9 is also correct and this concludes the proof of correctness.
We now analyze the running of the algorithm. Steps 1 and 2 can be easily checked in O(n + m) time. For step 3, it suffices to calculate the distances between z, w, u and all other vertices; this can be done by visiting the maximal cliques one by one. Steps 4-7 can be done in O(n) time.
Step 8 can be checked in O(n) time: We have already calculated the distance between z and v. Therefore, the total running time is O(n + m).

Graph searches on general graphs
We now describe an algorithm for deciding whether a vertex z of a general graph is an MCS end vertex. For each subset X ⊆ V(G) \ {z}, we define f(X) to be true if there exists an MCS visiting X before others, and false otherwise. The question whether z can be an end vertex is then simply the value of f(V(G) \ {z}). For a set X with f(X) is true and v ∈ X, let g(X, v) indicate whether there exists a search ordering that visits v after X and before others. We have For MCS, g(X, v) can be calculated in linear time, and thus we have a simple O(2 n n O(1) )-time algorithm similar to the classic Held-Karp algorithm [18].
Let us consider then BFS. We may fix the starting vertex s, which can be found by enumerating all the other n − 1 vertices. Let = max v∈V(G) dist(s, v), and for 1 i , let L i denote the set of vertices at distance i to s. Suppose that there is a BFS ordering σ started with s and ended with z, then z ∈ L . Clearly, vertices in L −1 are visited after those in L −2 and before L . Let u be the first visited vertex in L −1 that is adjacent to z, and let X be those vertices in L −1 visited before u. Since z is the last vertex, all vertices in L \ N(X) must be adjacent to u. We do not need any constraint on the order of vertices in L −1 \ (X ∪ {u}) being visited. Therefore, the information we need at level − 1 are the set X and the vertex u. We can generalize this observation to give a recursive formula for the BFS end vertex problem. Proof. We use the following algorithm for the fixed starting vertex s ∈ V(G) \ {z}. For X i ⊂ L i and u i ∈ L i \ X i , where 1 i < , we define a function f(X i , u i ) to be true if and only if there exists a BFS that starts with s and visits L i in the order of X i , u i , L i \ (X i ∪ {u i }). Note that it is true for all sets and vertices when i = 1. For 1 i < , we use the following formula After that, we return f(L \ {z}, z). We now show the correctness of (BFS-subproblem). Suppose that there is a BFS ordering σ of G that visits vertices in L i+1 in the order of X i+1 , u i+1 , and L i+1 \ (X i+1 ∪ {u i+1 }). Let u i be the first vertex in L i ∩ N(Y i+1 ) visited in σ, and X i those vertices in L i visited before u i . By the selection of u i and X i , the value of f(X i , u i ) is true and X i ∩ N(Y i+1 ) is empty. Since u i is adjacent to some vertex in Y i+1 , to enforce the order in L i+1 , vertex u i has to be adjacent to u i+1 and all vertices in X i+1 \ N(X i ). Therefore, the right-hand side is true for X i and u i .
The other direction is similar. Suppose that σ is a BFS ordering of G that visits vertices in L i in the order of X i , u i before others, and the three conditions are all true. After finishing the L i , we proceed as follows. In level i + 1, we visit N(X i ) ∩ L i+1 ⊆ X i+1 , and then all the other vertices in X i+1 and u i+1 in order, which are adjacent to u i . This verifies that f(X i+1 , u i+1 ) is true.
In the last we consider DFS. Recall that a DFS sets two timestamps for a vertex v, first when it is visited, and second when it is finished, i.e., when all its neighbors have been examined and the search backtracks to the vertex that discovered v (or terminates when v is the source vertex). Note that when a vertex is finished, all its neighbors have been visited, and all but one of them have been finished. In particular, when the last vertex is visited, no vertex in its neighborhood has been finished. At any moment, the set of vertices that have been visited but not finished form a path in the depth-first tree. Suppose that z is the end vertex of a DFS ordering σ of G. If v is the earliest visited neighbor of z, then all the vertices after v are descendants of v in the depth-first tree.
The following simple property of DFS is stronger than Proposition 5.1. In a DFS ordering σ, if the set of vertices after v, i.e., {u : v < σ u}, and v induce a connected subgraph, then their visiting order is irrelevant to vertices visited before v. Proof. For a vertex set X ⊆ V(G) and s, t ∈ X, we define a function f(X, s, t), which is true only when (1) G[X] is connected; and (2) there exists a DFS ordering of G[X] that starts with s and ends with t. We may assume without loss of generality that G is connected. Then whether z is a DFS end vertex is v∈V(G)\{z} f(V(G), v, z). It is clear that f(X, s, t) is true if G[X] is connected and s is the only neighbor of t in X. We use the following formula to calculate it otherwise (DFS-subproblem) One direction is clear: If there exist vertex v and set Y such that both f ((X \ Y) ∪ {v}, s, v) and f(Y, v, t) are true, then we can visit X \ Y, followed by v, and then other vertices in Y. In the rest we focus on the other direction,-i.e., if f(X, s, t) is true, then there must be one v making the right hand true. Let