Graph Structure Basic and Code Implementation
Prerequisite Knowledge
Before reading this article, you should first study:
Summary in One Sentence
A graph structure is an extension of the N-ary tree structure. Logically, a graph consists of several nodes (Vertices) and edges. We typically use adjacency lists, adjacency matrices, and other methods to store graphs.
In tree structures, the parent node only points to child nodes, there are no child-to-parent links, nor links between sibling nodes. However, in graphs, there are fewer restrictions, allowing nodes to point to each other, forming complex network structures.
The visualization panel supports creating graph structures. You can open the visualization panel below to see the logical structure of graphs, as well as how adjacency lists and matrices are stored:
Initially, I intended to include graphs as an extension chapter of binary tree structures. However, given the richness of graph-specific algorithms, I decided to dedicate an entire chapter to graph structures and algorithms, facilitating updates to the site's content.
Since graph structures can abstract more complex problems, they have led to the development of more complex graph theory algorithms. Classic examples include the Bipartite Graph Algorithm, Topological Sort, Shortest Path Algorithm, and Minimum Spanning Tree Algorithm, which will all be introduced later.
This article mainly introduces the basic concepts of graphs and how to implement graph structures in code.