adjacency Matrix : Information that stores data elements (vertices) and the relationships between data elements (edges or arcs) with two arrays.
Consider, for example, the following map:
If the adjacency matrix is stored, it can be expressed as:
1. Vertex array:
2. Adjacency Matrix:
Traversal of graphs:
Depth First (DFS):
The depth-first search traversal is similar to the first root traversal of a tree, which is the generalization of the tree's first root traversal. Assuming that the initial state is not accessed by all vertices in the graph, the depth-first search can be set off from a vertex v in the graph, access this vertex, and then proceed from the inaccessible adjacency point of V to the depth first to traverse the graph, until all the vertices in the diagram and V have paths are accessed; The previous procedure is repeated until all vertices are accessed, as the starting point of the unreachable vertex in the alternate diagram.
Upper image Depth First traversal result: Abcdfeghi
Breadth First (BFS):
Breadth-First search is similar to a hierarchical traversal of trees. Assuming that from a vertex v in the diagram, after the V is accessed, each of the inaccessible adjacent points of V is accessed sequentially, and then the neighboring points are accessed from the neighboring points, and then the adjacency points of the first accessed vertices are accessed before the adjacent points of the vertex being accessed. The adjacent points of all the vertices that have been accessed in the diagram are accessed. If a vertex is still not reachable at this time, the remaining vertex in the alternate diagram as the starting point repeats the process until all vertices are accessed.
Breadth-First traversal results above: ABGCEHIDF