The answer is easier to arrive at if you imagine the 2nd and subsequent children of a given node are actually a chain of descendents of the first child node, so that e.g.
O
/|\
/ | \
/ | \
O O O
is actually represented as
O
/
/
/
O===O===O
(I'm representing "sibling-of" edges as ===
.) In this new representation, each node except the root can have at most 2 children: one being its actual first child, and the other being its first sibling to the right. (The root can have no siblings so it will have at most one child.) For example, the second tree in the OP's post,
O
/ \
/ \
/ \
O O
/ \
/ \
/ \
O O
can be represented in the "sibling-edge" representation as
O
/
/
/
O=======O
/
/
/
O=======O
The trick is that transfers to both of a node's children will occur simultaneously. That lets us arrange the tree visually so that all nodes that are transferred to at the same time appear in the same vertical position. We now get:
0 O
/
/
/
1 O
/ \\
/ \\
/ \\
2 O O
\\
\\
\\
3 O
To figure out the maximum number of nodes that can be transferred to by time t
, we need a tree in the above layout whose bottommost (t
th) row contains no gaps. Let's call this maximum number of nodes m(t)
. For t
> 1, we can build such a tree by taking the maximum-size tree for t-1
and creating 2 children (= 1 child and 1 sibling in the original tree) for each rightmost node. Tabulating a few values of m(t)
gives us:
t Total Rightmost
nodes nodes
0 1 1
1 1+1*1=2 1 (only multiply by 1 because the root can't have siblings)
2 2+1*2=4 2
3 4+2*2=8 4
4 8+4*2=16 8
Clearly, m(t) = 2^(t-1)
, which makes sense, because this optimal tree is just a complete binary tree with a little "stem" at the top for the root node.
From this it follows that if the number of nodes n
is a power of 2, the optimal tree for n = 2^t
nodes needs t+1
time, while if it's not, it will need 1 more unit of time than the next smaller power of 2. So the amount of time needed to send to n
nodes is roundup(log2(n)) + 1
.
To realise the actual communication tree, you can now convert the "sibling-of" edges back into edges between the left node's parent and the right node. This shows that for power-of-2 node counts, the number of edges leaving the root will be the same as the total time needed (roundup(log2(n)) + 1
). The number of edges leaving the 1st child of any node is always one less than its parent, and the number of edges leaving each 2nd and subsequent child is always one less than its left sibling.