Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python heapq problem: Suppose you're working for tech support, and there are a bunchof tickets (requests for help) that need to be processed. Eachticket is

Python heapq problem:

Suppose you're working for tech support, and there are a bunchof tickets (requests for help) that need to be processed. Eachticket is represented as a tuple consisting of a positive integerfor the urgency (lower numbers are more urgent) and the user's idas a string. Assume there are exactly n tickets at the beginning,and the possible urgency levels are 1 through n. Tickets areprocessed one-at-a-time, in order of urgency. However, once aticket is resolved, it invariably generates another problem withthe user's machine requiring help (a chain reaction), albeit lessurgent. Specifically, if the urgency is u, then immediately afterbeing processed, another ticket gets generated with urgency 2u bythe same user, unless 2u > n (in which case no further ticket isgenerated at this time)

4a. [25 points Use Python's standard library heapq to write afunction process_tickets(t) that takes the initial list of ticketst and returns the list of user ids in the order they'll have thetickets processed. For example, process_tickets ([(1, 'Alice'), (4,'Bob'), (2, 'Carol'), (3, 'Alice')]) should return ['Alice','Alice', 'Carol', 'Alice 'Alice', 'Bob, 'Carol'] since Alice'surgency-1 ticket spawns an urgency-2 ticket, and Alice's andCarol's urgency- 2 tickets each spawn urgency-4 tickets (butAlice's urgency-3 ticket spawns nothing since 2 * 3 > n=4). Keepin mind that you can put tuples in a heap, and they will get sortedby the 0-th component (with ties broken by the 1-st component-alittle unfair to users at the end of the alphabet!)

4b. 5 points What is the running time?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions