In Java Software Structures 3rd Edition by Lewis and Chase the array implementation of a heap works for small numbers of items, but in cases with a large number of items sometimes throws a ArrayIndexOutOfBoundsException. It occurs in line 113 of the method heapifyRemove() in ArrayHeap (which extends ArrayBinaryTree).
Line 113:
if ((tree[left] == null) && (tree[right] == null))
It seems that left sometimes walks off the end of the array. How could this be fixed?
For reference: