You Can’t Pause Toast Leon needs to make breakfast toast for the n members of hi
ID: 3720633 • Letter: Y
Question
You Can’t Pause
Toast Leon needs to make breakfast toast for the n members of his family. His toaster can accommodate one person’s toast at a time, and each family member, j, wants their toast to spend tj seconds in the toaster. In Leon’s household, certain family members must have their toast before others (the precedence relationships form a directed acyclic graph). Violating precedence constraints is not an option, as it will make everything topsy turvy. Also, the amount of complaining that will be voiced by family member, j, if they receive their toast at time t is cj (t), where cj is a member-specific, non-negative, strictly increasing function. One thing Leon has learned is that you cannot pause toast. Pausing toast causes it to lose its essence. So, once Leon starts toasting someone’s toast, he cannot stop until it is done. Now, truth be told, Leon does not want to bring the ruckus to this breakfast. He asks you to develop a greedy algorithm that finds the ordering (schedule) that minimizes the maximum complaining among all valid toast schedules. Hint: start at the end
Explanation / Answer
It is evident that the sum of the waiting times for the family members should be minimized while maintaining the precedence relation and providing toasting times.
The following is the algorithm to find the ordering that minimizes the maximum complaining among all valid toast schedules:
Input:
Let G be the Precedence Graph, ti be the Toast times and cj(t) denotes the complaining.
Output:
The output will be an optimum schedule and the following steps are needed to be followed to get the required objective.
Find the list of nodes which does not have any incoming edges.
Append them in a queue Q in an increasing order of cj(t) for t = min (their toasting times).
A Breadth First Search(BFS) should be done by traversing through the entire graph G.
Dequeue the vertex v from the queue Q and place in the schedule.
Add the children nodes of v into the queue Q.
Continue this process until the queue Q becomes empty.
Finally, the schedule will be formed as an output.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.