Max(3, 2) + 1 (root)
= 40
.1
(to account for the root).h
is the height of the tree.height = 0
.node_count
).height
by 1 after processing each level.Aspect | Recursive | Iterative |
---|---|---|
Approach | Divide-and-conquer | Level-order traversal |
Space Complexity | O(h) (stack space) | O(w) (queue space) |
Ease of Implementation | Simpler to implement | Requires explicit queue management |