Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a binary tree question..

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is a given binary tree
each of member are of a Node type


in the info part of each node we have a number.
in each one of his leaves we have some number
and in each one of its roots (crossroads) we have zeros.

my gole is to build a method which calculates the difference between the
sums of the leaves in the right subtree of T
and the sum of the leaves in the left subtree of T
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So what have you tried so far ?
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my main idea that i can think of is
building a recursive function for each suntree of T
and because i was told that all the subroots are zeros
then if i get an object in which we have null in both the right and
the left of its "sub objects"

for BTree


for BNode:


i dont know if i did it correctly
can you tell me if i got my purpose in this code??
 
Henry Wong
author
Marshal
Pie
Posts: 21194
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know if i did it correctly
can you tell me if i got my purpose in this code??



How do you propose to tell if you did it correctly? Can you write a test program to try it out? Remember, you don't need the complete program to test the code, you can test individual components.

Henry
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my time is running realy short till my test
i dont have time to build a whole program to test this

i am asking you to look in a proffesional eye
and tell wether i did it ok

i in my code i tried to look for the leaves of the left subtree add them together then to add the leaves of the right subtree together

and to calculate the difference between them
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My professional eye, like Henry's, tells me that looking at code is a rather poor way of telling whether code will work. That's why we advocate testing code.
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i will be satisfied with your opinion

even if its not as good as building a test program

again its because i am short on time
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short of time or not, you should at least try compiling the code. That would only take you a few seconds whereas soliciting answers here will take much longer than that.

(Hint: your code won't compile.)

The fact that you made the choice to post rather than to compile indicates, to me at least, the reason you're short of time. You just aren't managing your time well.
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok want to try my code

how do i build a binary tree
to test my code on
??

personally i prefer to know where is my logical problem with the code
cause i think i have done it ok
??
[ February 18, 2008: Message edited by: donaldth smithts ]
[ February 18, 2008: Message edited by: donaldth smithts ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like the OP found time to compile his code here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic