title: The confusion of the index priority queue
body: <p>I have got the idea of the priority queue.But when it comes to  the index priority queue, I'm a little confused with the implemention of some method such as <em>change(int k, Item item)</em> and <em>delete(int i)</em> .</p>
  <blockquote>
  <p>change(int k, Item item) is to change the item associated with k to item</p>
  <p>delete(int i) is to remove k and its associated item</p>
  </blockquote>
  <pre><code>public void changeKey(int i, Key key) {
          if (i &lt; 0 || i &gt;= maxN) throw new IndexOutOfBoundsException();
          if (!contains(i)) throw new NoSuchElementException(&quot;index is not in the priority queue&quot;);
          keys[i] = key;
          swim(qp[i]);
          sink(qp[i]);
      }
  
  public void delete(int i) {
          if (i &lt; 0 || i &gt;= maxN) throw new IndexOutOfBoundsException();
          if (!contains(i)) throw new NoSuchElementException(&quot;index is not in the priority queue&quot;);
          int index = qp[i];
          exch(index, n--);
          swim(index);
          sink(index);
          keys[i] = null;
          qp[i] = -1;
      }
  
  private void swim(int k) {
          while (k &gt; 1 &amp;&amp; greater(k/2, k)) {
              exch(k, k/2);
              k = k/2;
          }
      }
  
      private void sink(int k) {
          while (2*k &lt;= n) {
              int j = 2*k;
              if (j &lt; n &amp;&amp; greater(j, j+1)) j++;
              if (!greater(k, j)) break;
              exch(k, j);
              k = j;
          }
      }
  
  
  private int maxN;        // maximum number of elements on PQ
  private int n;           // number of elements on PQ
  private int[] pq;        // binary heap using 1-based indexing
  private int[] qp;        // inverse of pq - qp[pq[i]] = pq[qp[i]] = i
  private Key[] keys;      // keys[i] = priority of i
  </code></pre>
  <p>I understand the operation of <strong>sink</strong> and <strong>swim</strong>.But why in the method <em>delete(int i)</em> and <em>changeKey(int i,Key key)</em> have the statements <code>swim(qp[i]/index);</code> and <code>sink(qp[i]/index);</code>what on earth happens?</p>
  <p>And I also want to know the elements construction style between priority queue and index priority queue and what is stored in the binary heap on the index priority queue?index or elements?</p>