In the topic about tree traversal in Leetcode, the common tree traversal methods (pre, middle, and post order traversal) have been explained in detail.
Stacks are used for front, middle and back order traversal , and queues are used for hierarchical traversal
This article mainly discusses: Hierarchical traversal of trees
102. Level order traversal of binary tree
107. Level Order Traversal of Binary Tree II
429. Level Order Traversal of N-ary Trees
The front-middle-order traversal uses DFS (depth-first search) , while the hierarchical traversal uses BFS (breadth-first traversal)
DFS needs to use stack
BFS needs to use queue <