0

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).

Community
  • 1
  • 1
nmeln
  • 495
  • 5
  • 17

1 Answers1

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