Question: ***Use Python 3 and lots of comments,please!******* Q. Suppose youre working for tech support, and there are a bunch of tickets (requests for help) that

***Use Python 3 and lots of comments,please!*******

Q. Suppose youre working for tech support, and there are a bunch of tickets (requests

for help) that need to be processed. Each ticket is represented as a tuple consisting of a

positive integer for the urgency (lower numbers are more urgent) and the users id as a string.

Assume there are exactly n tickets at the beginning, and the possible urgency levels are 1

through n. Tickets are processed one-at-a-time, in order of urgency. However, once a ticket

is resolved, it invariably generates another problem with the users machine requiring help (a

chain reaction), albeit less urgent. Specifically, if the urgency is u, then immediately after

being processed, another ticket gets generated with urgency 2u by the same user, unless

2u > n (in which case no further ticket is generated at this time).

Q_a. Use Pythons standard library heapq to write a function process_tickets(t)

that takes the initial list of tickets t and returns the list of user ids in the order theyll

have the tickets processed. For example,

process_tickets ([(1, Alice),

(4, Bob),

(2, Carol),

(3, Alice)])

should return [Alice, Alice, Carol, Alice, Alice, Bob, Carol]

since Alices urgency-1 ticket spawns an urgency-2 ticket, and Alices and Carols urgency2

tickets each spawn urgency-4 tickets (but Alices urgency-3 ticket spawns nothing since

2 3 > n = 4). Keep in mind that you can put tuples in a heap, and they will get sorted

by the 0-th component (with ties broken by the 1-st componenta little unfair to users

at the end of the alphabet!).

Q_b.What is the running time?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!