Lexicographic Breadth First Search
Lexicographical Order
Lexicographical Order
A sequence of vectors is in lexicographical order if, for each vector (a1 , a2 )
and (b1 , b2 ),
(a1 , a2 ) ≤ (b1 , b2 ) if and only if a1 < b1 ∨ (a1 = b1 ∧ a2 ≤ b2 ).
Examples
I
Words in a dictionary
I
0815
156
18
22
734
9
2/6
LexBFS
Idea
I
Modified BFS
I
Each vertex has a label (updated during iteration).
I
Next vertex is vertex with lexicographically largest label.
Applications
I
Recognition of special graph classes.
I
Diameter approximation for special graph classes.
3/6
LexBFS – Algorithm
Input: A graph G = (V , E) with |V | = n and a start vertex v ∈ V .
Output: A vertex ordering σ.
1
Set label(v) := hni.
2
For each vertex u 6= v, set label(u) := h i.
3
For i := 1 To n
4
Pick an unvisited vertex u with a lexicographically largest label.
5
Set u as visited and σ[i] := u, i. e., u is the i-th vertex in order σ.
6
For Each unvisited w ∈ N (u)
7
Append i to label(w).
How can we implement this in linear time?
4/6
Partition Refinement
Idea
I
“Data structure” representing a partition of a set.
I
It allows refining the partition by splitting its sets into smaller sets.
Refinement
I
Given: Family of disjoint sets S = {S1 , S2 , . . .} and set X .
I
Replace each set Si by Si ∩ Xi and Si \ Xi .
I
Remove a set if empty.
Implementation
I
S is doubly linked list.
I
Constant time function f : X → S with f (x) = Si if and only if x ∈ Si .
5/6
LexBFS using Partition Refinement
Input: A graph G = (V , E) with |V | = n and a start vertex v ∈ V .
Output: A vertex ordering σ.
1 Initialise S := {v}, V − v = S1 , S2 }.
2
For i := 1 To n
3
Pick first vertex u ∈ Si , set u as visited, and set σ[i] := u.
4
S := Refine(S, {u})
5
S := Refine(S, { x ∈ N (u) | x is unvisited})
6/6
© Copyright 2026 Paperzz