A school has one printer shared by all its classrooms. Explain why a queue is a more appropriate data structure than a stack for holding the print jobs.
Show the markscheme
Markscheme (3 marks)
- A queue is FIFO: the first job sent is the first to be printed.
- Therefore jobs are printed in order of arrival / fairly.
- With a stack (LIFO) the last job sent would be printed first, so the earliest jobs could wait indefinitely (starvation) if new jobs keep arriving.
A full-marks answer
A queue works on a FIFO basis: jobs are added at the rear and the printer always takes the one at the front, that is, the one that has been waiting longest. In this way documents are printed in the same order in which they were sent, which is fair to all users. If a stack (LIFO) were used, the most recently received job would always be printed first; at a busy time, the earliest jobs would stay at the bottom and might never be printed while others kept arriving.