Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre and post numbers

When doing a depth first search on a Directed Graph what is meant by pre and post numbers?

For example:

enter image description here

If you were to start at node A and do an alphabetic Depth First Search how do you determine the pre and post numbers?

like image 621
Deekor Avatar asked Feb 10 '14 05:02

Deekor


1 Answers

Note : Although the question has been asked quite a time ago, but it may be referred by someone else.

Pre and Post values in a Depth First Search depict the start time of the visit and end time of visit of a vertex respectively. By start time, I mean the time when the vertex is discovered and end time means the time when all the children (in the DFS tree) will be visited.

Here's a sample pseudocode for DFS-

dfs(Graph, Vertex)

    static count = 1
    pre[Vertex] = count++
    visited[Vertex] = true

    for all v in Edge(Vertex, v)
        if visited[v] = false
            dfs(Graph, v)

    post[Vertex] = count++;

The pre and post values have a lot of significance. Edge classification is one such example. Also you can find the use of post values where sources and sinks come into picture.

like image 198
return007 Avatar answered Oct 25 '22 05:10

return007