nmeln
nmeln

Reputation: 495

Find count of nodes on a specific level of a binary tree (iteratively)

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

Answers (1)

peter.petrov
peter.petrov

Reputation: 39457

You can turn your recursive algorithm into an iterative one.
Just use a stack structure where you do the recursion.

Upvotes: 1

Related Questions