I know how to count nodes on a level of a tree recursively (used tips from this answer https://stackoverflow.com/a/12879973/2663649 ), but I can't form an iterative algorithm, and not sure if I should use stack or pointer array to save previous nodes (to return to root).
Asked
Active
Viewed 836 times
1 Answers
1
You can turn your recursive algorithm into an iterative one.
Just use a stack structure where you do the recursion.

peter.petrov
- 38,363
- 16
- 94
- 159