title: Java : How to print heap stored as array, level by level
body: <p>I have an array that represents a Max Heap. For example</p>
  
  <pre><code>84 81 41 79 17 38 33 15 61 6
  </code></pre>
  
  <p>so the root is max. Each mid tier node at index i can have at most two children. They would be at 2*i+1 and 2*i+2.</p>
  
  <p>How can i print this heap out in a level by level fashion? like</p>
  
  <pre><code>                             84(0)
  
                   81(1)                  41(2)
  
              79(3)        17(4)     38(5)       33(6) 
  
         15(7)    61(8)         6(9)
  </code></pre>
  
  <p>the index of each element in the array is shown in paranthesis for clarification. i dont have to print the index. I was thinking it would be similar to printing a BST in level order but here, the heap is stored in an array not a list which makes it a bit tricky!</p>