What are the ways to realize binary tree?
What are the ways to implement binary trees? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
There are two ways to realize binary tree, namely: 1, sequential storage, which refers to using sequential table to store binary tree, which is only suitable for complete binary tree; 2. Chain storage, when storing binary tree by link, each node should not only store the data of the node itself, but also set up two pointer fields lchild and rchild.
Binary tree
Five basic forms: empty binary tree, binary tree with only root node, binary tree with root node and left subtree TL, binary tree with root node and right subtree TR, binary tree with root node, left subtree TL and right subtree TR
Other binary trees: oblique binary tree, full binary tree, perfect binary tree
Implementation: sequential storage, chain storage
The sequential storage of binary trees refers to the use of sequential tables (arrays) to store binary trees. It is important to note that sequential storage only applies to complete binary trees. In other words, only a complete binary tree can be stored using a sequential table. Therefore, if we want to store the ordinary binary tree sequentially, we need to convert the ordinary binary tree into a complete binary tree in advance.
Each node of a binary tree has at most two children. When storing a binary tree in a linked way, in addition to storing the data of the node itself, each node should also set up two pointer fields lchild and rchild, which point to the left child and the right child of the node respectively.
After reading the above, have you mastered the ways to realize the binary tree? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!