Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Stack or Queue? Why or why not? Consider (a) and/or (b) within response. 1. A pr

ID: 3687532 • Letter: S

Question

Stack or Queue? Why or why not? Consider (a) and/or (b) within response.

1. 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.

a.The maze wants the first initialize, the last position the program was at.

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.

a. Good use of a queue. First in to the queue is the first to be served (FIFO), which is how we should serve clients at a clinic.

b. Is it really a good idea? What about emergencies?

Explanation / Answer

1. Stack is used.

To backtrack to a poisition we need to keep track of the path in which we travelled. To perform back tracking we pop the stack to reach the initial state or previous state.

Stack was initialized to the poisition at which we started.

2. Considering Option B. in case of emergencies using FIFO queue is not Good idea.

Because the emergencies must be treated first, we need to use a priority queue.

In priority queue is patient is assigned with a priority, Queue must be treated based on priority value, Doctor is assigned to the patient with high priority.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote