Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand trees in programming

Shulou Source: shulou.com Published: 2022-06-03 01:24:21 09月21日 Update

This article mainly explains "how to understand the tree in programming". The content in the article is simple and clear, and it is easy to learn and understand. let's follow the editor's train of thought to study and learn how to understand the tree in programming.

Tree

Tree is a very commonly used data structure, which keeps pace with linear tables and stacks.

Definition of tree

Tree is abstracted from nature. It refers to a finite set of N parent and child nodes. For this finite set, the following conditions need to be met:

When Numb0, the node collection is empty and the tree is empty.

In any non-empty tree, there can be only one root node

When N > 1, the other nodes that are unexpected to the node are also gathered to form a tree. That is, a tree is recursive, a tree is made up of several subtrees, and each tree is made up of several smaller subtrees, as shown in the figure

Binary tree

A binary tree is an ordered tree in which each node can only have at most two subtrees. Usually the left subtree is called the left subtree and the right tree is called the right subtree. A binary tree can only have two symmetrical trees at most, and a binary tree can be divided into left and right. The difference between a tree and a binary tree

1. There is no limit on the degree of the nodes of the tree, the binary tree is limited to 2, and the tree has no limit.

two。 The nodes of the unordered tree are not divided into left and right, while the nodes of binary tree are divided into left and right.

Binary search tree

Binary search tree is an empty tree. A binary tree with the following properties is called binary search tree.

Its left subtree is not empty, and all node values of the left subtree are less than the values of the following nodes.

If its right subtree is not empty, the value of all nodes in the right subtree is greater than the value of the following node.

Its left and right subtrees are binary sorting trees respectively.

Balanced binary tree

A balanced binary tree has the following properties: it is an accusation or the absolute height difference between its left and right subtrees is not more than 1, and both left and right subtrees are a balanced binary tree. The nodes of balanced binary tree are red-black tree, AVL tree, stretching tree, and the node of minimum binary balanced tree is F (n) = F (nmur1) + F (nmur2) + 1.

B-tree

An m-order B tree, which is a balanced m-path search tree, or an empty tree, satisfies the following properties

1 root node has at least two children

Each non-follower node contains 1 element of k Mel and k children, of which m prime 2

Tags: Node subtree element leaf two data black programming search property index red learning limit minimum information content child database file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi Shulou Information Docker Shulou Technology