The Queue Puzzle


A queue is the British term for a waiting line; it is also the term used in mathematics and computer science to denote a system for handling a stream of incoming jobs or "clients" that must wait in turn for the attention of a processor or "server".

In the standard form of a queue, a given number of clients N wait in line. The first client is being served. After the first client is served, it leaves the queue, and all other clients move up one position, with the former second client now at the head of the queue, and being served. If new clients arrive, they are placed at the end of the queue, in the order of their arrival. A queue is often called a "FIFO" or "first in, first out" system, since clients are served exactly in the order of their arrival.

Here is a variation of a queue. The first person is sent to the end of the queue, and the second person is served. Then the third person is sent to the end of the queue and the fourth person served, and so on. In this description of the queue, a client may be passed over many times, but will eventually be served. We describe this as a special queue with M = 2.

For the special queue with M = 3, we send clients 1 and 2 back to the end, and serve person 3. We send persons 4 and 5 to the end of the queue and serve person 6, and so on. Again, all clients will be served, although at the end there may be some funny business where the only remaining client will nonetheless be skipped twice before being served.

Clearly, this "special" queue can be regarded as a generalization of a standard queue, for which the parameter M would be 1. On the other hand, it hardly seems obvious that there would ever be any reason to use such a queue. And yet, such queues are used all the time and some even have theme songs!

For some reason, Josephus must take his place in a queue for which N = 41 and M = 3. What position should he take in order to be served last?

I give up, show me the solution.


Last revised on 01 April 2000.