8

Node having maximum sum of immediate children and itself in n-ary tree

 2 years ago
source link: https://www.geeksforgeeks.org/videos/node-having-maximum-sum-of-immediate-children-and-itself-in-n-ary-tree/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Node having maximum sum of immediate children and itself in n-ary tree

Node having maximum sum of immediate children and itself in n-ary tree
  • 50 Views
  • 02/06/2022

Given an N-Ary tree, find and return the node for which sum of data of all children and the node itself is maximum. In the sum, data of node itself and data of its immediate children is to be taken.

The idea is we will maintain a integer variable maxsum which contains the maximum sum yet, and a resnode node pointer which points to the node with maximum sum. Traverse the tree and maintain the sum of root and data of all its immediate children in currsum integer variable and update the maxsum variable accordingly.

Node having maximum sum of immediate children and itself in n-ary tree : https://www.geeksforgeeks.org/node-maximum-sum-immediate-children-n-ary-tree/


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK