This article is published in the official account of the self. The original is written by Lee, and has been authorized by the original author.
This issue brings you the last part of the summary of the basic knowledge of graph theory.
Most of the production materials of slides come from the Internet, and most of the sources can’t be found. Thank you for the original content here. But I believe that the sharing of knowledge is priceless. As Lu Xun said, “if someone reprints, his merit is boundless.”
Let’s focus on the adjacency matrix.
- Using matrix theory and analysis method to study graph theory, some problems of graph are transformed into matrix operation problems, which is more suitable for computer processing.
- Graph is stored and read in the form of matrix in computer. The problems in matrix can also be studied with the help of graph theory and method
Here’s an example, Knight dialer.
The simplest idea of this problem is to convert the phone number into a graph and use DFS with memo to do this problem. The following is the answer to @ peritan in the discussion area.
At the same time, this question can well explain the subtle relationship between DP & BFS & DFS. Readers can carefully understand and distinguish the similarities and differences between them. In the last lecture, we mentioned the relationship between them.
Let’s take another look at the iteration solution of straight forward. As you can see, the part of iterative calculation is the relationship between the edges of the graph.
The chart below shows the initial value of each number and the effect of their growth. Personally, I think it is a bit like the effect of Markov chain, which is easy to be associated with matrix operation.
So we can express their transformation relationship in a matrix, and the number of paths in each step is calculated by matrix power operation. Matrix power operation can be optimized to o (logn). There are many templates for matrix operation on the Internet. It is not a template party for the time being. It is also very easy to write. The same method can also be used in many places. The difficulties of individual problems will be reflected in the construction of relation matrix. Its essence is linear change, and it can be quickly exponentiated by recursion.
Back to our topic, let’s talk about the data structure of storage graph and adjacency table that I often use in algorithm problems.
The above is the summary of our basic knowledge of graph theory. Practice the general DFS and BFS writing methods in the figure, and you will succeed in more than half. Advanced graph theory knowledge often involved, as well as various algorithms named after people, including but not limited to: Two minimum spanning trees MST, three shortest paths, common ancestor LCA. Since I don’t know them very well, I don’t want to express it for the time being. I look forward to other teachers’ contributions.