Minimum no. of iterations to pass information to all nodes in the tree

Given a very large n-ary tree. Where the root node has some information which it wants to pass to all of its children down to the leaves with the constraint that it can only pass the information to one of its children at a time (take it as one iteration).

Now in the next iteration the child node can transfer that information to only one of its children and at the same time instance the child’s parent i.e. root can pass the info to one of its remaining children. Continuing in this way we have to find the minimum no of iterations required to pass the information to all nodes in the tree.

Minimum no of iterations for tree below is 6. The root A first passes information to B. In next iteration, A passes information to E and B passes information to H and so on.

from: http://www.geeksforgeeks.org/minimum-iterations-pass-information-nodes-tree/

每次只能传播到一个子结点,要使迭代次数最小,那么迭代数要求比较大的点应该先传播。父结点的迭代数应该就是子结点的迭代数的最大值+i+1(这里i是按迭代数排序后的坐标)。

时间: 2024-10-26 19:42:44

Minimum no. of iterations to pass information to all nodes in the tree的相关文章

783. Minimum Distance Between BST Nodes BST节点之间的最小距离

Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Example : Input: root = [4,2,6,1,3,null,null] Output: 1 Explanation: Note that root is a TreeNode objec

783. Minimum Distance Between BST Nodes

Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Example : Input: root = [4,2,6,1,3,null,null] Output: 1 Explanation: Note that root is a TreeNode objec

[LeetCode&Python] Problem 783. Minimum Distance Between BST Nodes

Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Example : Input: root = [4,2,6,1,3,null,null] Output: 1 Explanation: Note that root is a TreeNode objec

783. Minimum Distance Between BST Nodes - Easy

Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Example : Input: root = [4,2,6,1,3,null,null] Output: 1 Explanation: Note that root is a TreeNode objec

[leetcode-783-Minimum Distance Between BST Nodes]

Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Example : Input: root = [4,2,6,1,3,null,null] Output: 1 Explanation: Note that root is a TreeNode objec

SVN :This XML file does not appear to have any style information associated with it.

SVN :This XML file does not appear to have any style information associated with it. The document tree is shown below. 地址输入错误.尼玛... SVN :This XML file does not appear to have any style information associated with it.

[LeetCode] Second Minimum Node In a Binary Tree

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes.

671. Second Minimum Node In a Binary Tree 二叉树中第二小节点

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly twoor zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. G

[leetcode-671-Second Minimum Node In a Binary Tree]

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes.