```Reply to Benjamin,

>
>> Suppose that a miracle happen and the decision is taken at the
>> highest level to retreat all of US military presence from Iraq. That
>> will take a while, but sending the orders quickly is a must.
>>
>> For utmost certainty, all orders are to be sent via phone and down
>> the command chain, and only to direct subordinates. Each officer has
>> a variable number of subordinates. Initially the president calls his
>> immediate subordinates, who call their immediate subordinates, etc.
>> Each call can be assumed to take the same amount of time.
>>
>> Devise an algorithm that ensures every foot soldier gets the news as
>> quickly as possible, show it is correct, and show it is fast.
>>
>> Andrei
>>
> Sort everyone under you (directly or indirectly) by the number of
> subordinates they have. Pick the subordinate with the most
> subordinates and call the next man in line to them. remove every
> subordinate down that chain of command and repeat.
>
> This assumes that the depth of command is more or less the same across
> the board.
>

This is based on the ssumption that the people with the most subordinates
need to get started first.
```
```BCS wrote:
>> Sort everyone under you (directly or indirectly) by the number of
>> subordinates they have. Pick the subordinate with the most
>> subordinates and call the next man in line to them. remove every
>> subordinate down that chain of command and repeat.
>>
>> This assumes that the depth of command is more or less the same across
>> the board.
>>
>
> This is based on the ssumption that the people with the most
> subordinates need to get started first.

But consider this case...

I have two subordinates: Dirk and Deek. Dirk has only one subordinate of
his own, but Deek has three. It seems like I should call Deek first.

But what if Dirk's single subordinate has twenty subordinates of his
own, which Deek's subordinates are leaf-nodes? In that case, it makes a
whole lot more sense to call Dirk first.

So it seems essential to implement a cost function for each branch of
the tree. Something more elaborate than just counting each person's
subordinates.

But a weighted-subtree function isn't the right approach either.

Consider this case (with JSON-y goodness):

A: {
B: [ B1, B2, B3, B4, B5, B6, B7, B8 ],
C: {
C1: [ C1a, C1b, C1c ],
C2: [ C2a, C2b, C2c ]
}
}

In this case, "A" has two subordinates: "B" and "C". If I calculate my
cost function by summing the number of subordinates under each officer,
"B" and "C" seem to have identical cost, since they have a total of
eight subordinates each.

The cost of any soldier "s" can be calculated like this:

1 + max(s.subordinateCount(), + s.mostExpensiveSubordinate())

Each officer should contact his subordinates in decreasing-cost order.

--benji
```