Back to course home
0% completed
Vote For New Content
Could you help explain how heapq._siftup(heap, ind)heapq._siftdown(heap, 0, ind)...
chachachoco
Mar 29, 2022
Could you help explain how heapq._siftup(heap, ind) heapq._siftdown(heap, 0, ind) part works ?
6
0
Comments
Comments
D
Dylan Asoh3 years ago
^
Design Gurus3 years ago
_siftup() bubbles the element up keeping the heap property.
This means, for a min heap, _siftup() will start from the given index 'ind' and see if its parent is bigger. If the parent is bigger, it swaps the element at index 'ind' with its parent. Then it repeats this...
On this page