title: Building a Python implementation of min heap
body: <p>What is wrong with the below code to buld a min heap? The bubble_up method doesn't work it gets an index out of range error.</p>
  
  <pre><code> def __init__(self):
      self.heap = []
      self.heap_size = 0
  
   def bubble_up(self, i):
      print(self.heap)
      while i // 2 &gt; 0:
          if self.heap[i] &lt; self.heap[i // 2]:
              tmp = self.heap[i // 2 - 1]
              self.heap[i] = self.heap[i // 2]
              self.heap[i // 2] = tmp
          print(self.heap)
          i = i // 2
  
  
  def insert(self, data):
      self.heap.append(data)
      self.heap_size = self.heap_size + 1
      self.bubble_up(self.heap_size)
  
  if __name__ == "__main__":
      min_heap = MinHeap()
      min_heap.insert(5)
      min_heap.insert(4)
      min_heap.insert(3)
      min_heap.insert(2)
      min_heap.insert(6)
  </code></pre>