Last week, the local Primary school was visited by the Government School Inspector who was there to check that teachers were performing well in their respective classes. He was very impressed with one particular teacher. The Inspector noticed that each time the class teacher asked a question, every child in the class put up their hands enthusiastically to answer it. More surprisingly, whilst the teacher chose a different child to answer the questions each time, the answers were always correct.
Why would this be?
The children were instructed to ALL raise their hands whenever a question was asked. It did not matter whether they knew the answer or not. If they did not know the answer, however, they would raise their LEFT hand. If they knew the answer, they would raise their RIGHT hand. The class teacher would choose a different child each time, but always the ones who had their RIGHT hand raised.
You have just purchased a small company called Company X. Company X has N employees, and everyone is either an engineer or a manager. You know for sure that there are more engineers than managers at the company.
Everyone at Company X knows everyone else's position, and you are able to ask any employee about the position of any other employee. For example, you could approach employee A and ask "Is employee B an engineer or a manager?" You can only direct your question to one employee at a time, and can only ask about one other employee at a time. You're allowed to ask the same employee multiple questions if you want.
Your goal is to find at least one engineer to solve a huge problem that has just hit the company's factory. The problem is so urgent that you only have time to ask N-1 total questions.
The major problem with questioning the employees, however, is that while the engineers will always tell you the truth about other employees' roles, the managers may lie to you if they like. You can assume that the managers will do their best to confuse you.
How can you find at least one engineer by asking at most N-1 questions?
You can find at least one engineer using the following process:
Put all of the employees in a conference room. If there happen to be an even number of employees, pick one at random and send him home for the day so that we start with an odd number of employees. Note that there will still be more engineers than managers after we send this employee home.
Then call them out one at a time in any order. You will be forming them into a line as follows:
If there is nobody currently in the line, put the employee you just called out in the line.
Otherwise, if there is anybody in the line, then we do the following. Let's call the employee currently at the front of the line Employee_Front, and call the employee who we just called out of the conference room Employee_Next.
So ask Employee_Front if Employee_Next is a manager or an engineer.
If Employee_Front says "manager", then send both Employee_Front and Employee_Next home for the day.
However, if Employee_Front says "engineer", then put Employee_Next at the front of the line.
Keep doing this until you've called everyone out of the conference room. Notice that at this point, you'll have asked N-1 or less questions (you asked at most one question each time you called an employee out except for the first employee, when you didn't ask a question, so that's at most N-1 questions).
When you're done calling everyone out of the conference room, the person at the front of the line is an engineer. So you've found your engineer!
But the real question: how does this work?
We can prove this works by showing a few things.
First, let's show that if there are any engineers in the line, then they must be in front of any managers.
We'll show this with a proof by contradiction. Assume that there is a manager in front of an engineer somewhere in the line. Then it must have been the case that at some point, that engineer was Employee_Front and that manager was Employee_Next. But then Employee_Front would have said "manager" (since he is an engineer and always tells the truth), and we would have sent them both home. This contradicts their being in the line at all, and thus we know that there can never be a manager in front of an engineer in the line.
So now we know that after the process is done, if there are any engineers in the line, then they will be at the front of the line. That means that all we have to prove now is that there will be at least one engineer in the line at the end of the process, and we'll know that there will be an engineer at the front.
So let's show that there will be at least one engineer in the line. To see why, consider what happens when we ask Employee_Front about Employee_Next, and Employee_Front says "manager". We know for sure that in this case, Employee_Front and Employee_Next are not both engineers, because if this were the case, then Employee_Front would have definitely says "engineer". Put another way, at least one of Employee_Front and Employee_Next is a manager. So by sending them both home, we know we are sending home at least one manager, and thus, we are keeping the balance in the remaining employees that there are more engineers than managers.
Thus, once the process is over, there will be more engineers than managers in the line (this is also sufficient to show that there will be at least one person in the line once the process is over). And so, there must be at least one engineer in the line.
Put altogether, we proved that at the end of the process, there will be at least one engineer in the line and that any engineers in the line must be in front of any managers, and so we know that the person at the front of the line will be an engineer.
Once upon a time, in the West Lake village, a servant lived with his master. After service of about 30 years, his master became ill and was going to die.
One day, the master called his servant and asked him for a wish. It could be any wish but just one. The master gave him one day to think about it. The servant became very happy and went to his mother for discussion about the wish. His mother was blind and she asked her son for making a wish for her eye-sight to come back. Then the servant went to his wife. She became very excited and asked for a son as they were childless for many years. After that, the servant went to his father who wanted to be rich and so he asked his son to wish for a lot of money. The next day he went to his master and made one wish through which all the three (mother, father, wife) got what they wanted. You have to tell what the servant asked the master.
The servant said, "My mother wants to see her grandson swinging on a swing of gold."
A poor miller living with his daughter comes onto hard times and is not able to pay his rent. His evil landlord threatens to evict them unless the daughter marries him.
The daughter, not wanting to marry the landlord but fearing that her father won't be able to take being evicted, suggests the following proposition to the landlord. He will put two stones, one white and one black, into a bag in front of the rest of the townspeople. She will pick one stone out of the bag. If she picks the white stone, the landlord will forgive their debt and let them stay, but if she picks the black stone, she will marry the landlord, and her father will be evicted anyway.
The landlord agrees to the proposal. Everybody meets in the center of the town. The landlord picks up two stones to put in the bag, but the daughter notices that he secretly picked two black stones.
She is about to reveal his deception but realizes that this would embarrass him in front of the townspeople, and he would evict them. She quickly comes up with another plan. What can she do that will allow the landlord save face, while also ensuring that she and her father can stay and that she won't have to marry the landlord?
The daughter picks a stone out, keeps it in her closed hand, and proclaims "this is my stone." She then throws it to the ground, and says "look at the other stone in the bag, and if it's black, that means I picked the white stone." The landlord will reveal the other stone, which is obviously black, and the daughter will have succeeded. The landlord was never revealed as a cheater and thus was able to save face.
In a far away land, it was known that if you drank poison, the only way to save yourself is to drink a stronger poison, which neutralizes the weaker poison.
The king that ruled the land wanted to make sure that he possessed the strongest poison in the kingdom, in order to ensure his survival, in any situation. So the king called the kingdom's pharmacist and the kingdom's treasurer, he gave each a week to make the strongest poison. Then, each would drink the other one's poison, then his own, and the one that will survive, will be the one that had the stronger poison. The pharmacist went straight to work, but the treasurer knew he had no chance, for the pharmacist was much more experienced in this field, so instead, he made up a plan to survive and make sure the pharmacist dies.
On the last day the pharmacist suddenly realized that the treasurer would know he had no chance, so he must have a plan. After a little thought, the pharmacist realized what the treasurer's plan must be, and he concocted a counter plan, to make sure he survives and the treasurer dies. When the time came, the king summoned both of them. They drank the poisons as planned, and the treasurer died, the pharmacist survived, and the king didn't get what he wanted. What exactly happened there?
The treasurer's plan was to drink a weak poison prior to the meeting with the king, and then he would drink the pharmacist's strong poison, which would neutralize the weak poison. As his own poison he would bring water, which will have no effect on him, but the pharmacist who would drink the water, and then his poison would surely die. When the pharmacist figured out this plan, he decided to bring water as well. So the treasurer who drank poison earlier, drank the pharmacist's water, then his own water, and died of the poison he drank before. The pharmacist would drink only water, so nothing will happen to him. And because both of them brought the king water, he didn't get a strong poison like he wanted.
At a dinner party, many of the guests exchange greetings by shaking hands with each other while they wait for the host to finish cooking.
After all this handshaking, the host, who didn't take part in or see any of the handshaking, gets everybody's attention and says: "I know for a fact that at least two people at this party shook the same number of other people's hands."
How could the host know this? Note that nobody shakes his or her own hand.
Assume there are N people at the party.
Note that the least number of people that someone could shake hands with is 0, and the most someone could shake hands with is N-1 (which would mean that they shook hands with every other person).
Now, if everyone at the party really were to have shaken hands with a different number of people, then that means somone must have shaken hands with 0 people, someone must have shaken hands with 1 person, and so on, all the way up to someone who must have shaken hands with N-1 people. This is the only possible scenario, since there are N people at the party and N different numbers of possible people to shake hands with (all the numbers between 0 and N-1 inclusive).
But this situation isn't possible, because there can't be both a person who shook hands with 0 people (call him Person 0) and a person who shook hands with N-1 people (call him Person N-1). This is because Person 0 shook hands with nobody (and thus didn't shake hands with Person N-1), but Person N-1 shook hands with everybody (and thus did shake hands with Person 0). This is clearly a contradiction, and thus two of the people at the party must have shaken hands with the same number of people.
Pretend there were only 2 guests at the party. Then try 3, and 4, and so on. This should help you think about the problem.
Search: Pigeonhole principle