Crazy java--tree and two-fork Tree (11th chapter)

Source: Internet
Author: User

The tree represents a nonlinear data structure.

Terms:

Leaf node: A node without a child node, so the leaf node is not a parent node;

Degree of node: the number of sub-trees owned by a node is called the degree of the node (degree);

The degree of the tree: the maximum value of the degree of all nodes in the tree is the degree of the tree;

Node hierarchy: The level of the node is calculated from the root, the root hierarchy value is 1, the remaining node's hierarchy value is the parent node level value plus 1;

Depth of tree (depth): The maximum hierarchical value of a node in a tree is called the depth or height of a tree;

Ordered and unordered trees: if each subtree of a node in the tree is considered ordered from left to right (that is, it cannot be interchanged), it is called an ordered tree, otherwise called an unordered tree.

Father point notation: Each child node records its parent node (this is the way to start with a child node)

Child chain notation: each non-leaf node records all its child nodes through a linked list. (This approach is initiated from the parent node, with the feature that each node can quickly find all its child nodes) such as:

two fork Tree : An ordered tree of up to two subtrees per node.

Full two fork tree: If a binary tree has a depth of K, it contains 2k-1 nodes. Full Two tree like:

Complete binary Tree : A two-tree with n nodes, numbered according to the numbering of two-tree, the tree is called a complete binary tree if all the nodes in the tree and the full two-tree 1-n number are exactly the same. That is, all nodes in the remaining layers are full except for the last layer. Such as:

Two fork Tree nature:

1) In any binary tree, if the number of its leaf nodes is N0, the number of child nodes with a degree of 2 is N1, then n0=n1+1;

2) The depth of a complete binary tree with n nodes is log2n+1;

Binary tree's two-fork list stores the idea that each node can remember its left and right two nodes. Add left and right two pointers to each node, referencing the node's two child nodes, respectively.

Binary tree of the three-linked list of the idea of storage: let each node not only remember its left and right nodes, but also remember its parent node, using the pointer to the parent.

Traversing a binary tree

I, the first sequence traversal:

1) access to the root node;

2) recursively traverse left subtree;

3) recursively traverse right sub-tree;

II, Middle sequence traversal:

1) recursively traverse left subtree;

2) access to the root node;

3) recursively traverse right sub-tree;

III. Post-Sequential traversal:

1) Recursively traverse right sub-tree;

2) access to the root node;

3) recursively traverse left subtree;

Breadth-First traversal: traversal by layer;

Crazy java--tree and two-fork Tree (11th chapter)

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.