Article Directory
Use the tree to understand the depth and breadth-first priority
In our last blog post Algorithms_ binary tree preorder traversal, in order traversal, subsequent traversal (depth-first) , is a depth-first nature. Why do you say? We look at
5
/ \
3 6
/ \ \
2 4 8
Preorder traversal: 5, 3,2,4,6,8
Preorder: 2,3,4,5,6,8
Postorder: 2,4,3,8,6,5
Whether the preamble, the order or the order will be put to the left sub-tree traversal no element, and then traverse the right subtree to no elements.
The traverse the level it? (Breadth-first)
5 先遍历第0层的数据
---------------------------------------
/ \
3 6 然后遍历第1层的数据
---------------------------------------
/ \ \
2 4 8 再遍历第2层的数据
---------------------------------------
We traverse the data layer by layer traversal, it is one kind of breadth-first traversal of nature.