7-Dec-15 Super Chicken A little puzzle
Pecking order Assumptions: Chickens have a pecking order: Given any two chickens A and B, either A pecks B or B pecks A (but not both) Pecking is not transitive: If chicken A pecks chicken B, and chicken B pecks chicken C, you don’t know whether chicken A pecks chicken C or chicken C pecks chicken A No chicken pecks itself Problem: Given a set of chickens and full information about who pecks whom, is there a super chicken—a chicken that pecks every other chicken (and is pecked on by none)? “There can be only one.”
Array representation We will use a 1 in [i][j] to show that chicken i pecks chicken j, and a 0 to show that it doesn’t The main diagonal ( i==j ) is all zeros, because no chicken pecks itself Except when i==j, the value in [i][j] is always different from the value in [j][i] I’ve colored a few [i][j], [j][i] pairs as examples An array with this form is called antisymmetric Notice that for n chickens, it requires n 2 time (and n 2 space) to create this array
Finding the super chicken A super chicken is one who is never pecked on Hence, the column for that chicken has all zeros (And the row has all ones, except for the cell on the main diagonal) It’s easy to come up with an n 2 algorithm to find the super chicken for each column c do for each row r do check if [r][c] is zero if not, try the next column You can’t do better than O(n 2 ) in creating the array There is an O(n) (linear time) algorithm for finding the super chicken Can you discover it?
About this puzzle This puzzle is not for credit, so don’t hand anything in When you find the answer, don’t give it away to your friends—make them work for it The answer is simple enough that, when you have found it, you will know you have found it If you aren’t sure, your solution is too complicated I think you will agree that finding the solution gives you a very satisfied feeling Analysis of algorithms is all about finding better solutions to problems
The End