The problem: There's a ton of animals on a farm. Every animal can have any number of animal friends, except for the anti-social animals--they don't have friends that belong to them, but they belong to other normal animals as friends. Each animal is exactly as happy as it's least happiest animal friend, except for the anti-social animals of course. The anti-social animals happiness' levels can be anything.
One morning all the animals wake up and find some of the anti-social animals mood's have changed. How does the farmer figure out the happiness of each animal?
Here's as far as the ranch hands got (they didn't go to farmer school):

DataTable animals = Select_All_Animals();
foreach (DataRow animal in animals.Rows)
{
int worstMood = 10; //Super Happy!
DataTable friendRecords = Select_Comp_Animal_AnimalFriend((int)animal["AnimalID"]);
foreach (DataRow friend in friendRecords.Rows)
{
DataTable animalFriends = Select_AnimalFriend((int)friend["AnimalID_Friend"]);
foreach (DataRow animalFriend in animalFriends.Rows)
{
int animalMood = Get_Animal_Mood((int)animalFriend["Mood"]);
if (animalMood < worstMood)
{
worstMood = animalMood;
}
}
}
}
But this will not work because the animal table does not sequentially follow the animal friend hierarchies that have formed. Animals can make friends with each other at any time! So Animal(1) might have Animal(4000) as a friend. Animal(1) will not show an accurate mood because it will check Animal(4000)'s mood before Animal(4000)'s mood has been updated itself. And new animals are being dropped off everyday. I figure the solution might a common algorithm design, but I haven't been able to find it. I don't believe I have the correct terminology