当前位置:网站首页>Tree and binary tree: storage structure of binary tree
Tree and binary tree: storage structure of binary tree
2022-06-13 09:27:00 【Ritian juvenile wzh】
Trees and binary trees : Binary tree storage structure
The sequential storage structure of binary tree
Review the properties of binary trees 4, Complete binary tree nodes are numbered by sequence :
The sequential storage structure of a complete binary tree
Sequential storage structure of incomplete binary tree
Characteristics of binary tree sequential storage structure :
- about Perfect binary tree Come on , Its sequential storage is very suitable
- about General binary tree , Especially for those binary trees with many single branch nodes , Because only a few storage units may be used , Especially for degenerate binary trees ( That is, each branch node is a single branch ), The waste of space is amazing
- In a sequential storage structure , It's easy to find parents and children at a node
The chain storage structure of binary tree
reference The child chain storage structure of the tree - The chain storage structure of binary tree
In the chain storage of binary tree , The types of nodes are defined as follows :
typedef struct node {
ElemType data;
struct node *lchild,*rchild; // All points to binary trees : Recursion
}BTNode;
Characteristics of binary chain storage structure :
- Except pointer , Binary chain Save storage space . The storage space occupied has nothing to do with the tree , It is only related to the number of nodes in the tree
- In a binary chain , It's easy to find a child at a node , But it is inconvenient to find his parents
- A tree is represented by a child sibling chain storage structure - Binary chain
In a binary chain , Number of null pointers ?
- n Nodes — 2n A pointer to a domain
- The number of branches is n-1 — The non empty finger field has n-1 individual
- Number of empty finger needle fields = 2n-(n-1) = n+1
Advantages and disadvantages of binary tree sequential storage and chain storage :
One , Sequential storage
advantage : It is more efficient to read a specified node O(0)
shortcoming : It's a waste of space ( In the case of incomplete binary trees )
Two , Chain store
advantage : The efficiency of reading a specified node is low O(nlogn)
shortcoming : Relatively large binary trees waste less space
The sequential storage of binary trees , It is very convenient to find descendant nodes and ancestor nodes , But for ordinary binary trees , Sequential storage wastes a lot of storage space , It is also not conducive to the insertion and deletion of nodes . Therefore, sequential storage is generally used to store complete binary trees
The chain storage of binary tree saves storage space compared with sequential storage , When inserting or deleting nodes, you only need to modify the pointer , But it is inconvenient to find the specified node . However, ordinary binary trees usually use chain storage structure
边栏推荐
- Jenkins集成Ldap,Ldap配置错误导致jenkins用户登录失败问题解决
- (dfs+ tree DP) acwing 846 Center of gravity of tree
- Zigzag transformation
- LeetCode 6097. Match after replacing characters (Dictionary)
- Spectre record
- 拜登:希望尽快签署两党枪支安全改革法案
- 英国出台粮食安全计划抵御粮食供应危机
- C language: timer principle
- C language: file operation
- C language: shortcut keys commonly used in VS
猜你喜欢
turtle库的使用数字时钟模拟时钟动态显示
Overview of common layers of image recognition neural network (under update)
Online debugging tool Arthas Foundation
C language: minesweeping
Heap
1-2 24:00 (20 points) [CSP certification true question]
Jenkins access openldap user authentication
Class loading overview
Classes and objects -- object model and this pointer
Online debugging tool Arthas advanced
随机推荐
I have summarized the knowledge points of JS [intermediate and advanced] for you
C language: timer principle
攻防世界-PWN-shell
Jenkins接入Openldap用戶認證
Simple use of spiel expressions
Batch read all voice files under the folder
线上调试工具Arthas高级
Acwing785. quick sort (sort+ quick sort + merge sort)
JUC atomic accumulator
C language: preprocessing in program environment
JUC atomic array
LeetCode 5289. Fair distribution of cookies (DFS)
线上调试工具Arthas基础
1-2 24:00 (20 points) [CSP certification true question]
攻防世界PWN play 条件竞争漏洞的利用
计算两个时间相差的天数(支持跨月、跨年)
【最全面详细解释】背包问题详解
LeetCode 5259. Calculate the total tax payable
Online debugging tool Arthas advanced
批量读取文件夹下的全部语音文件