Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4086836
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:46:44+00:00 2026-05-20T18:46:44+00:00

This question was asked of me in an interview. How can we convert a

  • 0

This question was asked of me in an interview. How can we convert a BT such that every node in it has a value which is the sum of its child nodes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:46:45+00:00Added an answer on May 20, 2026 at 6:46 pm

    Here is a solution that can help you: (the link explains it with tree-diagrams)

    Convert an arbitrary Binary Tree to a tree that holds Children Sum Property

    /* This function changes a tree to to hold children sum
       property */
    void convertTree(struct node* node)
    {
      int left_data = 0,  right_data = 0, diff;
    
      /* If tree is empty or it's a leaf node then
         return true */
      if(node == NULL ||
         (node->left == NULL && node->right == NULL))
        return;
      else
      {
        /* convert left and right subtrees  */
        convertTree(node->left);
        convertTree(node->right);
    
        /* If left child is not present ten 0 is used
           as data of left child */
        if(node->left != NULL)
          left_data = node->left->data;
    
        /* If right child is not present ten 0 is used
          as data of right child */
        if(node->right != NULL)
          right_data = node->right->data;
    
        /* get the diff of node's data and children sum */
        diff = left_data + right_data - node->data;
    
        /* If node's data is smaller then increment node's data
           by diff */
        if(diff > 0)
           node->data = node->data + diff;
    
        /* THIS IS TRICKY --> If node's data is greater then increment left
          subtree  by diff */
        if(diff < 0)
          increment(node->left, -diff);
      }
    }
    

    See the link to see the complete solution and explanation!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was the question asked in interview. Can we call one constructor from another
Yesterday in my interview I was asked this question. (At that time I was
In an interview this is the question that is asked: You have to write
This is a question that I was asked on a job interview some time
This is a interview Question which was asked and wanted to find an efficient
i was asked this question in my interview that how to make a class
I hope that this question has not been asked elsewhere, but I'm having difficulty
This question was asked at interview. Say I have a contract. [ServiceContract] public interface
This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more
This is an interview question asked a month ago.... Do session use cookies? If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.