Sum of nodes in binary tree whose grandparents exists

Grandchild node of binary tree whose parents and grandparents exist. For example.

Sum of all nodes in binary tree whose grandparents exists
Example 1
         4   
        /  \                          
       /    \    
      12     7    
     / \      \               
    2   3      1
       / \    / 
      6   8  5
     /        
    9                        
-------------------
Here node 
node key   parent  grandparents
   2        12         4
   3        12         4
   6        3         12
   8        3         12  
   9        6         3 
   1        7         4  
   5        1         7 
--------------------------
  34
--------------------------

Example 2
-----------

         4   
        /  \                          
       /    \    
      12     7    
     / \                    
    2   3      
       / \     
      6   8   
     /        
    9                        
-------------------
Here node 
node key   parent  grandparents
   2        12         4
   3        12         4
   6        3         12
   8        3         12  
   9        6         3    
--------------------------
  28
--------------------------

Here given code implementation process.




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2022, kalkicode.com, All rights reserved