Properties of Binary TreeThe common nonlinear data structure known as a tree. A tree illustrates a hierarchical structure in contrast to other data structures such an array, stack, queue, and linked list, which are linear in nature. A tree's ordering information is irrelevant. Two pointers and nodes make up a tree. The parent node's left and right children are represented by these two pointers. Let's thoroughly comprehend the words used in trees.
The primary uses for tree data structures include:
What is a Binary Tree?A binary tree is a tree data structure made up of nodes also known as left and right nodeseach of which has a maximum of two offspring. The tree starts at the root node. Binary Tree RepresentationEach node in the tree has the following information:
In C, we may use structures to represent a tree node. We may utilise classes as a component of other languages' OOP features. An illustration of a tree node containing integer data is shown below. Why use a treebased data structure?
Properties of Binary Tree1. In a binary tree, level 'l' can have up to 2l nodes: Note: In this case, level refers to the quantity of nodes along the route from the root to the node (including root and node). The root's level is 0.This is demonstrable by induction: Root l = 0, 20 nodes = 1 for root Assume there are 2l nodes at most on level "l." Since each node in a binary tree may only have two offspring, the subsequent level would have twice as many nodes, or 2 * 2l. 2. There can be a maximum of 2h  1 nodes in a binary tree of height "h": Notably, the maximum number of nodes along the roottoleaf path determines a tree's height in this case. A tree with a single node is regarded as having a height of 1. This outcome follows from the second point above. If all levels have the maximum number of nodes, the tree has reached its maximum number of nodes. Therefore, there may be a maximum of 1 + 2 + 4 +.. + 2h1 nodes in a binary tree of height h. This is a straightforward geometric series with h terms, and its total is 2h1. The height of the root is regarded as zero in certain texts. In this case, the formula above becomes 2h+1  1. 3. The smallest height or smallest number of levels in a binary tree with N nodes is Log2(N+1): Since each level must include at least one element, the height cannot exceed N. The most nodes that a binary tree of height "h" may have is 2h  1. (previous property). Consequently, there won't be as many nodes as this many or more. N <= 2h  1 2h >= N+1 log2(2h) >= log2(N+1) (Taking log both sides) hlog22 >= log2(N+1) (h is an integer) h >=  log2(N+1)  So the minimum height possible is  log2(N+1)  4. There are at least  Log2L + 1 levels in a binary tree with L leaves: When all levels are completely filled, a binary tree has the most leaves (and the fewest levels). If all leaves are at level L, then the formula below holds for L leaves. L <= 2l1 [From Point 1] [Note: Here, consider level of root node as 1] l =  Log2L  + 1 where l is the minimum number of levels. 5. The number of leaf nodes is always one more than nodes with two children in a binary tree where each node has 0 or 2 children: L = T + 1 Where L = Number of leaf nodes T = Number of internal nodes with two children Proof: No. of leaf nodes (L) i.e. total elements present at the bottom of tree = 2h1 (h is height of tree) No. of internal nodes = {total no. of nodes}  {leaf nodes} = { 2h  1 }  {2h1} = 2h1 (21)  1 = 2h1  1 So , L = 2h1 T = 2h1  1 Therefore L = T + 1 Hence proved 6. If n is the total number of nodes and e is the total number of edges in a nonempty binary tree, then e = n1: Except for the root node, every node in a binary tree has precisely one parent. So n1 nodes have precisely one parent if n is the entire number of nodes. Every child and its parent share the same edge. Thus, there are n1 edges overall. Application of Binary Tree
Binary Tree's benefits include
Binary Tree disadvantages:
Next TopicRight View of Binary Tree
