algorithm - complexity of brute force array traversal -
if have 4x4 grid example , want start @ arbitrary cell (i,j) , want travel down every path without crossing on over myself, complexity (big o) of this? have written following code:
traverse(int[][]grid, int i, int j, boolean[][] visited){ for(int x = -1; x<=1; x++){ for(int y=-1; y<=1; y++){ if(inbounds(grid, i+x, j+y), !visited[i+x][j+y]){ traverse(grid, i+x, j+y, copyofandset(visited, i+x, j+y)); } } } }
assume inbounds exists , copyofandset exists , o(1) (not o(n*n)) have implemented bitwise operations clarity have used array of booleans here.
what running time of algorithm above on nxn grid.
thanks
if understand question, want enumerate self avoiding walks on 2d grid. (you said "travel down every path without crossing on over myself")
you can find several papers googling these keywords.
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.8.5913
the problem seems #p-complete, according paper.
Comments
Post a Comment