Re: finding height of a BST by iteration
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 28 Mar 2007 06:12:06 GMT
subramanian100in@xxxxxxxxx, India wrote:
I know the Inorder, Preorder and Postorder traversal of a BST by
iteration.
Still I do not know how to calculate the height of a BST by iteration.
If you can traverse the tree in any order (with or without recursion)
then you can find the maximum height of the tree as you do so.
Keep a count, current_depth, of how deep you are in the tree at any one
step. Start with zero, increment current_depth whenever you move to a
node's children, decrement it whenever you step back from a node to its
parent. Keep a separate variable holding the maximum value of
current_depth. After you have completed the tree traversal, the
maximum will hold the height/depth of the tree.
-- chris
.
- References:
- finding height of a BST by iteration
- From: subramanian100in@xxxxxxxxx, India
- finding height of a BST by iteration
- Prev by Date: finding height of a BST by iteration
- Next by Date: Re: finding height of a BST by iteration
- Previous by thread: finding height of a BST by iteration
- Next by thread: Re: finding height of a BST by iteration
- Index(es):
Relevant Pages
|