DFS code and Minimum DFS code

Edge Code

We represent each code e={start, end} with start and end as the starting and ending nodes of edge. The edge code is defined as:

\left\{ Index_{start}, Index_{end},L_V(start), L_E(e), L_V(end)\right\}

where the Index of a vertex is an arbitrary number, in sequential visiting order, given to the vertices in the graph. The numbers marked in red in the following graph are the indices of the vertices.

Screen Shot 2018-08-25 at 18.03.27

There are many edge codes for this graph:

Forward edge: {0,1,X,a,Y}, {1,2,Y,b,X}, {2,3,X,c,Z}, {1,4,Y,d,Z}

Backward edge: {3,1,Z,b,Y}, {2,0,X,a,Z}

It is clear to see that we have Index_{start}<Index_{end} for forward edges and Index_{start}>Index_{end} for backward edges.

The order of edges and DFS code

Suppose we have two edges

e_1=\left\{ Index_{start1},Index_{end1}\right\}

e_2=\left\{ Index_{start2},Index_{end2}\right\}

To determine the ordering between 2 edges we must consider: i) the types of the edges, ii) the visiting order (Index) of the nodes in each edge.

If e_1 and e_2 are both forward edges, then e_1 < e_2 if one of the following holds:

  1. Index_{end1}<Index_{end2}
  2. Index_{end1}=Index_{end2} and Index_{start1}<Index_{start2}

If e_1 and e_2 are both backward edges, then e_1 < e_2 if one of the following holds:

  1. Index_{start1}<Index_{start2}
  2. Index_{start1}=Index_{start2} and Index_{end1}<Index_{end2}

If e_1 and e_2 are one forward edge and one backward edge, then e_1 < e_2 if one of the following two holds:

  1. e_1 is forward edge and e_2 is backward edge and Index_{end1}\leq Index_{start2}
  2. e_1 is backward edge and e_2 is forward edge and Index_{start1}<Index_{end2}

The DFS code is just the concatenation of all the edge codes in order. i.e. the DFS code for the above DFS tree is:

{0,1,X,a,Y,1,2,Y,b,X,2,0,X,a,X,2,3,X,c,Z,3,1,Z,b,Y,1,4,Y,d,Z}.

DFS Lexicographic Order and Minimum DFS code

The DFS lexicographic order of the DFS code is defined as follows:

If we have two DFS codes \alpha and \beta

\alpha={\alpha_0,...,\alpha_m}, \beta={\beta _0,...,\beta_n}

then \alpha\leq\beta if and only if either of the following is true

1.\exists t,0\leq t\leq min(m,n), \forall k<t, \alpha_k=\beta_k and \alpha_t<\beta_t

2.m\leq n and \forall k\leq m, \alpha_k=\beta_k

So we can order a list of DFS codes according to the DFS lexicographic order, and we define a minimum DFS code as the minimum one among all the possible DFS codes of a graph.

Leave a comment