views:

500

answers:

7

I found the following question while preparing for an interview:

You are in a very huge library that has no computer access, and you're looking for one particular book.

You look up where the book suppose to be from the card catalog, and went to shelf X to find it.

However the book is not there.

There is only one person that can answer questions, which is the libarian, but he only answers yes/no responses. Plus, his answers might not be correct.

What is your strategy for finding this book?

How would you answer this question? What methods of searching would you use?

+7  A: 

Use Binary search type questions to narrow the location of the book.

Each question should narrow the search field by half.

"Is the book on this half of the library"? (Point to the right direction).

Would work as an initial question.

You can also use The Knight and the Knave as part of your method of questioning the person. Your first 5 questions (to establish a baseline) could be about things you 'know'. You could determine his error rate from there. After that, you can use Binary Search-esque questions to determine where the book is.

George Stocker
log(n) questions where n is the number of books in the library. Since the library is "very huge" and the librarian has a > 0 probability of being wrong, this is unlikely to succeed.
Ben S
Not likely. If the librarian's answers might not be correct, then you could waste time looking at the wrong half of the library. This is equivalent to simply looking through the entire library. In fact, you cannot use any Binary search type questions because the answer could at any time be incorrect (or always incorrect). Thus you can gain no sense as to where the book is via this method.
AlbertoPL
I was extending my answer as you guys were typing. No, it alone may not be succesful, but using it plus known questions as a baseline would make it very successful. @Ben S: The search area is cut in half with each request; once you get it down to a shelf you simply need to scan the shelf. It's the most optimal solution.
George Stocker
it doesnt matter, the first question should be if the librarian even knows where the book is?
TStamper
You could also ask every question 10+ times and pick whichever answer he gives you more frequently (i.e 7 yes and 3 no => go with yes).
gnovice
And, for any number of books in the library, there's a likelihood the answer is correct that makes exhaustive search faster.
David Thornley
The interview suggests that looking at the book one by one would take days, and since books are kinda of random with unreliable answers from the librarian, I don't think binary search is the way to go
Timothy Chen
Nothing that I've suggested says you'd have to look at books '1 by 1' -- that's contrary to the essence of a binary search.
George Stocker
+1  A: 

here's a starting point: Assume the library uses the Dewey decimal system (but any classification system could be substituted). Question 1: is the book in the 100s? Question 2: is the book in the 200s? .. is the book between 50 and 150? is the book between 150 and 250?

james
I asked this question before going down this route, "Do you know where the book is?" answer is "no" :)
Timothy Chen
+4  A: 
Beta
+1 (for suggesting bribery :-) and) for considering realistic ways of avoiding the problem altogether - spending some time to come up with an O(0) solution (i.e. a way to avoid the work altogether) is much more efficient than any algorithm.
Andrzej Doyle
I like these strategies! Could add the ones other has suggested, like checked-out, being checked-out, being checked-in, on the way returning, etc.
Timothy Chen
+6  A: 

Step A: Calibrate your Librarian.

Pick a random book in the library, walk to a random spot and then ask the Librarian if the book (whose location you know) is to your left. Keep testing the Librarian until you have a good estimate of the probability, p, that Librarian answers correctly. Note that if p < 0.5 then you are better off following the opposite of whatever Librarian tells you. If p=0.5 then give up on Librarian -- her responses are no better than a flip of a coin.

If you find that p depends on the question asked (for example, if the Librarian always answers certain questions correctly, but other questions always falsely), then go to Step B1.

Step B1: If p==0.5 or p depends on the question asked, start thinking outside the box, like Beta suggests.

Step B2: If p < 0.5, reverse the answer the Librarian gives, and proceed to Step B3.

Step B3: If p > 0.5: Choose N. If p is close to 1, then N can be a low number like 10. If p is very close to 0.5, then choose N large, like 1000. The right value of N depends on p and how confident you wish to be.

Ask the Librarian the same question N times ("Is the book I'm looking for to my left"). Assume for the moment that whatever response is given more frequently is the "correct answer". Calculate the average response, assigning 1 for the "correct answer" and 0 for the wrong answer. Call this the "observed average".

The responses are like draws from a box with 2 tickets (the right answer and the wrong answer.) The standard deviation of a sample of N draws will be sqrt(p*q), where q = 1-p. The standard error of the average is sqrt(p*q/N).

Take the null hypothesis to be that p=0.5 -- that the Librarian is simply giving random responses. The "expected average" (assuming the null hypthesis) is 1/2.

The z-statistic is the (observed average - expected average)/(standard error of the average) = (observed average - 0.5)*sqrt(N)/(sqrt(p*q))

The z-statistic follows a normal distribution. If the z-statistic is > 1.65 then you have about a 95% chance the average response of the Librarian is statistically significant. If after N questions z is less than 1.65, repeat Step B3 until you get statistically significant response. Note that the larger you choose N, the larger the z-statistic will be, and the easier it will be to obtain statistically significant results.

Step C: Once you get a statistically significant response, you act upon it (using George Stocker's binary search idea) and hope you have not been statistically unlucky. :)

PS. Although the library might be 3-dimensional, you could play the Binary Search game along the x-axis, then the y-axis, then the z-axis. So the 3-dimensional problem can be reduced to solving 3 (1-dimensional problems).

unutbu
I guess it's hard to put statistics in a human that doesn't know it all :)
Timothy Chen
+1  A: 

Depends on who you are interviewing for:

Government (non-law enforcement/military) - hire infinite number of staff to check every location in library. Then hire an infinite number of junior managers to manage those staff, add an infinite number of middle managers etc.

Large corporation - same but use unpaid interns.

Government (law enforcement/military) - take librarian, apply tazer or waterboarding until location of book is revealed.

Small company (web 2.0 startup) - blog about location of book until somebody tells you.

Small company (real business) - try another library / bookstore.

Martin Beckett
A: 

Is it cheating to ask if the librarian takes commands? If he does, simply tell him to find the book and bring it back to you.

maniak1982
A: 

How would you answer this question?

"Thank you for your time." And I'd get up and walk out of the interview room. I'm not interested in working with people who think that asking silly riddles in an interrview is more useful than asking me to write some code or demonstrate how I would plan a project or lead a team.

Ether