Stackoverflowerror on Breath Search algorithm

hey ppl, i need an algorithm that can detect the best path to get in an array from a to b. however,shortest path is not what i need,since there might be a path that goes backwards.anyway i wanted to test the complexity of the algorithm first, and i got an error. however, i don't know if it can be solved in a way. if i reduce the size of the array by half, it works.

thnx 4 replys in advance

publicclass CriticalPath

{

Spot[][] grid =new Spot[128][96];

publicstaticvoid main(String[] args)

{

CriticalPath cp =new CriticalPath();

cp.makeGrid();

cp.determineBestPath(0,0,62,46);

}

publicvoid makeGrid()

{

for(int i=0;i<grid.length;i++)

{

for(int j=0;j<grid[i].length;j++)

{

grid[i][j] =new Spot(i,j);

}

}

}

publicvoid determineBestPath(int x,int y,int eindX,int eindY)

{

if((x==eindX)&&(y==eindY))

{

System.out.println("Ik ben er!");

}

else

{

grid[x][y].setFree(false);

if((x>0&&y>0)&&(grid[x-1][y-1].getFree()))

{

determineBestPath(x-1,y-1,eindX,eindY);

}

if((y>0)&&grid[x][y-1].getFree())

{

determineBestPath(x,y-1,eindX,eindY);

}

if((x<grid.length-1)&&(y>0)&&grid[x+1][y-1].getFree())

{

determineBestPath(x+1,y-1,eindX,eindY);

}

if((x>0)&&grid[x-1][y].getFree())

{

determineBestPath(x-1,y,eindX,eindY);

}

if((x<grid.length-1)&&grid[x+1][y].getFree())

{

determineBestPath(x+1,y,eindX,eindY);

}

if((x>0)&&(y<grid[x].length-1)&&grid[x-1][y+1].getFree())

{

determineBestPath(x-1,y+1,eindX,eindY);

}

if((y><grid[x].length-1)&&grid[x][y+1].getFree())

{

determineBestPath(x,y+1,eindX,eindY);

}

if(((x><grid.length-1)&&(y><grid[x].length-1))&&grid[x+1][y+1].getFree())

{

determineBestPath(x+1,y+1,eindX,eindY);

}

}

}

>

[4024 byte] By [hawkeye9393a] at [2007-10-1 9:13:02]
# 1
i ran a println alongside it, and the error occurs on the 3605 time the method gets run-xxx-&greetz
hawkeye9393a at 2007-7-10 1:37:38 > top of Java-index,Other Topics,Algorithms...
# 2

public class Spot

{

int x,y;

boolean free;

public Spot()

{

free = true;

}

public Spot(int x,int y)

{

free = true;

this.x=x;

this.y=y;

}

public Spot(int x,int y,boolean free)

{

this.x=x;

this.y=y;

this.free=free;

}

public void setFree()

{

free = true;

}

public void setFree(boolean free)

{

this.free = free;

}

public boolean getFree()

{

return free;

}

public int getX()

{

return x;

}

public int getY()

{

return y;

}

}

this is the class Spot,srry forgot to join it in the 1st post

hawkeye9393a at 2007-7-10 1:37:38 > top of Java-index,Other Topics,Algorithms...
# 3
Which error did you get? Please provide Error Stack printout.I guess it is OutOfMemoryException, however. In that case, just run your program with the -Xmx option to increase available memory.java -Xmx700m ... (Will give you 700 MB available memory)Gil
gilroittoa at 2007-7-10 1:37:38 > top of Java-index,Other Topics,Algorithms...