Suppose the country of Matristan has a network of secret agents. These agents may only contact certain other agents directly, according to the following rules:
* Each agent may contact himself or herself directly.
* Agent A may contact agents B and C directly.
* Agent B may contact agents C and D directly.
* Agent C may contact agent B directly.
* Agent D may contact Agents A and B directly.
Here’s the question: What is the least number of intermediate contacts agent C needs to contact agent A?
We can set up a network matrix that simulates these rules…
…where matrix position if agent can contact agent , or otherwise. Here, represents the row and represents the column, contacting agents A through D are represented as rows 1 through 4 respectively, and contacted agents A through D are represented as columns 1 through 4 respectively. So, for example, every agent may contact himself/herself, so necessarily, for . Another example: since agent B may contact agents B, C, and D, , and , with (i.e. agent B who is row 2 cannot contact agent A who is column 1).
How would we answer the problem? Well, each of these agents is contacting another agent in the network. If we assume each agent may contact all other agents at once per round (within our rules), and that each agent passes on messages from agents that have contacted them to agents they are contacting, then we can solve this problem pretty easily.
Take the square of :
Well, it looks like agent C still can’t contact agent A, because . Multiply by again:
So now, . It took two steps for agent C to contact agent A. Of course, we could’ve found that out by inspecting the original matrix, . Agent C contacts agent B, who contacts agent D, who contacts agent A. Agents B and D are the intermediate agents.
This way is much cooler though.