HEAP TIME COMPLEXITY PYTHON

import heapq
def getMaxUnit(num,boxes,UnitSize,UnitSize,unitPerBox, truckSize):

    if truckSize == 0 or num == 0:
        return 0

    h = []
    for i in range(num):
        h.append((-1*unitPerBox[i],boxes[i]))
    heapq.heapify(h)
    maxCapacity = 0
    while truckSize>=0 and len(h) != 0:
        popped = heapq.heappop(h)
        truckSize = truckSize-popped[1]
        available = popped[1]
        if truckSize < 0:
            available = popped[1]+truckSize
        maxCapacity = maxCapacity + available*(-1*popped[0])
    return maxCapacity


I'm trying to find the time complexity of the code here. I'm confused with what the time complexity of heapq.heappop here as it needs to maintain heap property every time we pop an element.



from Recent Questions - Stack Overflow https://ift.tt/3btu69P
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept