当前位置:网站首页>Graph traversal (BFS & DFS basis)
Graph traversal (BFS & DFS basis)
2022-07-28 13:48:00 【bj_ hacker】
Graph traversal
Preface
We talked about graph storage before , The ultimate goal of the graph is to traverse , What are the ways of traversal , Let's break it down one by one .
( Recognition and storage of graphs :https://blog.csdn.net/weixin_42178241/article/details/125931691?spm=1001.2014.3001.5501)
Graph traversal
solve the problem
Like solving the problem of graph theory search , It can spread to multiple points , But our computer uses linear storage , And this kind of problem is nonlinear , We need to transform nonlinear problems into linear .
BFS
Breadth first search
The main idea
Traversal by hierarchy , The starting point level is 0, Its child nodes are 1, Its grandson node is 2, Pay attention to the marked nodes , Not in tag
nature
The new node that is traversed for the first time , The corresponding level is the shortest legal path from the starting point to the node
Code thinking
- Input
- initialization
- The queue is not empty 4 5, Empty execution 6
- Pop up the team head element , If you jump to 6
- Expand the new node to execute 3
- Output
DFS
Depth-first search
The main idea
One way to the dark , Traverse in turn according to the route , Can't go back to the last node .
Code thinking
- Input
- initialization
- Traverse the starting node
- Traverse the child nodes respectively
- Node backtracking
- Output
evolution
Some topics are in the opposite direction array , Some changes , There are also great changes to the conditions of the map , There are two solutions :
- A new node
- Increase the dimension
summary
BFS
The main features
queue
solve the problem
- The shortest path of multiple lines at the same point
DFS
The main features
Stack
solve the problem
- Path process
- Number of paths
Postscript
These knowledge BFS&&DFS The basis of , We will talk about the more difficult later .
边栏推荐
- R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
- vite在项目中配置路径别名
- 不用Swagger,那我用啥?
- C语言:随机生成数+归并排序
- Paddleclas classification practice record
- 酷炫操作预热!代码实现小星球特效
- 少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
- JWT 登录认证 + Token 自动续期方案,写得太好了!
- R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
- 使用 Fail2ban 保护 Web 服务器免受 DDoS 攻击
猜你喜欢

word打字时后面的字会消失是什么原因?如何解决?

Some thoughts on.Net desktop development

org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程

SQL daily practice (Niuke new question bank) - day 4: advanced operators

从手机厂高位“出走”的三个男人

Three men "running away" from high positions in the mobile phone factory

Volcanic stone investment Zhang Suyang: hard technology, the relatively certain answer in the next 10 years

严格模式——let和const——箭头函数——解构赋值——字符串模板symbol——Set和Map——生成器函数

How to play a data mining game entry Edition
JWT login authentication + token automatic renewal scheme, well written!
随机推荐
接口调不通,如何去排查?没想到10年测试老鸟栽在这道面试题上
R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
Tutorial on the principle and application of database system (062) -- MySQL exercise questions: operation questions 32-38 (6)
C语言:随机生成数+快速排序
POJ3275 Ranking the Cows题解
C language: optimized merge sort
POJ3259虫洞题解
C language: random number + quick sort
数据库系统原理与应用教程(060)—— MySQL 练习题:操作题 11-20(四)
【架构】评分较高的三本微服务书籍的阅读笔记
word打字时后面的字会消失是什么原因?如何解决?
JWT login authentication + token automatic renewal scheme, well written!
Three men "running away" from high positions in the mobile phone factory
.net for subtraction, intersection and union of complex type sets
Debezium系列之:2.0.0.Beta1的重大变化和新特性
DOJP1520星门跳跃题解
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)
P1797重型运输 题解
Rust 从入门到精通01-简介
R语言ggplot2可视化:可视化散点图并为散点图中的数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点标签互相重叠(自定义指定字体类型font family)