Relationship between number of nodes and height of binary tree Last Updated : 01 Feb, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Binary Tree is a hierarchical data structure in which each node has at most two children, referred to as the left child and the right child. It is commonly used in computer science for efficient storage and retrieval of data, with various operations such as insertion, deletion, and traversal.Prerequisite - Binary Tree Data Structure Height of Binary TreeThe height of the binary tree is the longest path from root node to any leaf node in the tree. For example, the height of binary tree shown in Figure 1(b) is 2 as longest path from root node to node 2 is 2. Also, the height of binary tree shown in Figure 1(a) is 4. Calculating minimum and maximum height from the number of nodes - If there are n nodes in a binary tree, the maximum height of the binary tree is n-1, and the minimum height is floor (log2(n)). For example, the left skewed binary tree shown in Figure 1(a) with 5 nodes has a height of 5-1 = 4, and the binary tree shown in Figure 1(b) with 5 nodes has a height floor(log25) = 2. Calculating minimum and maximum number of nodes from height:If binary tree has height h, minimum number of nodes is h+1 (in case of left skewed and right skewed binary tree). For example, the binary tree shown in Figure 2(a) with height 2 has 3 nodes. If binary tree has height h, maximum number of nodes will be when all levels are completely full. Total number of nodes will be 2^0 + 2^1 + …. 2^h = 2^(h+1)-1. For example, the binary tree shown in Figure 2(b) with height 2 has 2^(2+1)-1 = 7 nodes.Questions on Finding Height of Binary TreeQuestion-1. The height of a tree is the length of the longest root-to-leaf path in it. The maximum and the minimum number of nodes in a binary tree of height 5 are: (A) 63 and 6, respectively (B) 64 and 5, respectively (C) 32 and 6, respectively (D) 31 and 5, respectively Solution: According to formula discussed, max number of nodes = 2^(h+1)-1 = 2^6-1 =63. min number of nodes = h+1 = 5+1 = 6. Question-2. Which of the following height is not possible for a binary tree with 50 nodes? (A) 4 (B) 5 (C) 6 (D) None Solution: According to formula discussed, Minimum height with 50 nodes = floor(log2(50)) = 5. Therefore, height 4 is not possible. Comment More infoAdvertise with us Next Article Relationship between number of nodes and height of binary tree GeeksforGeeks Improve Article Tags : Tree Engineering Mathematics GATE CS Mathematics DSA Discrete Mathematics +2 More Practice Tags : Tree Similar Reads Bayes's Theorem for Conditional Probability Bayes's Theorem for Conditional Probability: Bayes's Theorem is a fundamental result in probability theory that describes how to update the probabilities of hypotheses when given evidence. Named after the Reverend Thomas Bayes, this theorem is crucial in various fields, including engineering, statis 9 min read Prosecutor's Fallacy The Prosecutorâs Fallacy is a considerate fallacy that is usually common in legal proceedings while assessing probability based on statistical data. This is actually getting the likelihood of finding evidence under a hypothesis confused with the likelihood of the hypothesis given the evidence. The l 9 min read Random Variable Random variable is a fundamental concept in statistics that bridges the gap between theoretical probability and real-world data. A Random variable in statistics is a function that assigns a real value to an outcome in the sample space of a random experiment. For example: if you roll a die, you can a 10 min read Mathematics | Graph Theory Basics - Set 1 A Graph is just a way to show connections between things. It is set of edges and vertices where each edge is associated with unordered pair of vertices. Graph is a data structure that is defined by two components :Node or Vertex: It is a point or joint between two lines like people, cities, or websi 5 min read Mathematics | Graph Theory Basics - Set 2 Graph theory is a basic branch of discrete mathematics that mainly focuses on the relationship between objects. These objects are called vertices and these vertices are joined by edges. Graphs are common in computer science, network analysis, and many other everyday uses because they provide a good 10 min read Types of Graphs with Examples A graph is a mathematical structure that represents relationships between objects by connecting a set of points. It is used to establish a pairwise relationship between elements in a given set. graphs are widely used in discrete mathematics, computer science, and network theory to represent relation 9 min read Euler and Hamiltonian Paths Euler and Hamiltonian paths are fundamental concepts in graph theory, a branch of mathematics that studies the properties and applications of graphs. An Euler path visits every edge of a graph exactly once, while a Hamiltonian path visits every vertex exactly once. These paths have significant appli 8 min read Planar Graphs and Graph Coloring Planar graphs and graph coloring are fundamental concepts in graph theory, a branch of mathematics that studies the properties and applications of graphs. A planar graph can be drawn on a plane without any edges crossing.While graph coloring involves assigning colors to vertices such that no two adj 6 min read Mathematics | Graph Isomorphisms and Connectivity Graph theory is a fundamental area in mathematics and computer science, which studies the properties of graphs and their applications. Two essential concepts in graph theory are graph isomorphisms and connectivity. Graph isomorphisms help determine if two graphs are structurally identical, while con 3 min read Matching (Graph Theory) Matching (Graph Theory): In graph theory, matching is a fundamental concept used to describe a set of edges without common vertices. Matchings are used in various applications such as network design, job assignments, and scheduling. Understanding matchings is essential for solving problems involving 4 min read Like