Search code examples
algorithmdiscrete-mathematics

How do I solve this question about Pigeonhole Principle (Discrete Mathematics)?


I am not understanding the following question. I mean I want to know the sample input output for this problem question: "The pigeonhole principle states that if a function f has n distinct inputs but less than n distinct outputs,then there exist two inputs a and b such that a!=b and f(a)=f(b). Present an algorithm to find a and b such that f(a)=f(b). Assume that the function inputs are 1,2,......,and n.?"

I am unable to solve this problem as I am not understanding the question clearly. looking for your help.


Solution

  • Well let's go step by step.

    I have 2 boxes. My father gave me 3 chocolates....

    And I want to put those chocolates in 2 boxes. For our benefit let's name the chocolate a,b,c.

    So how many ways we can put them?

    [ab][c]
    [abc][]
    [a][bc]
    

    And you see something strange? There is atleast one box with more than 1 chocolate.

    So what do you think?

    You can try this with any number of boxes and chocolates ( more than number of boxes) and try this. You will see that it's right.

    Well let's make it more easy:

    I have 5 friends 3 rooms. We are having a party. And now let's see what happens. (All my friends will sit in any of the room)

    I am claiming that there will be atleast one room where there will be more than 1 friend.

    My friends are quite mischievious and knowing this they tried to prove me wrong.

    • Friend-1 selects room-1.
    • Friend-2 thinks why room-1? Then I will be correct so he selects room-2
    • Friend-3 also thinks same...he avoids 1 and 2 room and get into room-3
    • Friend-4 now comes and he understands that there is no other empty room and so he has to enter some room. And thus I become correct.

    So you understand the situation?

    There n friends (funtions) but unfortunately or (fortunately) their rooms (output values) are less than n. So ofcourse one of the there exists 2 friend of mine a and b who shares the same room.( same value f(a)=f(b))