• Post Reply Bookmark Topic Watch Topic
  • New Topic

Popping from an overfilled MaxHeap. keep getting ArrayIndexOutOfBoundsException error  RSS feed

 
Stan Austin
Ranch Hand
Posts: 50
1
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tasked to find the (K) largests numbers in an array of 50 million integers, the number range from 1-10 digits in length (0- 9,999,999,999)
there is a constraint to not use more than 500 Kilobytes of memory and identify the top 5000 numbers in under 1.75 seconds.
looking at performance programming i found that the best approach is to convert the array into a maxheap size (K) and as it is filled with ever larger number the smaller ones pop themselves out.
I got the max heap working so when I store the whole array in the heap i can find the top K numbers.

here is what I have so far;

Error message from cmd line:

Any help greatly appreciated. Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Starting backwards from your stacktrace...
Stan Austin wrote:


This line ...

says that the main() method will call a method at line 82 of the TestClass.java file.... which leads to this line...

which says that the extractMin() method, that was called from main() method will do an operation at line 41 of the TestClass.java file... that triggers this...

This is an array out of bounds index.... specifically, the code is trying to access the element at index -1. And since Java doesn't support negative indexes, it is clear why this is an error.  Anyway, going to line 41 of the TestClass.java file, you get this...

... and ... from this line, it is quite clear where the issue is. There are two array dereferences, but one of them is clearly index zero. The other is dependent on the position variable... and...

If you print out the position variable, I will easily bet that the value of the position at this point is zero...

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!