34. Toad's data structure note 34 Tree concept

Source: Internet
Author: User

34. Toad's data structure note 34 Tree concept

This famous article:"The past belongs to death, the future belongs to you." - - Shelley "

This note begins with a new concept we're going to get into, tree! Isn't that a little bit exciting? Let's start with the concept.

Of course the concept to understand, if not immediately understood, you can follow the combination of code to understand the effect better.

1. Tree-type Structure

So much of what we learned before, in fact, are linear data structures.

The tree is different, it is a nonlinear structure.

The tree structure refers to the data structure of a "one-to-many" tree relationship, and is a kind of important nonlinear data structure. In the tree structure, there is no precursor node in the root node, and there is only one precursor node for each of the remaining nodes. There are no subsequent nodes in the leaf nodes, and the subsequent node number of each knot can be one or more.

In addition, the tree structure in mathematical statistics can represent hierarchical relationships. Tree-shaped structures are also used in many other ways. can represent subordination, side-by-side relationships.

Tree structure in the objective world State is a large number of existence , such as family tree, administrative organization can be represented by the tree image. Tree in the field of computer also has a wide range of applications, such as in the compiler, a tree to represent the syntax structure of the source program, in the database system, the tree can be used to organize information, in the analysis of the behavior of the algorithm, the tree can be used to describe its execution process.

2. Definition of a tree

A tree is a commonly used nonlinear structure. We can define this: the tree is a finite set of n (n≥0) nodes. If n=0, it is called an empty tree; otherwise, there is only one specific node that is called the root, and when n>1, the remaining nodes are divided into M (m>0) disjoint subsets T1,t2,...,tm, and each subset is a tree. As you can see, the definition of a tree is recursive .

3. Forest

The forest is a collection of M (m≥0) trees that are disjoint from each other.

The link between the forest and the tree: a non-empty tree removes the root and its subtree forms a forest; a forest adds a root knot to become a tree.

4. Two fork Tree

Definition: The two fork tree is another tree-shaped structure. The difference between it and the tree structure is:

(1) Each node has a maximum of two subtrees trees.

(2) The sub-tree has left and right points.

5. The tree's storage structure

Storage structure A glance can be, follow slowly thoroughly understand.

5.1 Parental representations

Implementation: Defines the nodes of the structure array to hold the tree, with two fields per node:

Data fields: Storing the node's own information

Parent domain: Indicates the position of the parent node of this node in the array.

Features: Easy to find parents, difficult to find children

5.2 Child Notation

Multilink lists: Each node has multiple pointer fields, pointing to the root of its subtree, respectively

Node isomorphism: The number of pointers to the nodes is equal, the degree of the tree D

Nodes are different: the number of node pointers varies, and the degree of the node is D

5.3 Child Brother representation

Implementation: A binary linked table for the storage structure of the tree, each node in the list of two pointers to their first child node and the next sibling node

Features: Easy to operate, destroy the level of the tree

6. Basic Terminology

Node-represents an element in a tree, including data items and several branches that point to its subtree

Node degree (degree)--number of subtrees owned by the node

Leaf (leaf)--a node of degree 0, also called terminal node.

Child--The root of the knot point tree is called the child of the node

Parent (parents)--the upper node of the child's knot is called the node.

The degree of the tree-the largest node in a tree

Node level--from the root node, the root is the first layer, its child is the second layer ...

Depth (depth)--the maximum number of layers in a tree's nodes

Ordered tree, unordered tree----If each subtrees tree in the tree has a certain order from left to right, it is not interchangeable, it is called ordered tree, otherwise called unordered tree.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

34. Toad's data structure note 34 Tree concept

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.