Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 3: Priority Queue Requires: knowing how to implement a class . understanding inheritance In the greedy scheduling algorithm, you will need to consider the
Task 3: Priority Queue Requires: knowing how to implement a class . understanding inheritance In the greedy scheduling algorithm, you will need to consider the parcels one at a time. While we could use a Python list, it has no efficient way to give us items in order according to our priority (e.g. by volume in non-decreasing order). Instead we will use something called a Priority Queue. Like a list, it is also a kind of container that allows you to add and remove items. However, a priority queue removes items in a very specific order: it always removes the item with the highest "priority". If there is a tie for highest priority, it chooses among the tied items the one that was inserted first. (See the docstrings in class PriorityQueue for examples.) A priority queue can prioritize its entries in different ways. For example, we might want to make a priority queue of strings in which shorter have higher priority. Or we want to make a priority queue of employees in which employees with the least seniority have highest priority. Our PriorityQueue class lets client code define what the priority is to be by passing to the initializer a function that can compare two items. Cool! See section 1.4 of the Lecture Notes for information about the type annotation Callable, which is used in that class. A Priority Queue supports the following actions: determine whether the priority queue is empty insert an item with a given priority remove the item with the highest priority File container.py contains the general Container class, as well as a partially- complete PriorityQueue class. PriorityQueue is a child class of Container. You must complete the add() method according to its docstring. It is just one method, but you will have to read carefully and think clearly to complete it. (Notice that we're using a sorted list to implement this class; in later courses, you'll learn about a much more efficient implementation called heaps.) This module contains the Container and PriorityQueue classes. from typing import Any, List, Callable class Container: "A container that holds Objects, This is an abstract class. Only child classes should be instantiated. def add(self, item: Any) -> None: "Add
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started