Thread: fill the gaps question..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    fill the gaps question..

    i am given two bst trees
    fill the gaps so it will return the number nodes which are equal in both trees

    Code:
    typedef struct Node{
    int Val;
    struct Node *Left, *Right;
    } Node;
    
    int CommonNodes(Node *T1, Node *T2) 
    {
        if ( ?? 1 ?? || ?? 2 ?? )
    	return 0;
    				
        if ( ?? 3 ?? == ?? 4 ?? ) 
    	return  ?? 5 ?? + ?? 6 ?? + ?? 7 ?? ;
    
        if ( ?? 8 ?? ) 
    	return  CommonNodes(?? 9 ??) + CommonNodes(?? 10 ??)
       - CommonNodes(?? 11 ??) ;
    
       if ( ?? 12 ??  ) 
    	return  ?? 13 ?? + ?? 14 ?? - ?? 15 ?? ;
    }
    i tried like this
    i know that its some how about
    when we take the same common nodes twice
    so we ned to subtract that group
    but i cant see when it happens
    Code:
    int CommonNodes(Node *t1, Node *t2) 
    {
        if (!t1||!t2 )
    	return 0;
    				
        if ( t1->val == t2->val) 
    	return  CommonNodes(t1->left,t2->left) + CommonNodes(t1->right,t2->right) +1;
    
        if ( ?? 8 ?? ) 
    	return  CommonNodes(?? 9 ??) + CommonNodes(?? 10 ??)
       - CommonNodes(?? 11 ??) ;
    
       if ( ?? 12 ??  ) 
    	return  ?? 13 ?? + ?? 14 ?? - ?? 15 ?? ;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You fill it in, like we all told you already ad-nauseum.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    nope you havent me how?

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by transgalactic2 View Post
    nope you havent me how?
    Just forget about filling in the blanks, for now. Solve the actual problem at hand, and once you have a firm grasp of the issue you probably won't have much trouble filling in the blanks (hopefully, anyway).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    no its not working like that.
    i told you what the last part is about
    but i dont know when it happens

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but these have a different algorithm.
    i have it on the tip of my tongue.
    the answer is
    we have two groups
    and in those two groups we have a common numbers
    so when we what to find the total number of values.
    we sum the amount of values in the first group with the amount of values in the second group
    and we delete the common numbers.(because we counted them twice)

    this is what they want in the last part
    but i cant figure out how to do that in that case in practice
    ??

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No effort = No thread.

    Closed. And I actually get to close this before Salem.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > but these have a different algorithm.
    Your point being?

    > i have it on the tip of my tongue.
    Great, but until your thoughts reach the tips of your fingers as well, we're not interested in your "bluster" as to what you know (or don't know).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fill the gaps question..
    By transgalactic2 in forum C Programming
    Replies: 4
    Last Post: 07-28-2009, 12:08 PM
  2. linked list fill the gaps question..
    By transgalactic2 in forum C Programming
    Replies: 2
    Last Post: 07-06-2009, 12:35 PM
  3. subsets filling the gaps question..
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 07-06-2009, 04:51 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM