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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly