0
0
DSA Pythonprogramming~30 mins

Priority Queue Introduction and Concept in DSA Python - Build from Scratch

Choose your learning style9 modes available
Priority Queue Introduction and Concept
📖 Scenario: Imagine you are managing a hospital emergency room. Patients arrive with different levels of urgency. You want to treat the most urgent patients first. This is a perfect use case for a priority queue.
🎯 Goal: You will create a simple priority queue using a list of tuples where each tuple contains a patient's name and their priority level. Then, you will extract patients in order of their priority.
📋 What You'll Learn
Create a list called patients with given patient names and priority levels
Create a variable called highest_priority to track the highest priority found
Write a loop to find the patient with the highest priority
Print the patient with the highest priority
💡 Why This Matters
🌍 Real World
Priority queues are used in hospitals, task scheduling, and anywhere urgent tasks must be handled first.
💼 Career
Understanding priority queues helps in roles like software development, system design, and operations where task prioritization is key.
Progress0 / 4 steps
1
Create the patient list
Create a list called patients with these exact entries: ("Alice", 2), ("Bob", 5), ("Charlie", 1), ("Diana", 4)
DSA Python
Hint

Use a list of tuples where each tuple has a name and a number for priority.

2
Set up the highest priority variable
Create a variable called highest_priority and set it to 0 to start tracking the highest priority
DSA Python
Hint

Start with 0 because priorities are positive numbers and we want to find the maximum.

3
Find the patient with the highest priority
Use a for loop with variables name and priority to iterate over patients. Inside the loop, update highest_priority if priority is greater than highest_priority. Also, create a variable called top_patient to store the name of the patient with the highest priority.
DSA Python
Hint

Compare each patient's priority to the current highest and update both the highest priority and the top patient name.

4
Print the patient with the highest priority
Write a print statement to display the text: "Patient with highest priority: " followed by the value of top_patient
DSA Python
Hint

Use string concatenation or f-string to combine the message and the patient name.