Tree and Tree algorithm

Source: Internet
Author: User

The concept of a tree:

A tree is an abstract data type (ADT) or a data structure of an abstract data type that simulates a collection of data of a tree-like nature. It is a set of hierarchical relationships consisting of n (n>=1) finite nodes. It's called a "tree" because it looks like an upside down tree, which means it's rooted up and leaves facing down. It has the following characteristics:

  • Each node has 0 or more child nodes;
  • A node without a parent node is called the root node;
  • Each non-root node has only one parent node;
  • In addition to the root node, each child node can be divided into multiple disjoint subtrees;

For example:

terminology of the tree
  • node degree : The number of sub-trees that a node contains is called the degree of the node;
  • degree of the tree: the degree of the largest node in a tree is called the degree of the tree;
  • leaf node or end node : A zero-degree node;
  • father node or parent node : If a node contains child nodes, this node is called the parent node of its child nodes;
  • child node or child node : The root node of a subtree containing a node is called a child node of that node;
  • sibling nodes : nodes with the same parent node are called sibling nodes;
  • the hierarchy of nodes : From the beginning of the root definition, the root is the 1th layer, the root of the child node is the 2nd layer, and so on;
  • the height or depth of a tree : the maximum level of nodes in a tree;
  • cousin Node : The parent node in the same layer of the nodes are each other cousins;
  • ancestor of a node : All nodes from the root to the branch of the node;
  • descendants : Any node in a subtree that is rooted in a node is known as the descendant of that node.
  • Forest : The collection of trees that are disjoint by M (m>=0) is called a forest;
Types of Trees
  • unordered Tree : There is no sequential relationship between the child nodes of any node in the tree, which is called the unordered tree, also known as the free tree;
  • ordered Tree: There is a sequential relationship between the child nodes of any node in the tree, which is called an ordered tree;
    • Two fork Tree: A tree with a maximum of two subtrees per node is called a binary tree;
      • Complete binary tree : For a binary tree, suppose its depth is D (d>1). In addition to layer D, the number of nodes in each layer has reached the maximum, and all nodes of layer d are continuously arranged from left to right, so that the two-fork tree is called a complete binary tree, where the definition of full two-tree is the complete binary tree with all the leaf nodes at the bottom;
      • Balanced binary Tree (AVL tree): When and only if the height difference of the two subtrees trees of any node is not greater than 1 of the two-fork tree;
      • Sort binary Tree (binary lookup tree (English: Binary search tree), also known as binary searching trees, ordered binary tree);
    • Huffman Tree (For information coding): The shortest two-tree with the right path is called Huffman tree or optimal binary tree;
    • B-Tree : A self-balancing two-fork search tree that optimizes read and write operations, keeps data in order and has two additional subtrees.
storage and representation of trees

:

chained storage:

Because the number of nodes can not be mastered, the storage representation of the common tree is converted to binary tree for processing, the number of child nodes is up to 2

Common application scenarios for some trees

1.xml,html and so on, then the parser that writes these things, inevitably uses the tree
2. The routing protocol is the algorithm that uses the tree
3.mysql Database Index
4. Directory structure of the file system
5. So many of the classic AI algorithms are actually tree searches, and the decision tree in machine learning is also the structure of trees

Tree and Tree algorithm

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.