Data structure THU2018-Figure

1. Representation of a graph

1.1 Adjacency matrix

Insert picture description here
If there is an edge between two nodes, it is marked as the edge weight in the matrix; if there is no edge, it is marked as 0.
Insert picture description here

1.2 Incidence matrix

Insert picture description here
Each node corresponds to an edge set:
Insert picture description here

1.3 Adjacency list

In order to save space, each node only needs to save a list of nodes connected to it:
Insert picture description here

Space complexity:

  • Directed graph: O(n+e)
  • Undirected graph: O(n+2e), because the edge is saved twice

2. Breadth First Search

Insert picture description here

3. Depth First Search

The depth-first search algorithm is an algorithm used to traverse or search trees or graphs. Traverse the nodes of the tree along the depth of the tree and search the branches of the tree as deep as possible. When the edges of node v have been explored, the search will backtrack to the starting node of the edge where node v is found. This process continues until all nodes reachable from the source node have been found. If there are still undiscovered nodes, select one of them as the source node and repeat the above process. The whole process is repeated until all nodes are visited. It is a blind search.
Insert picture description here
Insert picture description here

4. Topological Sort

4.1 Problem

Insert picture description here

4.2 Strategy: output zero-in-degree nodes sequentially

Insert picture description here
Insert picture description here

5. Minimum spanning tree

5.1 Definition

Insert picture description here

5.2 Prim's Algorithm

Insert picture description here
example:
Insert picture description here
Insert picture description here
Insert picture description here

6. The shortest path

6.1 Problem description

Insert picture description here
Each time, the smallest point in the working set is selected, and then the values ​​of all points connected to this point are updated again.

6.2 Examples

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_41332009/article/details/114894849