Non-recursive algorithm to find the height of a BInary Tree

R

Ravi

Hi,

I need to find the non-recursive algorithm to find the height of a
Binary Tree.

Regards,
SunLight.
 
W

Walter Roberson

I need to find the non-recursive algorithm to find the height of a
Binary Tree.

Any recursive algorithm can be converted to a non-recursive algorithm
(possibly requiring dynamic storage allocation for the implementation.)
 
K

Keith Thompson

Ravi said:
I need to find the non-recursive algorithm to find the height of a
Binary Tree.

Good luck with that. Did you have a question?

The fact that you need a non-recursive algorithm strongly implies that
this is homework. We won't do your homework for you.
 
S

SM Ryan

# Hi,
#
# I need to find the non-recursive algorithm to find the height of a
# Binary Tree.

Unless the tree is height balanced or threaded, you're going to be
doing an effectively recursive traversal anyway.
 
J

Julian V. Noble

Ravi said:
Hi,

I need to find the non-recursive algorithm to find the height of a
Binary Tree.

Regards,
SunLight.

According to Kruse, "Data Structures & Program Design" any recursive
algorithm can be converted to a non-recursive one, by theorem. However,
the proof is not constructive, so there is no guidance for specific cases.
This is why CS, like mathematics, has an element of art.

--
Julian V. Noble
Professor Emeritus of Physics
(e-mail address removed)
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"For there was never yet philosopher that could endure the
toothache patiently."

-- Wm. Shakespeare, Much Ado about Nothing. Act v. Sc. 1.
 
R

Richard Tobin

Julian V. Noble said:
According to Kruse, "Data Structures & Program Design" any recursive
algorithm can be converted to a non-recursive one, by theorem.

Though true, this is not generally useful, since you will typically
have to use something equivalent to a stack.

In the case of tree-traversal algorithms, it is sometimes possible to
use the tree itself instead of a stack, using "pointer reversal"
tricks. In years gone by garbage collectors often used this trick
(and perhaps they still do).

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top