HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includi ...
, lexicographic breadth-first search or Lex-BFS is a linear time algorithm for ordering the vertices of a
graph Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discre ...
. The algorithm is different from a
breadth-first search Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next de ...
, but it produces an ordering that is consistent with breadth-first search. The lexicographic breadth-first search algorithm is based on the idea of
partition refinement In the design of algorithms, partition refinement is a technique for representing a partition of a set as a data structure that allows the partition to be refined by splitting its sets into a larger number of smaller sets. In that sense it is dual t ...
and was first developed by . A more detailed survey of the topic is presented by . It has been used as a subroutine in other graph algorithms including the recognition of
chordal graph In the mathematical area of graph theory, a chordal graph is one in which all cycles of four or more vertices have a ''chord'', which is an edge that is not part of the cycle but connects two vertices of the cycle. Equivalently, every induced c ...
s, and optimal coloring of
distance-hereditary graph In graph theory, a branch of discrete mathematics, a distance-hereditary graph (also called a completely separable graph) is a graph in which the distances in any connected induced subgraph are the same as they are in the original graph. Thus, any ...
s.


Background

The
breadth-first search Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next de ...
algorithm is commonly defined by the following process: *Initialize a
queue __NOTOC__ Queue () may refer to: * Queue area, or queue, a line or area where people wait for goods or services Arts, entertainment, and media *''ACM Queue'', a computer magazine * ''The Queue'' (Sorokin novel), a 1983 novel by Russian author ...
of graph vertices, with the starting vertex of the graph as the queue's only element. *While the queue is non-empty, remove (dequeue) a vertex from the queue, and add to the queue (enqueue) all the other vertices that can be reached by an edge from that have not already been added in earlier steps. However, rather than defining the vertex to choose at each step in an imperative way as the one produced by the dequeue operation of a queue, one can define the same sequence of vertices declaratively by the properties of these vertices. That is, a standard breadth-first search is just the result of repeatedly applying this rule: *Repeatedly output a vertex , choosing at each step a vertex that has not already been chosen and that has a predecessor (a vertex that has an edge to ) as early in the output as possible. In some cases, this ordering of vertices by the output positions of their predecessors may have ties — two different vertices have the same earliest predecessor. In this case, the order in which those two vertices are chosen may be arbitrary. The output of lexicographic breadth-first search differs from a standard breadth-first search in having a consistent rule for breaking such ties. In lexicographic breadth-first search, the output ordering is the order that would be produced by the rule: *Repeatedly output a vertex , choosing at each step a vertex that has not already been chosen and whose entire set of already-output predecessors is as small as possible in
lexicographic order In mathematics, the lexicographic or lexicographical order (also known as lexical order, or dictionary order) is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of a ...
. So, when two vertices and have the same earliest predecessor, earlier than any other unchosen vertices, the standard breadth-first search algorithm will order them arbitrarily. Instead, in this case, the LexBFS algorithm would choose between and by the output ordering of their second-earliest predecessors. If only one of them has a second-earliest predecessor that has already been output, that one is chosen. If both and have the same second-earliest predecessor, then the tie is broken by considering their third-earliest predecessors, and so on. Applying this rule directly by comparing vertices according to this rule would lead to an inefficient algorithm. Instead, the lexicographic breadth-first search uses a set partitioning data structure in order to produce the same ordering more efficiently, just as a standard breadth-first search uses a queue data structure to produce its ordering efficiently.


Algorithm

The lexicographic breadth-first search algorithm replaces the
queue __NOTOC__ Queue () may refer to: * Queue area, or queue, a line or area where people wait for goods or services Arts, entertainment, and media *''ACM Queue'', a computer magazine * ''The Queue'' (Sorokin novel), a 1983 novel by Russian author ...
of vertices of a standard breadth-first search with an ordered sequence of sets of vertices. The sets in the sequence form a
partition Partition may refer to: Computing Hardware * Disk partitioning, the division of a hard disk drive * Memory partition, a subdivision of a computer's memory, usually for use by a single job Software * Partition (database), the division of a ...
of the remaining vertices. At each step, a vertex ''v'' from the first set in the sequence is removed from that set, and if that removal causes the set to become empty then the set is removed from the sequence. Then, each set in the sequence is replaced by two subsets: the neighbors of ''v'' and the non-neighbors of ''v''. The subset of neighbors is placed earlier in the sequence than the subset of non-neighbors. In pseudocode, the algorithm can be expressed as follows: *Initialize a sequence Σ of sets, to contain a single set containing all vertices. *Initialize the output sequence of vertices to be empty. *While Σ is non-empty: **Find and remove a vertex ''v'' from the first set in Σ **If the first set in Σ is now empty, remove it from Σ **Add ''v'' to the end of the output sequence. **For each edge ''v-w'' such that ''w'' still belongs to a set ''S'' in Σ: ***If the set ''S'' containing ''w'' has not yet been replaced while processing ''v'', create a new empty replacement set ''T'' and place it prior to ''S'' in the sequence; otherwise, let ''T'' be the set prior to ''S''. ***Move ''w'' from ''S'' to ''T'', and if this causes ''S'' to become empty remove ''S'' from Σ. Each vertex is processed once, each edge is examined only when its two endpoints are processed, and (with an appropriate representation for the sets in Σ that allows items to be moved from one set to another in constant time) each iteration of the inner loop takes only constant time. Therefore, like simpler graph search algorithms such as breadth-first search and depth-first search, this algorithm takes linear time. The algorithm is called lexicographic breadth-first search because the order it produces is an ordering that could also have been produced by a breadth-first search, and because if the ordering is used to index the rows and columns of an
adjacency matrix In graph theory and computer science, an adjacency matrix is a square matrix used to represent a finite graph. The elements of the matrix indicate whether pairs of vertices are adjacent or not in the graph. In the special case of a finite simp ...
of a graph then the algorithm sorts the rows and columns into lexicographical order.


