Thread: Help,PLease!!!Something about BST

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Help,PLease!!!Something about BST

    i want to know how to find the height of a binary tree...Hope some one can help ma....thx

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What have you tried so far? Think about it logically on paper first, then try to write the code. Post it here when you have troubles and someone will help you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    3
    I have tried to use recursive function to do it,but actually cannot think of a feasible algorithm.Can any one tell me the algorithm of this function, thx a alot

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    The height of a tree is 1 plus the greater of the heights of the subtrees. That should be a clue on how to implement this recursively:

    Code:
    int TreeHeight( Node* Tree)
    {
        if node is NULL return 0;
        else return 1 plus greater of left/right subtree heights // hint: use recursion here
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Cool

    Wml:

    This is a common tree problem- you could have look it up in text/reference books. Or do a search on the internet!!
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST array
    By Iron_Shortage in forum C Programming
    Replies: 5
    Last Post: 04-20-2009, 03:04 PM
  2. bst in postorder to file algorithm?
    By iunah in forum C Programming
    Replies: 2
    Last Post: 02-01-2009, 06:13 AM
  3. problem inserting into recursive BST
    By nfrandsen in forum C Programming
    Replies: 4
    Last Post: 09-13-2008, 07:03 PM
  4. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  5. Splitting BST General
    By cpp_is_fun in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2005, 02:02 AM