C + + Implementation of data structure definition and properties of binary tree and special binary tree

Source: Internet
Author: User
Tags definition

The one or two-forked tree (Binary) is a finite set of n (n>=0) nodes, the collection is either an empty set (called a null binary tree) or a two-fork tree of a root node and two disjoint Saozi, called root nodes, respectively. As shown in Figure 1 is a tree with two forks

Figure 1

The characteristics of the binary tree:

(1) Each node has a maximum of two Shang trees, so there is no node with a degree greater than 2 in the binary tree.

(2) Saozi the right subtree is ordered, the order cannot be reversed.

(3) Even if a node in the tree has only one Shang tree, it is also to distinguish whether it is a Zuozi or a right subtree.

The binary tree has five basic forms:

(1) an empty binary tree; (2) Only one root node, (3) the root node is only Zuozi, (4) The root node is only the right subtree, (5) The root node has both Zuozi and right subtree.

Two, special two fork Tree

1, Oblique tree: All the nodes are only Zuozi two fork tree is called Left oblique tree. All nodes are only the right subtree of the two-tree called the right oblique tree.

2, full two fork tree: In a binary tree, if all branch nodes exist Saozi right subtree, and all leaves are on the same layer, such a two-fork tree is called full two fork tree, such as Figure 2.

Figure 2

The characteristics of two fork trees are:

(1) The leaves can only be present at the bottom of the floor. It is impossible to strike a balance in other layers.

(2) The degree of non-leaf node must be 2.

(3) In the same depth of the two-fork tree, the number of nodes with two fork trees is the most, and the most leaves tree.

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.