Things I learned today was brushing up my skills on leetcode and shared my learned could help someone who is on the same journey as me
Heap – Heap is the complete binary.
Max heap – Root is the max element in the entire tree
Min heap – Root is the min element in the entire tree
I am sure many people might be familiar with it, but here are some additional tips which I found intriguing while revising the concepts wanted to share it as it might help during interview
Python inbuild function in heap and cost incur-

  1. Which to use directly depends on size of k
    • heapify( )– O(n log n -klogk)
    • heappush() – O(n log k)
    • if k is small, heappush is better. If k =~ n heapify is better.
  2. heappop() – is better when adding/multiple etc
    Heapification during initialization
    • Perceived: O(log N) time , O(log N) space
    • Actual: O(log N) time and O(N) space
Comments (0)