wu :: forums
« wu :: forums - root to leaf sum with given numbers »

Welcome, Guest. Please Login or Register.
May 1st, 2025, 9:53am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: william wu, SMQ, towr, Grimbal, ThudnBlunder, Icarus, Eigenray)
   root to leaf sum with given numbers
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: root to leaf sum with given numbers  (Read 1130 times)
srikanth.iiita
Newbie
*





   


Posts: 33
root to leaf sum with given numbers  
« on: Mar 13th, 2010, 11:46am »
Quote Quote Modify Modify

given a bst,a number s and a group of numbers g, check whether all the elements of g occur in the same path,all elements sum upto s without including root and the leaf
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7528
Re: root to leaf sum with given numbers  
« Reply #1 on: Mar 15th, 2010, 9:06am »
Quote Quote Modify Modify

When you say "all elements sum up to s", does it refer to all elements in the BST or all elements in a path containing all elements of G?
 
And by path, do you mean a path starting from the root, or any path linking 2 nodes?
IP Logged
srikanth.iiita
Newbie
*





   


Posts: 33
Re: root to leaf sum with given numbers  
« Reply #2 on: Mar 16th, 2010, 10:41am »
Quote Quote Modify Modify

sum of elements means (sum of  given numbers in group g)
we have to find a root-leaf path ( excluding root,leaf)..
all other numbers should be equal to respective numbers in g
IP Logged
srikanth.iiita
Newbie
*





   


Posts: 33
Re: root to leaf sum with given numbers  
« Reply #3 on: Mar 16th, 2010, 10:45am »
Quote Quote Modify Modify

the elements of g should lie on a single path.. from root to leaf
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: root to leaf sum with given numbers  
« Reply #4 on: Mar 16th, 2010, 11:03am »
Quote Quote Modify Modify

Do we need to find all the elements of g on the path?
And wouldn't that mean we can check before hand whether they sum to s?
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
srikanth.iiita
Newbie
*





   


Posts: 33
Re: root to leaf sum with given numbers  
« Reply #5 on: Mar 16th, 2010, 11:18am »
Quote Quote Modify Modify

we have to find all the elements of g on a single path...
i don't know what to do with the sum...
« Last Edit: Mar 16th, 2010, 11:19am by srikanth.iiita » IP Logged
AB
Newbie
*





   


Posts: 20
Re: root to leaf sum with given numbers  
« Reply #6 on: Mar 17th, 2010, 10:25pm »
Quote Quote Modify Modify

I got it all wrong.. Does the sum refers to the sum of all the elements on the path.
IP Logged
srikanth.iiita
Newbie
*





   


Posts: 33
Re: root to leaf sum with given numbers  
« Reply #7 on: Mar 18th, 2010, 3:25am »
Quote Quote Modify Modify

sum of numbers in g.. i think....
IP Logged
sushiljacksparrow
Newbie
*





   
Email

Posts: 1
Re: root to leaf sum with given numbers  
« Reply #8 on: Mar 24th, 2010, 9:08pm »
Quote Quote Modify Modify

the recursive version of the code should look something like this..
   
 
    bool check( bool flag, set <int>s, int sum, node *root)
    {
     if(root->next->next ==NULL && sum==0 && set.size()==0)
      return true;
     if(root->next->next==NULL)
     return false;
   
    if(flag)
    {
 
    return check(!flag, s, sum, root->left) || check(!flag,s,sum,root->right);
  }
  else
  {
    return (s.find(root->data)!=s.end())?( (flag,s.delete(root->data),sum-root->data,root->left )||(flag,s.delete(root->data),sum-root->data,root->right)) : false;
}
}
 
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board