Applications


Chordal graphs

A graph ''G'' is defined to be chordal if its vertices have a ''perfect elimination ordering'', an ordering such that for any vertex ''v'' the neighbors that occur later in the ordering form a clique. In a chordal graph, the reverse of a lexicographic ordering is always a perfect elimination ordering. Therefore, one can test whether a graph is chordal in linear time by the following algorithm: *Use lexicographic breadth-first search to find a lexicographic ordering of ''G'' *For each vertex ''v'': **Let ''w'' be the neighbor of ''v'' occurring prior to ''v'', as close to ''v'' in the sequence as possible ***(Continue to the next vertex ''v'' if there is no such ''w'') **If the set of earlier neighbors of ''v'' (excluding ''w'' itself) is not a subset of the set of earlier neighbors of ''w'', the graph is not chordal *If the loop terminates without showing that the graph is not chordal, then it is chordal. This application was the original motivation that led to develop the lexicographic breadth first search algorithm.


Graph coloring

A graph ''G'' is said to be ''perfectly orderable'' if there is a sequence of its vertices with the property that, for any
induced subgraph In the mathematical field of graph theory, an induced subgraph of a graph is another graph, formed from a subset of the vertices of the graph and ''all'' of the edges (from the original graph) connecting pairs of vertices in that subset. Defini ...
of ''G'', a
greedy coloring In the study of graph coloring problems in mathematics and computer science, a greedy coloring or sequential coloring is a coloring of the vertices of a graph formed by a greedy algorithm that considers the vertices of the graph in sequence an ...
algorithm that colors the vertices in the induced sequence ordering is guaranteed to produce an optimal coloring. For a chordal graph, a perfect elimination ordering is a perfect ordering: the number of the color used for any vertex is the size of the clique formed by it and its earlier neighbors, so the maximum number of colors used is equal to the size of the largest clique in the graph, and no coloring can use fewer colors. An induced subgraph of a chordal graph is chordal and the induced subsequence of its perfect elimination ordering is a perfect elimination ordering on the subgraph, so chordal graphs are perfectly orderable, and lexicographic breadth-first search can be used to optimally color them. The same property is true for a larger class of graphs, the
distance-hereditary graph In graph theory, a branch of discrete mathematics, a distance-hereditary graph (also called a completely separable graph) is a graph in which the distances in any connected induced subgraph are the same as they are in the original graph. Thus, any ...
s: distance-hereditary graphs are perfectly orderable, with a perfect ordering given by the reverse of a lexicographic ordering, so lexicographic breadth-first search can be used in conjunction with greedy coloring algorithms to color them optimally in linear time., Theorem 5.2.4, p. 71.


Other applications

describe an extension of lexicographic breadth-first search that breaks any additional ties using the
complement graph In the mathematical field of graph theory, the complement or inverse of a graph is a graph on the same vertices such that two distinct vertices of are adjacent if and only if they are not adjacent in . That is, to generate the complement of ...
of the input graph. As they show, this can be used to recognize
cograph In graph theory, a cograph, or complement-reducible graph, or ''P''4-free graph, is a graph that can be generated from the single-vertex graph ''K''1 by complementation and disjoint union. That is, the family of cographs is the smallest class of ...
s in linear time. describe additional applications of lexicographic breadth-first search including the recognition of
comparability graph In graph theory, a comparability graph is an undirected graph that connects pairs of elements that are comparable to each other in a partial order. Comparability graphs have also been called transitively orientable graphs, partially orderable grap ...
s and
interval graph In graph theory, an interval graph is an undirected graph formed from a set of intervals on the real line, with a vertex for each interval and an edge between vertices whose intervals intersect. It is the intersection graph of the intervals. In ...
s.


LexBFS ordering

An enumeration of the vertices of a graph is said to be a LexBFS ordering if it is the possible output of the application of LexBFS to this graph. Let G=(V,E) be a graph with n vertices. Recall that N(v) is the set of neighbors of v. Let \sigma=(v_1,\dots,v_n) be an enumeration of the vertices of V. The enumeration \sigma is a LexBFS ordering (with source v_1) if, for all 1\le i with v_i\in N(v_k)\setminus N(v_j), there exists m such that v_m\in N(v_j)\setminus N(v_k).


Notes


References

*. *. *. *. *{{citation, first1=D. J., last1=Rose, first2=R. E., last2=Tarjan, author2-link=Robert Tarjan, first3=G. S., last3=Lueker, year=1976, title=Algorithmic aspects of vertex elimination on graphs, journal=
SIAM Journal on Computing The ''SIAM Journal on Computing'' is a scientific journal focusing on the mathematical and formal aspects of computer science. It is published by the Society for Industrial and Applied Mathematics (SIAM). Although its official ISO abbreviation is ...
, volume=5, pages=266–283, issue=2, doi=10.1137/0205021. Graph algorithms Search algorithms