当前位置:网站首页>Theoretical basis of graph
Theoretical basis of graph
2022-07-01 11:31:00 【Life needs depth】
This chapter introduces the basic concept of graph in data structure .
Catalog
1. The basic concept of graph
2. The storage structure of the graphReprint please indicate the source : If the sky doesn't die - Blog Garden
The basic concept of graph
1. Definition of graph
Definition : chart (graph) It's a little bit (vertex) The connection with these points (edge) Made up of ; among , Points are usually called " The vertices (vertex)", The connection between points is called " Edge or arc "(edege). It's usually written as ,G=(V,E).
2. Types of graphs
Depending on whether the edge has a direction , The graph can be divided into : Undirected graph and Directed graph .
2.1 Undirected graph
The picture above G0 Is undirected graph , All edges of an undirected graph are undirected .G0=(V1,{E1}). among ,
(01) V1={A,B,C,D,E,F}. V1 By "A,B,C,D,E,F" A collection of several vertices .
(02) E1={(A,B),(A,C),(B,C),(B,E),(B,F),(C,F), (C,D),(E,F),(C,E)}. E1 By the side (A,B), edge (A,C)... And so on . among ,(A,C) Denotes by vertex A And vertex C Connected edges .
2.2 Directed graph
The picture above G2 It's a directed graph . Unlike an undirected graph , All edges of a digraph have directions ! G2=(V2,{A2}). among ,
(01) V2={A,C,B,F,D,E,G}. V2 By "A,B,C,D,E,F,G" A collection of several vertices .
(02) A2={<A,B>,<B,C>,<B,F>,<B,E>,<C,E>,<E,D>,<D,C>,<E,B>,<F,G>}. E1 Is made up of vectors <A,B>, vector <B,C>... And so on . among , vector <A,B) By " The vertices A" Point to " The vertices C" The directed side of .
3. Adjacency point and degree
3.1 Adjacency point
Two vertices on an edge are called adjacency points .
for example , Undirected graph above G0 The summit of A And vertex C It's the adjacency point .
In a directed graph , Except for adjacency points ; also " Into the side " and " Out of the way " The concept of .
The entry edge of the vertex , Refers to the edge ending at this vertex . And the edge of the vertex , It refers to the edge starting from this vertex .
for example , There is a directed graph G2 Medium B and E It's the adjacency point ;<B,E> yes B Out of the way , still E The entry side of .
3.2 degree
In the undirected graph , The degree of a vertex is the edge adjacent to that vertex ( Or arc ) Number of .
for example , Undirected graph above G0 Middle peak A The degree is 2.
In a directed graph , Degrees and " The degree of " and " The degree of " Points .
The penetration of a vertex , Refers to the number of edges ending at this vertex . And the output of the vertex , Is the number of edges starting from this vertex .
The degree of the vertex = The degree of + The degree of .
for example , There is a directed graph G2 in , The vertices B My penetration is 2, The output is 3; The vertices B Degree =2+3=5.
4. Paths and loops
route : If the vertex (Vm) To the top (Vn) There is a sequence of vertices between . said Vm To Vn It's a path .
The length of the path : In the path " The number of sides ".
Simple path : If vertices do not appear repeatedly on a path , It's a simple path .
loop : If the first vertex of the path is the same as the last vertex , It's the loop .
Simple circuit : The first vertex is the same as the last vertex , The other loops whose vertices do not repeat are simple loops .
5. Connected graphs and connected components
Connected graph : For undirected graphs , There is an undirected path between any two vertices , The undirected graph is called a connected graph . For a directed graph , If there is a directed path between any two vertices in the graph , Then the directed graph is called strongly connected graph .
Connected component : Each connected subgraph in a non connected graph is called the connected component of the graph .
6. power
I'm learning " Huffman tree " When , Read about " power " The concept of . The concept of weight in the figure is similar .
Above is a weighted graph .
The storage structure of the graph
I understand above " The basic concept of graph ", Now let's introduce the storage structure of the diagram . The storage structure of the graph , What is commonly used is " Adjacency matrix " and " Adjacency list ".
1. Adjacency matrix
Adjacency matrix refers to using matrix to represent graph . It uses a matrix to describe the relationship between vertices in the graph ( And the right of arc or edge ).
Suppose the number of vertices in the graph is n, Then the adjacency matrix is defined as :
The following is a schematic diagram to explain .
In the picture G1 Is an undirected graph and its corresponding adjacency matrix .
In the picture G2 Is an undirected graph and its corresponding adjacency matrix .
Two arrays are usually used to realize adjacency matrix : A one-dimensional array is used to store vertex information , A two-dimensional array to store edge information .
The disadvantage of adjacency matrix is that it consumes more space .
2. Adjacency list
Adjacency list is a chained storage representation of graph . It is improved " Adjacency matrix ", Its disadvantage is that it is not convenient to judge whether there is an edge between two vertices , But it saves more space than adjacency matrix .
In the picture G1 Is an undirected graph and its corresponding adjacency matrix .
In the picture G2 Is an undirected graph and its corresponding adjacency matrix .
边栏推荐
- 今天开户今天能买股票吗?在线开户是很安全么?
- Is it safe for Huatai Securities to open an account online?
- sshd_ Discussion on permitrotlogin in config
- Share the method of how to preview PSD format and PSD file thumbnail plug-in [easy to understand]
- Goldfish rhca memoirs: do447 uses ansible to communicate with API -- using ansible tower API to start jobs
- Redis的攻击手法
- Packet mode and three streaming modes in SDP protocol
- S7-1500PLC仿真
- 为什么一定要从DevOps走向BizDevOps?
- Redis common sense
猜你喜欢
Global filter (processing time format)
如何看懂开发的查询语句
Tempest HDMI leak receive 3
Technology sharing | introduction to linkis parameters
Mingchuang plans to be listed on July 13: the highest issue price is HK $22.1, and the net profit in a single quarter decreases by 19%
编译调试Net6源码
博途V15添加GSD文件
Unittest框架中跳过要执行的测试用例
Dameng data rushes to the scientific innovation board: it plans to raise 2.4 billion yuan. Feng Yucai was once a professor of Huake
Network security learning notes 01 network security foundation
随机推荐
TMUX usage
Exposure:A White-Box Photo Post-Processing Framework阅读札记
Face detection and recognition system based on mtcnn+facenet
Comment Cao définit la décimale de dimension
sshd_config 中 PermitRootLogin 的探讨
redis中value/list
妙啊!MarkBERT
Export and import of incluxdb on WIN platform
Oneconnect plans to be listed in Hong Kong on July 4: a loss of nearly 3 billion in two years, with a market capitalization evaporation of more than 90%
Share the method of how to preview PSD format and PSD file thumbnail plug-in [easy to understand]
Is it safe for Huatai Securities to open an account online?
索引失效的几种情况
Shangtang entered the lifting period: the core management voluntarily banned and strengthened the company's long-term value confidence
MySQL in and not in() empty list error
Openinstall: wechat applet jump to H5 configuration service domain name tutorial
编译调试Net6源码
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%
Activity workflow engine
MySQL IN 和 NOT IN () 空列表报错
node版本管理器nvm安装及切换