Data structures and Algorithms (5)-----> Two fork Trees

Source: Internet
Author: User

1. Concept

The structure of a binary tree node:

Class node{    int value;    //value indicates the node value    of the binary tree Node left;    Node right;    //left and right represent two children    of a binary tree Node (int data) {       this.value = data;    }}

2. Two fork number traversal 2.1 sequentially traverse the binary tree
    • First Order traversal: Middle, left, and right
    • Middle sequence traversal: Left, middle, and right
    • Post-post traversal: Left, right, middle
      • Take a two-fork tree as an example:
      • The result of the first order traversal is: 1, 2,4,5,3,6,7
      • The result of the middle sequence traversal is: 4,2,5,1,6,3,7
      • Post-order traversal results are: 4,5,2,6,7,3,1
2.2 Traversing a binary tree by layer
    1. The width-first traversal of the binary tree;
    2. Width-first traversal often uses queue structure;
    3. (often asked to print along with the companion number!!) )

3. Balanced binary tree (AVL tree)

Concept:

    1. The empty tree is a balanced binary tree;
    2. If a tree is not empty, and all of its subtrees satisfy their respective Zuozi and right sub-tree height difference is not more than 1, is a balanced binary tree;
      • For example:
          • (Balanced binary tree)

          • (Unbalanced binary tree)
          • Because, for, in the 2 nodes of the subtree, the left subtree is 2, the right subtree is 0, the height difference is greater than 1, I am therefore not balanced binary tree;
4. Search for binary trees

Search for binary tree features:

The head node values for each subtrees tree are larger than the values of all nodes on the respective left subtree, and are smaller than the values of all nodes on the respective right subtree.

    1. Search binary tree According to the sequence of sequential traversal, must be from small to large arrangement.
    2. Among them, the red black tree/Balanced binary tree (AVL tree), etc., are different implementations of the search binary tree.
5. Full two fork Tree

Concept: Full Two forks the tree is a node with two child nodes on each layer except the last node without any child nodes.

The number of layers in the two-ary tree is L, and the node points are N, then N=2L-1;L=LOG2 (n+1).

5. Complete binary Tree

Concept: In addition to the last layer, each of the other layers of the number of nodes are full, the last layer if also full, is a full two fork tree, is also a complete binary tree. If the last layer is dissatisfied, the missing nodes are all concentrated on the right, and that is a tree full of two forks.

As below, are completely binary tree!!!

   

Data structures and Algorithms (5)-----> Two fork Trees

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.