In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
I would like to share with you the example analysis of binary tree and Hoffman tree in programming development. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. let's learn about it!
The deep properties of primary and binary trees
Property 1
There are at most 2 ^ (iMel 1) nodes in the I layer of the binary tree. (I ≥ 1)
The first layer of has at most 2-1 nodes.
The second layer of has at most 2 ^ (2-1) = 2 nodes.
The third layer of has at most 2 ^ (3-1) = 4 nodes
Property 2
A binary tree with a depth of k has at most 2 ^ k-1 nodes. (K ≥ 0)
If the has one layer, there will be at most 1 node between 2 and 1 node
If a has two layers, it has at most 3 nodes: 1: 2 = 2 ^ 2-1: 1
If the has three layers, there are at most 7 nodes of 1'2'4 = 2 ^ 3-1'7.
Property 3
For any binary tree, if it has n 0 leaf nodes and n 2 non-leaf nodes with degree 2, there are
n0=n2+1
Property 4
The height of a complete binary tree with n nodes is [log2 n] + 1. ([X] represents the largest integer not greater than X)
Property 5
A binary tree with n nodes (height is [log2 n] + 1). Nodes are numbered hierarchically (top to bottom, left to right). For any node I, there are:
if I = 1, then node I is the root of the binary tree.
If I > 1, the parent node of is [iUniver 2].
if 2i n, then node I has no left child
if 2i+1 n, then node I has no right child
Second, the method of creating binary tree
The method of guiding the way to locate nodes
The guidance method can avoid the "linear" location of binary tree recursion by locating through the relative position of the root node and the target node.
Binary tree storage structure
Using the structure to define the head node of the pointer domain binary tree in the binary tree can also be implemented by the structure / / the node pointer domain defines typedef struct _ tag_BTreeNode BTreeNode;struct _ tag_BTreeNode {BTreeNode* left; BTreeNode* right;}; / / the header node defines typedef struct _ tag_BTree TBTree;struct _ tag_BTree {int count; BTreeNode* root;}
Positioning: using 0 and 1 in the binary system to represent left and right respectively, bit operation is the basis of the guidance method.
Traversing the binary tree
The traversal of a single linked list means that starting from the first node (the node with the subscript 0), each node is accessed in a certain order.
The traversal of the binary tree means that starting from the root node, all the nodes in the binary tree are accessed in a certain order.
Preorder traversal
Mid-order traversal
Post-order traversal
Hierarchical traversal
4. Threaded binary tree
The threaded binary tree refers to the logical "rearrangement" of the nodes in the binary tree, so that it can access each node in a linear way.
After the binary tree is threaded, each node has a linear subscript, through which the node can be accessed quickly without traversing the binary tree.
Threading method 1
uses the empty pointer domain in the node to point to the successor node.
Algorithm idea:
Threading method 2
uses linear table to save the traversal order of binary tree.
Algorithm idea:
The structure of the tree will be destroyed by using the method of node null pointer lineation, and the binary tree can not be restored after threading.
These two problems can be solved by adding a threaded pointer to the tree node.
, however, the addition of threaded pointers will waste memory space and is not flexible enough.
The linked list threading method will not break the structure of the tree, but can destroy the linked list when it is not needed.
The linked list threading method can easily lineate the binary tree in any traversal order.
5. Hoffman tree
The above is all the contents of the article "sample Analysis of binary Tree and Huffman Tree in programming Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.