Open In App

Puzzle – Good Processor

Last Updated : 18 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Question:

You are in a spaceship with an n-processor computer. Suddenly, the spaceship is hit by an alien laser beam and some of the processors are damaged. However, you recognize that quite half the processors are still good. You can ask one processor whether or not it thinks every other processor is right or horrific. An exact processor will usually inform the truth, however, a horrific one will usually lie. A ‘step’ consists of asking one processor if it thinks another processor is good or bad. Find a minimum number of steps required to find at least one good processor.

Solution:

Let the processors be numbered 1,2,3….. up to n. Let’s start by asking processor 1 if processor 2 is good. If the answer is “no”, remove these two processors from the list and start again. Remember that you already removed one good processor and one bad processor from the list, so more than half of the remaining processors are still good. But if processor 1 says processor 2 is good, continue by asking processor 2 about processor 3, 3 about 4, and so on, until you get a “no” answer. Let’s suppose, the processor ‘j’ that says processor j+1 is bad. Both processors j and j+1 are removed from the list (as before, more than half of the remaining processors are good, since one of the two which were removed was good and one was bad), and the process is continued by asking processor j-1 about processor j (the processor that was after j+1 before it was removed and the original processor j).
A “chain” of processors is being created where each processor thinks that the next processor in the chain is good. So these processors may be all good or all bad. Once this chain becomes more than half of the processors in the remaining list, you are confirmed that all these processors are good. Or, if you’ve removed so many processors that only one or two remain, you know that  one or those two are good.
This process involves at most n-2 steps because every processor is asked about at most once, and the first processor is never asked about. Also, the last processor is never asked about either, and you stop once the chain is longer than half the list.
Hence, N-2 is the correct answer.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads