Reputation: 495
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).
Upvotes: 0
Views: 848
Reputation: 39457
You can turn your recursive algorithm into an iterative one.
Just use a stack structure where you do the recursion.
Upvotes: 1