BST Height Formula:
From: | To: |
The height of a binary search tree is the number of edges on the longest path from the root node to a leaf node. It's a fundamental measure of a tree's structure and affects search efficiency.
The calculator uses the recursive BST height formula:
Where:
Explanation: The height of a tree is determined by its tallest subtree plus one for the current node.
Details: Tree height directly impacts search performance (O(height) time complexity) and helps determine if the tree is balanced.
Tips: Enter the heights of left and right subtrees (0 if subtree is empty). The calculator will compute the total height of the BST.
Q1: What's the height of an empty tree?
A: The height of an empty tree (null node) is typically considered -1 or 0, depending on definition. This calculator uses 0 as base case.
Q2: How does height relate to tree balance?
A: A balanced BST has heights of left and right subtrees differing by at most 1 at every node.
Q3: What's the time complexity of height calculation?
A: O(n) for full traversal, but this calculator assumes you already have subtree heights.
Q4: How is this different from depth?
A: Height is measured from leaf to root (bottom-up), while depth is from root to node (top-down).
Q5: What's the minimum possible height for n nodes?
A: Minimum height is ⌊log₂n⌋ for a perfectly balanced tree.