Algorithms related to trees and Binary Trees

Source: Internet
Author: User

;

*; // Left child

*; // Right child

; // Node data

,*;


()

(! = ){

(, ()-> );

(-> );

(-> );

()

(! = ){

(-> );

(, ()-> );

(-> );

()

(! = ){

(-> );

(-> );

(, ()-> );

()

;

(&);

(! =)

(&,);

(! (&))

(&,&);

();

(->! = ){

(&,-> );

(->! = ){

(&,-> );

(&);

;

A is the root of the tree. Then, let's look at the position of the central sequence a. The a in the middle sequence divides the sequence into two parts, dbe and c. Then we can conclude that the left child of a is dbe, And the right child is c. Then, check dbe. In the first order, dbe is in the bde order. B should be the root of the left child of a, so that dbe can be split into d and e by the sequence of B traversing in the middle order. Therefore, the two children of B are d and e. Thus, a definite binary tree can be obtained. No matter what traversal is used, the node sequence of the left child of the tree must be in front of the right child node. This is because the above four traversal types access the left child first and then the right child.

The middle and back order are similar to the latter)

Number of nodes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.