Let's understand the balanced binary tree through examples. For example, AVL and Red-Black trees are balanced binary tree. The balanced binary tree is a tree in which both the left and right trees differ by atmost 1. It is also known as a left-skewed tree as all the nodes have a left child only. The above tree is also a degenerate binary tree because all the nodes have only one child. It is also known as a right-skewed tree as all the nodes have a right child only. The above tree is a degenerate binary tree because all the nodes have only one child. Let's understand the Degenerate binary tree through examples. The degenerate binary tree is a tree in which all the internal nodes have only one children. Note: All the perfect binary trees are the complete binary trees as well as the full binary tree, but vice versa is not true, i.e., all complete binary trees and full binary trees are the perfect binary trees. The below tree is not a perfect binary tree because all the leaf nodes are not at the same level. Let's look at a simple example of a perfect binary tree. The maximum height of a complete binary tree isĪ tree is a perfect binary tree if all the internal nodes have 2 children, and all the leaf nodes are at the same level.The minimum height of a complete binary tree is log 2(n+1) - 1.The minimum number of nodes in complete binary tree is 2 h.The maximum number of nodes in complete binary tree is 2 h+1 - 1.The above tree is a complete binary tree because all the nodes are completely filled, and all the nodes in the last level are added at the left first. In a complete binary tree, the nodes should be added from the left. In the last level, all the nodes must be as left as possible. The complete binary tree is a tree in which all the nodes are completely filled except the last level. The maximum height of the full binary tree can be computed as:.The minimum height of the full binary tree is log 2(n+1) - 1.The minimum number of nodes in the full binary tree is 2*h-1.The maximum number of nodes is the same as the number of nodes in the binary tree, i.e., 2 h+1 -1.In the above example, the number of internal nodes is 5 therefore, the number of leaf nodes is equal to 6. The number of leaf nodes is equal to the number of internal nodes plus 1.In the above tree, we can observe that each node is either containing zero or two children therefore, it is a Full Binary tree. Let's look at the simple example of the Full Binary tree. The full binary tree can also be defined as the tree in which each node must contain 2 children except the leaf nodes. The tree can only be considered as the full binary tree if each node must contain either 0 or 2 children. The full binary tree is also known as a strict binary tree. If there are 'n' number of nodes in the binary tree. Conversely, if the number of nodes is maximum, then the height of the tree would be minimum. If the number of nodes is minimum, then the height of the tree would be maximum.The minimum number of nodes possible at height h is equal to h+1.In general, the maximum number of nodes possible at height h is (2 0 + 2 1 + 2 2+….2 h) = 2 h+1 -1. Therefore, the maximum number of nodes at height 3 is equal to (1+2+4+8) = 15. The tree which is shown above has a height equal to 3. The height of the tree is defined as the longest path from the root node to the leaf node.At each level of i, the maximum number of nodes is 2 i.The nodes 3, 5 and 6 are the leaf nodes, so all these nodes contain NULL pointer on both left and right parts. The node 2 contains both the nodes (left and right node) therefore, it has two pointers (left and right). In the above tree, node 1 contains two pointers, i.e., left and a right pointer pointing to the left and right node respectively. The logical representation of the above tree is given below: The above tree is a binary tree because each node contains the utmost two children. Let's understand the binary tree through an example. Here, binary name itself suggests that 'two' therefore, each node can have either 0, 1 or 2 children. Balanced Binary Tree : It is a type of binary tree in which the difference between the height of the left and the right subtree is either 0 or 1.The Binary tree means that the node can have maximum two children.Perfect Binary Tree : It is a type of tree in which every node has exactly two children nodes and all the leaf nodes are at the same level.Full Binary Tree : A full Binary tree is a tree in which every node consists of either two or no children.Following are the few types of the binary tree : There are many different forms of binary tree depending on such as numbers of children each node has, whether all nodes are at the same level or not, if every level is filled et cetera.
0 Comments
Leave a Reply. |