pytudes._2021.utils.heap

https://www.educative.io/courses/grokking-the-coding-interview/3Yj2BmpyEy4

See Also:
  • pytudes/_2021/educative/grokking_the_coding_interview/two_heaps/_1__find_the_median_of_a_number_stream__medium.py

Module Contents

Classes

MaxHeap

MinHeap with negated numbers

MinHeap

heapq-based interface

class pytudes._2021.utils.heap.MaxHeap[source]

Bases: MinHeap

Inheritance diagram of pytudes._2021.utils.heap.MaxHeap

MinHeap with negated numbers

Examples:
>>> heap = MaxHeap()
>>> heap.push(1)
>>> heap.push(2)
>>> heap.push(3)
>>> heap.peek()
3
>>> heap.pop()
3
>>> heap.pop()
2
>>> heap.pop()
1
peek()[source]
Return type:

int

pop()[source]
Return type:

int

push(num)[source]
Parameters:

num (int) –

Return type:

None

class pytudes._2021.utils.heap.MinHeap[source]

heapq-based interface

Examples:
>>> heap = MinHeap()
>>> heap.push(1)
>>> heap.push(2)
>>> heap.push(3)
>>> len(heap)
3
>>> heap.peek()
1
>>> heap.pop()
1
>>> heap.pop()
2
>>> heap.pop()
3
peek()[source]
Return type:

Optional[int]

pop()[source]
Return type:

int

push(num)[source]
Parameters:

num (int) –

Return type:

None