当前位置:网站首页>Compare advantages and disadvantages of DFS and BFS and name vocabulary
Compare advantages and disadvantages of DFS and BFS and name vocabulary
2022-06-13 07:23:00 【One two pandas】
dfs and bfs Use adjacency table and adjacency matrix to store graph , The time complexity is O(N E) and O(N2), If you traverse the entire graph , The space complexity is O(N) If you already know that the dissociation root node is closer , that BFS Better If each node has many edges as a whole , that BFS It will consume a lot of memory If a tree is very deep and has few answers , that DFS It could be very slow ( On the contrary, if the solutions are many and deep , that BFS It's going to be slow ) If a problem has infinite depth and limited breadth , that DFS You can't get a solution , but BFS Sure , On the contrary, the same is true
One , connected : Connectivity is from the vertex V To W There is an undirected path , said V and W It's connected .
Two , Connected component : The polar Tongzi graph of undirected graph .
Two characteristics of connected components
1. The maximum number of vertices : Add another one to the current graph and it will no longer be connected .
2. Maximum number of sides : Contains all edges connected to all vertices in the subgraph .( All included edges of all vertices are in )
3、 ... and , loop
The path from the beginning to the end .
Four , Connected graph
All vertices in a graph are connected .
5、 ... and , Strong connectivity 、 Weakly connected
In a directed graph, vertices V and W There is a two-way path between , said V and W It's strongly connected .
6、 ... and , Strongly connected graph
Vertices of any quantity in a directed graph are strongly connected
7、 ... and , Strong connected components
Maximal strongly connected graphs of directed graphs
One call at a time DFS(x)/BFS(x) Are all the x Traversal of the connected component . So what if a graph is not connected , We'll do the required... Once for all the points we haven't visited DFS(x)/BFS(x), You can traverse all the points of the graph .
Pay attention to the time complexity , If you have any N vertices E side . The time complexity of adjacency table storage graph is O(N+E), The time complexity of adjacency matrix is O(N²);
边栏推荐
- 量化框架backtrader之一文读懂Analyzer分析器
- The management practice of leading enterprises has proved that what is the core of sustainable development of enterprises?
- B. I Hate 1111 (记忆化搜索 数论
- Wechat applet - positioning, map display, route planning and navigation
- Evolution in the digital age
- Nfv basic overview
- 理财产品连续几天收益都是零是怎么回事?
- Time field comparison time size in MySQL
- RT thread simulator lvgl control: button button style
- 快速排序
猜你喜欢
Continuous management design
Evolution in the digital age
量化框架backtrader之一文讀懂Analyzer分析器
微隔离(MSG)
C # related knowledge points
redis-3. Redis list, set, hash, sorted_ set、skiplist
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
Try to use renderdoc to view the shader code of UE
基于SSM实现水果商城批发平台
redis-6. Redis master-slave replication, cap, Paxos, cluster sharding cluster 01
随机推荐
Time field comparison time size in MySQL
MySQL query timeout control
MySQL row column conversion (updated version)
理财产品连续几天收益都是零是怎么回事?
The password does not take effect after redis is set
Powerdispatcher reverse generation of Oracle data model
Nfv basic overview
EF CORE执行SQL语句
Test development programmers, are you still confused? You can't define yourself as a yard farmer
How to solve the 404 problem
redis-0. Introduction to redis and NiO principle (random talk)
redis-7. Redis master-slave replication, cap, Paxos, cluster sharding cluster 02
Department store center supply chain management system
部署RDS服务
Interview questions must be asked - Optimization of large table Pagination
Oracle problem: the data in the field is separated by commas. Take the data on both sides of the comma
First day of learning MySQL Basics
Issues related to C # delegation and events
B. I hate 1111 (mnemonic search number theory
JMeter encryption interface test