SO i have written the following main function in java to compute editdistancee of 1000 random generated pairs of length 10, 20, 50 and 100. It is running fine for the lengths 10 n 20 but for length 50 it is giving this error. "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space". I am confused what to do. any help would be appreciated.
for (j=0; j< numoftimes; j++) {
for (int i = 0; i < len2; i++) {
s5r += (char) ( 'a' + r.nextInt(26));
s6r += (char) ( 'a' + r.nextInt(26));
}
starttime2 = System.nanoTime();
int distance2 = editDistance(s5r,s6r);
endtime2 = System.nanoTime() - starttime2;
}
avg_CPUtime2 = (endtime2/numoftimes);
System.out.println("Average CPU time in nanoseconds for 1000
pair of random words of length "+len2+" : "+avg_CPUtime2);
int len3 = 100;
long starttime3 = 0;
long endtime3 = 0;
long avg_CPUtime3 = 0;
String s7r = "";
String s8r = "";
for (j=0; j< numoftimes; j++) {
for (int i = 0; i < len3; i++) {
s7r += (char) ( 'a' + r.nextInt(26));
s8r += (char) ( 'a' + r.nextInt(26));
}
starttime3 = System.nanoTime();
int distance3 = editDistance(s7r,s8r);
endtime3 = System.nanoTime() - starttime3;
}
avg_CPUtime3 = (endtime3/numoftimes);
System.out.println("Average CPU time in nanoseconds for 1000
pair of random words of length "+len3+" : "+avg_CPUtime3);
the out is this
Average CPU time in nanoseconds for 1000 pair of random words of length 10 :
674163
Average CPU time in nanoseconds for 1000 pair of random words of length 20
: 3128792
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at algorithmDesign.Sequences.editDistance(Sequences.java:12)
at algorithmDesign.Sequences.main(Sequences.java:116)