Graph depth-first traversal algorithm-Nirvana huofeng-blog Garden
Depth-first Traversal Algorithm
Correct the mistakes in the previous blog: the previous blog post has the suspicion of non-undirected graphs and not having to traverse the breadth first. In fact, the breadth-first search can also be used in Directed Graphs, because an undirected
The graph has four storage structures: array, adjacent table, cross linked list, and multiple adjacent tables. The following uses an array as the storage structure to achieve deep-first search traversal and breadth-first search traversal of graphs. Among them, the queue in STL is used in the breadth-first search traversal
Package arithmetic.graphtraveral;Import java.util.LinkedList;Import Java.util.Queue; /*** This example is the two ways of graph traversal* Through it, let me understand the traversal of the graph* Created on 2013-11-18* @version 0.1*/public class graphtraveral{Adjacency Matrix Storage Diagram--a B C D E F G H IA 0 1 0
Import java. util. *;/*** in this example, we use the graph Traversal method, let me understand the graph traversal * Created on 2013-11-18 * @ version 0.1 */public class DeptSearch {public static void main (String args []) {// construct the Node object NodeT a = new NodeT ("a"); NodeT B = new NodeT ("B"); NodeT c = ne
vertex value
for (int i = 0; i
Depth-first traversal of adjacency matrices
First, the graph traversal: from a vertex in the graph to visit the remaining vertices in the graph, and so that each vertex is accessed only once, this process is called
the first graph.
There are so many basic concepts of graphs. In fact, these concepts are very clear after being drawn.
How can we express this complicated data structure, that is, a bit of data with edges? People come up with many kinds of representation: the adjacent matrix, the adjacent table, and so on. Here we will only introduce the simplest adjacent matrix: it is to write n vertices in the graph into
In this paper, the graph is represented by the Adjacency table method, and the graph is traversed by the breadth-first traversal method.The following is an example of a diagram:The code is as follows:#include using namespace Std;typedef int VEXTYPE;typedef struct arcnode{Vextype data;struct Arcnode *nextarc;}arcnode;typedef struct VEXNODE{Vextype data;Arcnode *fi
the explicit children field, do not need to set the VIS array to ensure that only one traversal, because the knowledge is convenient once.Travel (node) {for (I=1:lengh) { //..... Process node Node if (null! =children) Travel (children); Another way of writing is to write a for loop outside the functionthe hierarchical traversal of the tree and BFS is very similar, in gener
DirectX: Add a custom filter (traversal filter in graph) to the graph Auto-link, filtergraph
In the filter test program for video playback provided to the customer, the positive manual connection method (http://blog.csdn.net/mao0514/article/details/40535791) is adopted because of different video compression formats, the disadvantage of this method is that you can
Undirectedgraphnode is the graph node, the label stores the node data, visited indicates whether the node has been accessed, neighbors represents the connected node.
Using stack to achieve the deep traversal of the graph, the stack is implemented by the back (), push_back (), Pop_back method of the list.
Traversal idea
. That
n N
OD (vi) =∑a[i,j], OD (vi) =∑a[j,i])
J=1 j=1
The adjacency matrix can also represent a weighted graph, as long as the
Wij, if
a[i,j]={
∞, otherwise.
Where Wij is the weight value on
Figure 5-6 lists a network and its adjacency matrix.
┌∞31∞∞┐
│∞∞51∞│
│∞∞∞∞∞│
│∞∞6∞∞│
└∞322∞┘
(a) network (b) adjacency matrix
Fig. 5-6 NET and its adjacency matrix
For the direction-free graph or the non-direction ne
Traversal of graphs
Graph traversal (traversing graph): from one vertex of the graph, visit the remaining vertices in the diagram, and each vertex is only accessed once.The traversal algorithm of graphs is the basis of operation
the adjacency table and the inverse adjacency table are integrated together, so that it is easy to find a V-tail arc, but also easy to find a V-headed arc, so it is easier to calculate the vertex and the degree of penetration.In addition to the complexity of the structure, in fact, the time complexity of creating the graph algorithm is the same as the adjacency table, therefore, in the application of the graph
, the number of edges, and the next line is the ID of this vertex and the ID of the neighbor, and the 2nd digit stores the total number of neighbors nodes of the node; For further operation, the original node ID can be mapped from 0 to N, and no edge nodes are 0 added. This time the line number and ID are equal, and the access is faster. The advantage of this storage is that it takes less memory to complete and is easy to operate.2. Adjacency MatrixThe adjacency matrix, as its name implies, is a
total number of nodes, the number of edges, and the next line is the ID of this vertex and the ID of the neighbor, and the 2nd digit stores the total number of neighbors nodes of the node; For further operation, the original node ID can be mapped from 0 to N, and no edge nodes are 0 added. This time the line number and ID are equal, and the access is faster. The advantage of this storage is that it takes less memory to complete and is easy to operate.2. Adjacency Matrix
The adjacency matrix, as
41 Toad Data Structure Note the depth of the traversal of the 41 graph is preferredThis famous article:"For me , the meaning of life is to put yourself in the shoes of people , worry about others , Joy of others." -- Einstein "In the previous chapter we implemented the graph of adjacency multiple table representations, as well as the depth
This article mainly introduces the JavaScript data structure and algorithm diagram and graph algorithm. This article describes the directed graph, unordered graph, simple graph, and graph trav
Huadian North Wind BlowsKey laboratory of cognitive computing and application, Tianjin UniversityLast Modification Date: 2015/8/22There are adjacency matrices, adjacency linked lists, sparse matrices and so on for the storage of the graph.The non-direction graph mainly includes the two sides content, the graph traverse and seeks the unicom component.One, the traversal
In this chapter, we introduce the depth first search and breadth first search, and then give the realization of C/c++/java.
Directory1. Depth First search graphics and text introduction1.1 Depth First Search introduction1.2 Depth First search diagram2. Breadth First search graphics and text introduction2.1 Breadth First Search introduction2.2 Breadth First search diagram3. Search algorithm's source code
Reprint please indicate the source: http://www.cnblogs.com/skywang12345/
More content: Data s
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.