Celebrity

A celebrity among a group of n n people is the one who knows nobody but is known by everyone else.

You go to a party and wonder if there is any celebrity. You can figure that out only by asking questions in the form "Do you know this person?"

Provided you ask optimally, what is the complexity of the number of times you have to ask the question to identify the celebrity or conclude that he/she doesn't exist?

O ( 1 ) O(1) O ( n ) O(n) O ( n log n ) O(n\log n) O ( n 2 ) O(n^2)

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Calvin Lin Staff
Oct 22, 2016

To find if there is any celebrity, we have to ask at least n 1 n-1 questions for the form "Person i i , do you know person j j ?", where i i goes from 1 to n n , other than j j .

Conversely, we will show that 2 n 2n questions is sufficient.

Each time we ask "Person i i , do you know person j j ?", if the answer is Yes, then i i is not a celebrity. If the answer is No, then j j is not a celebrity.
We proceed as follows:
Start with i = 1 , j = n i = 1, j = n . Ask: Person i i , do you know person j j ?
If yes, we increase i i by 1.
If no, we decrease j j by 1.

The n 2 n-2 question is of the form: Person k k , do you know person k + 1 k+1 ?
If the answer is yes, then we have eliminated everyone other than k + 1 k+1 as a celebrity.
if the answer is no, then we have eliminated everyone other than k k as a celebrity.
We just have another at most n 1 n-1 questions to ask everyone else if they know the potential celebrity.

Hence, 2 n 3 2n-3 questions is sufficient, so the order of complexity is O ( n ) O (n) .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...