Tree definition and classification

Source: Internet
Author: User

Tree Definition

The tree is a non-linear structure, and the tree is a finite set of N nodes. When n = 0, it is called an empty tree. Non-empty trees have the following features:

  1. There is only one node called the root node.
  2. If n> 1, except the root node, other nodes can be divided into M (M> 0) Non-intersecting sets T1, T2, T3, T4 ,......, TM, where each set is a tree. Tree T1, T2, T3,..., TM is called the Child tree of this pair.

Is a common tree:

 

Related Terms

  • Node: A tree is a set of finite elements. Each element is called a node, a, B, C, D, E, F, G, H, and I are all Tree nodes;
  • Node degree: the number of Subtrees contained in a node is called the degree of the node;
  • Leaf node or terminal node: A node with a degree of 0 is called a leaf node. D, E, C, and g are all leaf nodes;
  • Non-terminal node or branch node: A node with a degree of less than 0;
  • Child node: the root node of the subtree contained in a node is called the child node of the node;
  • Parent node (parent node): If a node contains a child node, this node is called the parent node of its child node;
  • Sibling node: A node with the same parent node is called a sibling node;
  • Sibling node: the nodes on the same layer are sibling nodes;
  • Node ancestor: All nodes from the root node to the branch of the node;
  • Descendant node: Any node in the subtree with a node as the root is called the descendant of the node;
  • Forest: a forest is a collection of trees that are separated by M (M> = 0) trees;
  • Tree degree: the highest node degree in a tree is called the tree degree;
  • Node hierarchy: defined from the root. The root layer is layer 1st, and the root sub-node is layer 2nd, and so on;
  • Tree height or depth: the maximum hierarchy of nodes in the tree;

 

Tree Classification

 

  • Ordered Tree: the Subtrees of a tree are fixed in sequence and cannot be changed at will.
  • Unordered tree: the Subtrees of a tree are in a variable order.
  • Binary Tree: each node can have up to two subnodes. The binary tree is an ordered tree, and the order of left and right Subtrees cannot be changed. Binary trees can be divided into full Binary Trees and full Binary Trees.
  • B tree
  • Hoffmann tree

 

Tree Storage

 

The computer memory is linear, while the tree is a non-linear data structure. It is worth exploring how to store the non-linear tree structure in linear memory. Currently, the following storage methods are available:

1. Parental representation:

  • Implementation: a two-dimensional array is usually used to store the parent node of the corresponding node while storing the node.
  • Features: it is easy to find the parent node and it is difficult to find the child node.

 

2. Child Notation:

  • Implementation: each node is stored in the first column of a two-dimensional array. Multiple subnodes are connected by a linked list. The last subnode points to null, the second element of the array points to the starting address of its subnode linked list.
  • Features: it is easy to find a child node and find a parent node.

 

3. Expression of two-parent child:

  • Implementation: Combine the Parent-Child notation to store the subscript of the parent node and point it to the subnode linked list.
  • Feature: it is easier to find the parent node and the child node, but it is more complex than the previous two.

 

4. Binary Tree storage:

  • Binary Tree storage is to convert a common tree into a binary tree and then store it. The storage of Binary Trees will be discussed separately.
  • There is a way to convert a common tree into a binary tree. The left child and right brother method means that a child of each node is stored on the left child node starting from the root node, the right sub-node stores one of its brothers, as shown in:

 

Forest Storage

 

A forest is a collection of trees that are separated from each other. The storage method is similar to that of a tree that is converted into a binary tree.

  • Convert every pair in the forest into a corresponding binary tree.
  • Use the second binary tree as the right child of the root node of each binary tree, and use the third binary tree as the right child of the root node of the second Binary Tree, and so on, the final binary tree is the binary tree converted from the forest.

 

 

About this article

 

I have introduced the concepts and terminologies of trees, as well as the storage methods of trees and forests. It is inevitable that I will not learn too much or make mistakes. You are welcome to criticize and correct me.

 

Tree definition and classification

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.