title: What's the time complexity of functions in heapq library
body: <p>My question is from the solution in leetcode below, I can't understand why it is <code>O(k+(n-k)log(k))</code>.</p>
  
  <p>Supplement: Maybe the complexity isn't that, in fact I don't know the time complexity of <code>heappush()</code> and <code>heappop()</code></p>
  
  <pre><code># O(k+(n-k)lgk) time, min-heap
  def findKthLargest(self, nums, k):
      heap = []
      for num in nums:
          heapq.heappush(heap, num)
      for _ in xrange(len(nums)-k):
          heapq.heappop(heap)
      return heapq.heappop(heap)
  </code></pre>