2022-07-08 11:29:47 +08:00
|
|
|
# Breadth First Search
|
|
|
|
|
|
|
|
#### 2022-07-08 11:19
|
|
|
|
|
|
|
|
> ##### Algorithms:
|
2022-09-03 15:41:36 +08:00
|
|
|
>
|
|
|
|
> #algorithm #BFS
|
|
|
|
>
|
2022-07-08 11:29:47 +08:00
|
|
|
> ##### Data structures:
|
2022-09-03 15:41:36 +08:00
|
|
|
>
|
|
|
|
> #DS #binary_tree
|
|
|
|
>
|
2022-07-08 11:29:47 +08:00
|
|
|
> ##### Difficulty:
|
2022-09-03 15:41:36 +08:00
|
|
|
>
|
2022-07-08 11:29:47 +08:00
|
|
|
> #CS_analysis #difficulty-
|
2022-09-03 15:41:36 +08:00
|
|
|
>
|
2022-07-08 11:29:47 +08:00
|
|
|
> ##### Additional tags:
|
|
|
|
|
|
|
|
##### Related problems:
|
2022-09-03 15:41:36 +08:00
|
|
|
|
2022-07-08 11:29:47 +08:00
|
|
|
##### Links:
|
2022-09-03 15:41:36 +08:00
|
|
|
|
2022-07-08 11:29:47 +08:00
|
|
|
- [cppreference]()
|
2022-09-03 15:41:36 +08:00
|
|
|
|
|
|
|
---
|
2022-07-08 11:29:47 +08:00
|
|
|
|
|
|
|
### What is Breadth First Search?
|
2022-09-03 15:41:36 +08:00
|
|
|
|
2022-07-08 11:29:47 +08:00
|
|
|
means BFS
|
|
|
|
|
|
|
|
### How does Breadth First Search work?
|
|
|
|
|
|
|
|
#### Example code
|
|
|
|
|
|
|
|
### Why and when to use it?
|
|
|
|
|
|
|
|
> [!tip] Whether to push root or root's nodes initially
|
|
|
|
> When checking the symmetry, [[Leetcode Symmetric-Tree]], push nodes to make sure the stack can be poped correctly.
|
2022-09-03 15:41:36 +08:00
|
|
|
> otherwise, check if the root node is needed and minimum amount of nodes in the tree is larger than 1
|