Tree and binary tree analysis, Binary Tree Analysis

Source: Internet
Author: User

Tree and binary tree analysis, Binary Tree Analysis

A tree is a connected undirected graph that does not contain loops.

There is a tree on the left, and a figure on the right, because there is no loop on the left, and there is a loop like 1-2-5-3-1 on the right.


Tree features:

1. Any two nodes in a tree have only one path connected;

2. If a tree has n nodes, it must have n-1 edges;

3. Adding an edge to a tree will constitute a loop.


A tree is an undirected graph with only one path between any two nodes. Only connected undirected graphs without loops are trees.


Root Node. A tree has only one root node. Parent node, child node. A node without a subnode is called a leaf node.


Depth: the number of layers from the root node to the node (the root layer is the first layer ).


Binary Tree

Binary Tree Features: each node can have at most two sons: The left son and the right son, or each node can have at most two trees.

The binary tree is either empty or composed of the root node, left subtree, and right subtree.


Full Binary Tree: Each internal node (neither the root node nor the leaf node) in a binary tree has two sons, or all the leaf nodes in the full binary tree have the same depth. Depth h with 2 ^ h-1 nodes.



Complete Binary Tree:In addition to one or more leaf nodes missing in the rightmost position, the other nodes are plump. The height is h. Except for layer h, other layers (1 ~ H-1) to the maximum number of nodes. If a node has a right son, it must also have a left son.

In a Complete Binary Tree, if a parent node number is k, the left son number is 2 * k, and the right son number is 2 * k + 1. if it is known that the son (either left or right) number is x, its parent node number is x/2.

If a full binary tree has N nodes, the height of the Complete Binary Tree is log2N or logN, that is, there are at most logN layer 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.