Java programming undirected graph structure storage and DFS operation code explanation
Concept of graph
The graph is an extension of the tree in the algorithm. The tree is a top-down data structure. All nodes have a parent node (except the root node) arranged from top to bottom. However, the graph has no concept of parent-child nodes, and the nodes in the graph are equal, so the result is more complex.
Undirected graph
Graph G = (V, e), where V represents vertex, e represents edge, and an edge is a fixed-point pair (U, V), where (U, V) ∈ v.
These two days, I met an algorithm about graphs. I searched the Internet for a long time and didn't find the Java version about graph storage and related operations in data structures. So I found a java version of the data structure book and read it. The following is a storage of undirected graphs and depth first traversal of graphs according to the explanations in the book. However, this traversal can only traverse connected graphs. If you want to traverse non connected graphs, you need to modify them. Share the code here, hoping to help those in need.
Results of program operation:
summary
The above is all about the storage of Java programming undirected graph structure and the detailed explanation of DFS operation code. I hope it will be helpful to you. Interested friends can continue to refer to this website:
Java programming realizes the complete code of depth first search and breadth first search based on graph
Depth first and breadth first Java implementation code examples
Java programming two tree menu structure conversion code