Inorder Traversal || Call Stack space to be considered (or) Not???

Hi all,

This query has been in my mind from many days and i wanted someone to clear it.
Problem :- Find number of nodes in a binary tree

Approach 1 :- (Iterative)
Do Inorder traversal using stack. whenever you are popping elements from stack, keep a count of it which are number of nodes in a binary tree.

Time Complexity - O(n)
Space Complexity - O(n)

Approach 2 :- (Recursive)

Time Complexity - O(n)
Space Complexity - O(1) or O(n)????

We can do inorder traversal recursively, but in an interview, which approach would be optimal expressing to the interviewer.....Iterative or recursive?? and also should i consider the recursive call stack space which boils down the space complexity to O(n) or should i stick with the O(1) Space complexity?

Comments (1)