Would the below applications be suitable for a queue or a stack and why ? 1. An
ID: 3663562 • Letter: W
Question
Would the below applications be suitable for a queue or a stack and why?
1. An ailing company wants to evaluate employee records so as to lay off some worker on the basis of service time (the most recently hired employees are laid off first).
2. A program is to keep track of patients as they check into a clinic, assigning them to doctors on a first come, first served basis.
3. A program to solve a maze is to backtrack to an earlier position (the last place where a choice was made) when a dead-end position is reached.
4. An inventory of parts is to be processed by part number.
5. An operating system is to process requests for computer resources by allocating the resources in the order in which they are requested.
Explanation / Answer
1. An ailing company wants to evaluate employee records so as to lay off some worker on the basis of service time (the most recently hired employees are laid off first).
Ans: As the most recently hired employees are laid off first, stack is best choice for implenting this case. Stack is last in-first out i.e the last employee who joined will be the first one to be laid off.
2. A program is to keep track of patients as they check into a clinic, assigning them to doctors on a first come, first served basis.
Ans: The patients are to be serviced according to first come,first serve. So queue is the suitable for this case. Becuase Queue is first in-first out. The first entry will be removed first from queue.
3. A program to solve a maze is to backtrack to an earlier position (the last place where a choice was made) when a dead-end position is reached.
Ans: As we need to backtrack to last place, stack is suitable. In stack the last one is the first one to be popped out. So the last position is stored on top of the queue and it is the first one to be popped out from the stack.
4. An inventory of parts is to be processed by part number.
Ans: The Parts are to be processed by part number. But its not specified whether which part number (highest or lowest) are to be processed and which order (Ascending/Descending) they are inserted into Queue/Stack. So we cannot say wheter Queue or Stack is suitable.
IF the parts are inserted on ascending order and lowest part number is to be serviced first Queue is suitable. If highest part number is serviced first then stack is suitable.
As the part is processed by part number, Hash implementation is the best solution if you want to fetch part by part number.
5. An operating system is to process requests for computer resources by allocating the resources in the order in which they are requested
Ans: Ther processes are to be service according to the order in which they are requested. i.e first one requested is first one to be serviced. So Queue(FIFO-first in - first out) suitable for this.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.