Trees Flashcards
1
Q
Height of Binary Tree
A
Height is defined by maximum count of nodes in a path.
Key is to set base case for if root == NULL return 0.
and then recursively return max(ht(root->left), ht(root->right)) +1.
Since we go through each node , time complexity is O(n) and auxiliary space required for recursion is O(ht)
Iterative: space is O(width) of tree by level order traversal.