Question 34.
Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.
You are managing an event ticketing system and need to process ticket requests in the order of their priority. Each ticket request has a priority number associated with it.
Code snippet:
class Ticket:
def __init__(self, ticket_id, priority):
self.priority = priority
tickets = []
tickets.append(Ticket(1))
tickets.append(Ticket(2))
tickets.append(Ticket(3))
tickets.append(Ticket(4))
tickets.append(Ticket(5))
priority_queue = []
for ticket in tickets:
heapq.heappush(priority_queue, (ticket.priority, ticket))
processed_tickets = []
while priority_queue:
processed_tickets.append(heapq.heappop(priority_queue)[1])
**
Show answer & explanation
Answer: A. A) Stack
Verified technical evaluation based on core computer science and mathematical principles.
Step-by-step Derivation:
Step 1: Parse problem constraints.
Step 2: Compute verified solution.
Step 3: Select matching option.