Results 1 to 3 of 3
  1. #1
    joshhazel is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Binary Tree Help - Find the largest sub-tree

    I have a binary tree and want to traverse through it to find the sub tree that has the largest total value.

    I get the concept of this issue but cannot quite figure out how i will program it. Any help appreciated.
    Attached Thumbnails Attached Thumbnails Binary Tree Help - Find the largest sub-tree-bt.jpg  
    Last edited by joshhazel; 01-30-2012 at 03:00 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: Binary Tree Help - Find the largest sub-tree

    If you can build a method that calculates the 'size' of a tree, you can always add one parameter that can contain a Node and the size of the tree starting at that Node. The recursion is just needed for the calculation of the 'size'; the parameter is just passed around and contains the Node and its 'size'. the parameter has the type:

    Java Code:
    class Parameter {
       Node node;
       int size;
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    joshhazel is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Re: Binary Tree Help - Find the largest sub-tree

    I need to be able to do this recursively without storing a sub-tree value.

Similar Threads

  1. binary tree
    By Dedo in forum Advanced Java
    Replies: 15
    Last Post: 05-26-2011, 09:11 PM
  2. Replies: 12
    Last Post: 10-31-2010, 06:14 PM
  3. binary tree
    By ryamz in forum New To Java
    Replies: 2
    Last Post: 08-12-2010, 02:45 AM
  4. Replies: 0
    Last Post: 04-04-2010, 07:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •