当前位置:网站首页>Storage of drawings (refined version)
Storage of drawings (refined version)
2022-07-26 08:18:00 【Fanshui 682】
Just finished Figure of the storage .
Blog and practice , Consolidate what you just learned qwq..
The blog features : Describe the characteristics or advantages and disadvantages of different storage , More straightforward .
Front row notice :
All directed edges are from u To v, Right to use q Express
This clarifies u,v,q The definition of .
The storage of graphs actually has Four ways , The first two are easy to understand , Then it involves stl Of vector So pre knowledge is needed , But it is also more widely used , They are as follows :
1. Save the edge directly
One dimensional array + The structure has edges ,a[i].u,a[i].v,a[i].q
shortcoming : Cannot save duplicate edges .
2. Adjacent edge matrix
Two dimensional array storage ( Point to the ) edge ,a[u][v]=q/0
shortcoming : Because it's a two-dimensional array , Too much space is easy to explode , Cannot save duplicate edges .
advantage : Inquire about O(1)【 This is very important , This storage method is used to query the card 】
3. Adjacency list
vector<int> a[n] Save edge ( myth : This is similar to a two-dimensional array , because vector There is one dimension in itself )
Put the edge on vector Inside :a[u].push_back(v);
location : All kinds of pictures are suitable for , Unless there is a special need ( If you need to quickly query whether an edge exists , And less points , have access to Adjacency matrix ).
4. Chain forward star
stay Adjacency list Add the function similar to linked list on the basis of
This forward star is more complicated , At present, I don't fully grasp , Don't mislead readers , Readers can find other materials to study .
// C++ Version
// head[u] and cnt The initial values of are -1
void add(int u, int v) {
nxt[++cnt] = head[u]; // Successor of current edge
head[u] = cnt; // The starting point u The first side of
to[cnt] = v; // The end of the current edge
}
// Traverse u Out of the way
for (int i = head[u]; ~i; i = nxt[i]) { // ~i Express i != -1
int v = to[i];
}location : All kinds of pictures are suitable for , It belongs to the golden mean of storage .
边栏推荐
- Day 4 homework
- VIM cross line matching search
- Using ordered dictionary to copy pcap files
- An empirical study on urban unemployment in Guangxi (Macroeconomics)
- 要不你给我说说什么是长轮询吧?
- Beauty naked chat for a while, naked chat over the crematorium!
- Pycharm code specification tool flake8
- A clear summary and configuration example of GPON has been highlighted
- [endnote] detailed explanation of document template layout syntax
- 基础乐理 节奏联系题,很重要
猜你喜欢

2w字详解数据湖:概念、特征、架构与案例

Basic music theory rhythm connection problem, very important

Ten thousand words long article | deeply understand the architecture principle of openfeign

关于期刊论文所涉及的一些概念汇编+期刊查询方法

Rack server expansion memory

Burp Suite-第一章 Burp Suite 安装和环境配置

Bee guitar score high octave and low octave

一点一点理解微服务

Excel file reading and writing (creation and parsing)
![[fastjson1.2.24 deserialization vulnerability principle code analysis]](/img/14/8f6a75fe5f06c19eeff9c7204979c3.png)
[fastjson1.2.24 deserialization vulnerability principle code analysis]
随机推荐
Date and time function of MySQL function summary
Burp Suite-第九章 如何使用Burp Repeater
2022/7/9 exam summary
Take out brother is the biggest support in this society
Awk operation
2022/7/11 exam summary
2022-07-14 group 5 Gu Xiangquan's learning notes day07
2022-07-09 group 5 Gu Xiangquan's learning notes day02
vscode国内的镜像服务器加速
小组成员参加2022中国多媒体大会
Guitar staff link Jasmine
Regular expression job
ORACLE 官方文档
es6中函数默认参数、箭头函数、剩余参数-讲解
OSPF总结
mysql函数汇总之条件判断函数
BGP的基本配置
Random distribution learning notes
Using ordered dictionary to copy pcap files
Introduction to arrays -- array