3-15 (Algorithm problem of binary tree)

Today, I mainly completed some algorithmic problems of binary trees. The difficulty is not very large, but I am very familiar with it. I don’t know how to do
1. The height
idea of binary trees : use post-order traversal to calculate the height of the left and right trees, then take the larger value and add 1. It is the height of the binary tree.
2. The
idea of reversing the binary tree : preorder traversal, looking at the left and right children, swapping address values, and then recursing each node.
3. The same tree
idea: Preorder traversal, comparing the roots, and then recursively comparing.
4. Symmetric binary tree: The
idea is to compare the left and right trees in the same way.
5. The
idea of ​​pre-order traversal of
binary tree : pre-order traversal 6. The
idea of balanced binary tree : take each node as a tree, and find the height of the left and right child trees of each node, if the height difference is not greater than 1

Guess you like

Origin blog.51cto.com/15085121/2660970