当前位置:网站首页>Basic concepts of tree
Basic concepts of tree
2022-06-30 20:37:00 【Life needs depth】
Summary
This chapter first introduces the relevant theoretical knowledge of binary tree , Then give C Detailed implementation of the language . Learning about binary trees , It should be noted that : It's not hard , Not only is it not difficult , And it's very simple . When I first came into contact with trees , I also think it seems very difficult ; This feeling is mainly due to a lot of strange concepts of binary trees 、 Nature and other contents . And when I really realized the binary tree and looked back at its related concepts and properties , I think it is so simple ! therefore , When learning binary tree : First, the basic concept of binary tree 、 Have a basic understanding of nature , Encounter difficult knowledge points , You can draw pictures to help understand ; After having a basic concept , And then I will personally implement the binary search tree ( This is crucial !); Finally, when I come back to summarize the theoretical knowledge of binary trees , You'll find that —— It's really simple ! In code practice , I take " Binary search tree , Not just a binary tree " Explain for example , A simple binary tree is very simple , It's rarely used in practice . Besides, I have mastered the binary search tree , The binary tree will be mastered naturally .
The binary search tree implemented in this article is C Language version of the , In the following chapters C++ and Java Implementation of version . You can practice learning according to your familiar language !
Please understand deeply 、 Practice and master " Binary search tree "! It is the later study AVL Trees 、 Stretch the tree 、 The cornerstone of red black tree and other related tree structures !
Catalog
1. Introduction to the tree
2. Introduction to binary tree
3. Binary search tree C Realization
4. Binary search tree C The test program
Reprint please indicate the source : Binary search tree ( One ) And Graphic analysis and C The realization of language - If the sky doesn't die - Blog Garden
More : Data structure and algorithm series Catalog
(01). Binary search tree ( One ) And Graphic analysis and C The realization of language
(02). Binary search tree ( Two ) And C++ The implementation of the
(03). Binary search tree ( 3、 ... and ) And Java The implementation of the
Introduction to the tree
1. The definition of a tree
A tree is a data structure , It is from n(n>=0) Finite nodes make up a set with hierarchical relationships .
- If n=0, It's called the empty tree
- If n>0, be :
- There is a specific called root (root) The node of , It has only direct successors , But there is no direct precursor
- Nodes other than the root are divided into m(m>=0) A finite set of disjoint T0,T1,...,Tn-1, Each set is a tree , And call it the subtree of the root (subtree)


Call it "it". “ Trees ” Because it looks like an upside down tree , That is to say, it is root up , And leaf down . It has the following characteristics :
(01) Each node has zero or more children ;
(02) A node without a parent is called a root node ;
(03) Each non root node has and only has one parent node ;
(04) Except for the root node , Each sub node can be divided into several disjoint sub trees .
2. The basic term for trees
If a node has a subtree , Then the node is called the root of the subtree " Parents ", The root of the subtree is the root of the node " children ". Nodes with the same parents are each other " brother ". Any node on all subtrees of a node is the descendant of that node . All nodes on the path from the root node to a node are the ancestors of the node .
The degree of node : The number of subtrees owned by the node .
leaf : A node of degree zero .
Branching nodes : Nodes with degree not zero .
The degree of a tree : The maximum degree of a node in a tree .
level : The level of the root node is 1, The hierarchy of the other nodes is equal to the hierarchy of the parent nodes of the node plus 1.
The height of the tree : The maximum level of nodes in a tree .
Disordered trees : If the order between the subtrees of the nodes in the tree is not important , You can switch places .
Ordered trees : If the order between the subtrees of nodes in a tree is important , You can't swap places .
The forest :0 One or more disjoint trees make up . Add a root to the forest , The forest becomes a tree ; Delete the root , Trees become forests .





1.3 Design common operations in the tree


2. The storage structure of the tree

The tree structure needs to add or delete nodes , Whether array storage can be flexible ? Each node can have multiple child nodes , How to store ?

2.2 The tree stores node relationships

The general tree representation method is based on the parent-child representation model , In this representation, each node has a pointer to its double clearing , Each node has several pointers to its children .
Another tree structure model is called the child brother representation model , Each node has a pointer to its first child , Each node has a pointer to its first right sibling .
Each node corresponding to this structure contains a data pointer and two node pointers :
- The data pointer points to the data stored in the tree
- The child node pointer points to the first child
- The sibling node pointer points to the first right sibling


Characteristics of the representation of children's brothers :
- Can represent any tree structure
- There are only three pointer fields in each node , Data pointer 、 Child node pointer 、 Sibling node pointer
- The structure of each node is simple , Only the child node pointer and brother node pointer constitute the tree branch
Choose to use a linked list to organize tree nodes , Storage nodes that can be traversed , The maintenance of linked lists is complicated .
边栏推荐
- Jenkins打包拉取不到最新的jar包
- Static classes use @resource annotation injection
- BioVendor sRAGE Elisa试剂盒测试原理和注意事项
- 杰理之关于长按开机检测抬起问题【篇】
- Basic components of STL
- 杰理之检测灵敏度级别确定【篇】
- Qt和其它GUI库的对比
- Notes on modification of Jerry's test box pairing software [chapter]
- Peking University ACM problems 1000:a+b problem
- 居家办公没有“血泪史”| 社区征文
猜你喜欢

PHP获取Opcode及C源码

Huffman tree (I) basic concept and C language implementation

哈夫曼樹(一)基本概念與C語言實現

PHP obtains opcode and C source code

Jenkins can't pull the latest jar package

左值引用和右值引用

Study on lumiprobe modified triphosphate biotin-11-utp

obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接

By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
![Jerry's touch key recognition process [chapter]](/img/ec/25d2d6fd26571e4fb642129a4eee1b.png)
Jerry's touch key recognition process [chapter]
随机推荐
Jenkins can't pull the latest jar package
Amazon restricts LGBTQ related search and product sales in the United Arab Emirates
Jerry's question about long press boot detection [chapter]
Jerry's determination of detection sensitivity level [chapter]
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
Dynamic style binding --style and class
杰理之触摸按键识别流程【篇】
Lumiprobe cell biology - dia, instructions for lipophilic tracer
To eliminate bugs, developers must know several bug exploration and testing artifacts.
北京大学ACM Problems 1006:Biorhythms
PM这样汇报工作,老板心甘情愿给你加薪
PM reports work like this, and the boss is willing to give you a raise
Golang应用 ━━ 安装、配置与使用hugo博客系统
maya房子建模
注册设备监理师难考吗,和监理工程师有什么关系?
Huffman Tree (1) Basic Concept and C - language Implementation
C文件指针
The Commission is so high that everyone can participate in the new programmer's partner plan
Implementation principle of PostgreSQL heap table storage engine
Go学习笔记