• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Popping from an overfilled MaxHeap. keep getting ArrayIndexOutOfBoundsException error

 
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic