Possible Duplicate:
the # of internal nodes
I'm taking course that's Data Structure in CS. I've this question that asks for a recursive algorithm that determines the height of the tree by given the ROOT NODE of the tree. I'll explain what is tree and root node:
root
/ \
internal node internal node
/ \ \
external node internal node external node
/
external node
what I've done so far is :
- input: int r (r= the root node) T is tree
- output: int h (h= the hight of tree)
hight(T,r):
if r is a root node of T then
- return 1
- else
- h<---1
- for each child w of r in T do
- h<---max(h, hight(T,w))
return 1+h
that what I get so far....