3-16 (The end of the binary tree and insertion sort)

Today, I mainly completed the algorithmic problems of the binary tree, as well as the insertion sort

1. Binary tree subtree

Idea: Mainly use the idea of ​​whether two binary trees are equal, divided into 3 cases, the first is equal to the root, the second is equal to the left subtree, and the third is equal to the right child. The recursion is complete.

2. Construct a tree with strings traversed in the previous order, and then print the middle order

Idea: First, build a binary tree based on the string, and build based on the preorder traversal. The main purpose of the construction is to remember the changes in the array i.

3. Insertion sort

Insertion sorting is mainly divided into two categories, namely direct insertion sorting, with a time complexity of O(N^2); Hill sorting, with a time complexity of O(N^1.3).

Direct insertion sort is to default the first element to order, and then insert the following elements in sequence.

Hill sorting is divided into 2 steps. The first step is pre-sorting, and the second step is insertion sorting. The pre-sorting is mainly gap, and the insertion sorting is gap=gap/=3+1;










Guess you like

Origin blog.51cto.com/15085121/2662459