Re: finding height of a BST by iteration



"subramanian100in@xxxxxxxxx, India" <subramanian100in@xxxxxxxxx>
writes:

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.

Traverse the BST. Each time you move downward, increment a
counter; if the counter is greater than the maximum known height,
then set the maximum known height to the counter. Each time you
move upward, decrement the counter. When traversal is finished,
the maximum known height is the height.
--
Ben Pfaff
http://benpfaff.org
.



Relevant Pages

  • Re: finding height 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 ...
    (comp.programming)
  • Re: finding height of a BST by iteration
    ... I know the Inorder, Preorder and Postorder traversal of a BST by ... BST by iteration. ...
    (comp.programming)
  • Re: word count
    ... >> akarl wrote: ... >>> OK, this is already off topic, but...how do you traverse the ... > BST approach is slower however. ... Try your simple binary tree with sorted input. ...
    (comp.lang.c)
  • performance question related to BST traversal
    ... Suppose a BST contains 100,000 ndoes. ... Suppose I have to traverse the BST by Preorder, say, without using ... I allocate memory for an array of nodeCount times the size of a tree ...
    (comp.lang.c)
  • Re: [bug] block subsystem related crash with latest -git
    ... for scatterlist iteration such as "traverse sg_nextuntil NULL" ... The only other real option if we don't convert the whole tree now to ...
    (Linux-Kernel)