This largely uses the collections module
Interested submodules are deque
This largely uses the collections module
Interested submodules are defaultdict
and ordereddict
This largely uses the heapq module
Documenation can be referenced from: here.
Note: heapq module would implement a min heap by default!
Easy Solution whilst retaining the same functions would be to multiply the elements of the heap by -1 !
Heapify Operation
Time Complexity: O(N)
import heapq as hq
list_stu = [(5,'Rina'),(1,'Anish'),(3,'Moana'),(2,'cathy'),(4,'Lucy')]
hq.heapify(list_stu)
It is noted that we would have to include tuples with the first element of the tuple representing the priority.
Heap Insert Time Complexity: O(logN)
hq.heappush(heap, newTuple)
Heap Removal Time Complexity: O(logN)
hq.heappop()