Skip to main content

PriorityQueue

PriorityQueue is an implementation of the binary heap data structure

Usage

UFDS(self, arr:list = None, comparator:Callable = lambda x, y: x >= y)

Parameters:
      arr : list or None
            if None, an empty binary heap is created else. list should contain the elements to be included into the heap
      comparator : Callable
            A lambda function to relatively order the items in the heap

Methods

MethodDescription
peekTake a look at the root node of the heap
extractReturns and remove the root node of the heap
sortReturns a sorted list according to the rules of the comparator
is_emptyChecks if the binary heap is empty
searchCheck if an item is present in the heap
updateReplace an item in the binary heap

Example

from jellybeans.structures import PriorityQueue as PQpq = PQ([None, 1, 2, 3, 4 ,5]) # Default is maxheapprint(pq) # [None, 5, 4, 3, 1, 2] (One indexed implementation)