41 lines
957 B
Markdown
41 lines
957 B
Markdown
# Breadth First Search
|
|
|
|
#### 2022-07-08 11:19
|
|
|
|
> ##### Algorithms:
|
|
> #algorithm #BFS
|
|
> ##### Data structures:
|
|
> #DS #binary_tree
|
|
> ##### Difficulty:
|
|
> #CS_analysis #difficulty-
|
|
> ##### Additional tags:
|
|
>
|
|
|
|
##### Related problems:
|
|
```expander
|
|
tag:#coding_problem tag:#BFS -tag:#template_remove_me
|
|
```
|
|
|
|
- [[Leetcode Binary-Tree-Level-Order-Traversal]]
|
|
- [[Leetcode Maximum-Depth-Of-Binary-Tree]]
|
|
- [[Leetcode Search-In-a-Binary-Tree]]
|
|
- [[Leetcode Symmetric-Tree]]
|
|
- [[Leetcode Two-Sum-IV-Input-Is-a-BST]]
|
|
|
|
|
|
##### Links:
|
|
- [cppreference]()
|
|
___
|
|
|
|
### What is Breadth First Search?
|
|
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.
|
|
> otherwise, check if the root node is needed and minimum amount of nodes in the tree is larger than 1 |