# Tree Edge, front edge, back edge, cross side

Source: Internet
Author: User

Transfer from http://www.gonglin91.com/dfs-graph-edge/

Tree edge, forward edge, back edge, cross side, it should be said, is not a concept of the diagram itself, should be the concept of Dfs. The figure for DFS will get a Dfs tree (forest) that has these concepts on this tree. DFS, can start from any vertex, the way of traversal is also diverse, so different traversal will get different Dfs tree, resulting in different tree edge, forward edge, back edge, cross edge. So these 4 kinds of sides, is a relative concept.
In the traversal of graphs, a bool value of a tag array vis is often set to record whether the vertices have been accessed. But sometimes it is necessary to change the meaning of the VIS value. The VIS has 3 values and represents 3 different meanings
Vis = 0, indicating that the vertex has not been accessed
Vis = 1, indicating that the vertex has been accessed, but its descendants have not yet been visited, and have not returned from that point
Vis = 2, indicating that the vertex has been accessed and that its descendants have already visited it, and has returned from that vertex
The 3 values that can be vis represent a sequence relationship and a time relationship

Correction: "Introduction to the Algorithm (third edition)" 353 pages have the exact definition of these 4 kinds of edges, not in this statement
DFS process, for an edge u->v
VIS[V] = 0, indicating v has not been accessed, V is the first to be discovered, U->v is a tree edge
VIS[V] = 1, indicating that V has been visited, but its descendants have not yet been visited (in the access), and you point to V? Note that u is a descendant of V, U->v is a back edge, so the back edge is also called the atavistic edge
VIS[V] = 3,z indicates that V has been visited and that its descendants have all been visited, u->v the edge may be a cross-border, or forward edge

Note: Tree-side, back-side, forward-side, all have ancestors, descendants of the relationship, but the cross-side is not, u->v for the cross-side, indicating that in this Dfs tree, they are not ancestor descendants of the relationship they may be brotherly relations, cousin relationship, or even farther relationship, if it is the Dfs forest, U and V can even be on different trees

In many algorithms, the back edge is useful, but the effects of the forward and cross edges are often diluted, but they do not have much effect.

Tree Edge, front edge, back edge, cross side

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.