title: MinHeap Delete Understanding
body: <p>I am having difficulty in understanding the solutions of one of the problems my professor gave me regarding heaps. </p>
  
  <blockquote>
    <p>Give pseudocode for the routine Min-Heap-Delete(A, k). Assume that key k is at location l
    of the heap and that 1 ≤ l ≤ n.</p>
  </blockquote>
  
  <p>My solution is that </p>
  
  <blockquote>
    <p><strong>Exchange A[k] with A[A.size() - 1]</strong></p>
    
    <p>A.size() = A.size() - 1</p>
    
    <p>Min-heapify(A,k)</p>
  </blockquote>
  
  <p>However, my solution has a difference with the professor's in the first part.</p>
  
  <blockquote>
    <blockquote>
      <p><strong>Exchange A[k] with A[A.heap_size()]</strong></p>
      
      <p>A.heap_size() = A.heap_size() - 1</p>
    </blockquote>
    
    <p>Min-heapify(A,k)</p>
  </blockquote>
  
  <p>Why would we use A.size() instead of A.size() - 1? Wouldn't A.size() over index the array that represent the heap since heap starts at index 1?</p>
  
  <p><a href="https://i.stack.imgur.com/gnADM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gnADM.png" alt="enter image description here"></a></p>
  
  <p>In this case, A.size() would give us 10. However, A[10] doesn't exist and would cause an error. Therefore, why isn't it A[10-1] to obtain the last node in the heap tree? </p>