Most efficient algorithm to find the biggest square in a two dimension map

前端 未结 5 578
长情又很酷
长情又很酷 2021-02-02 04:03

I would like to know the different algorithms to find the biggest square in a two dimensions map dotted with obstacles.

An example, where o would be obstacl

5条回答
  •  半阙折子戏
    2021-02-02 04:28

    here is an approach using recurrence relation :-

    isSquare(R,C1,C2) = noObstacle(R,C1,R,C2) && noObstacle(R,C2,R-(C2-C1),C2) && isSquare(R-1,C1,C2-1)
    
    isSquare(R,C1,C2) = square that has bottom side (R,C1) to (R,C2) 
    
    noObstacle(R1,C1,R2,C2) = checks whether there is no obstacle in line segment (R1,C1) to (R2,C2)
    
    Find Max (C2-C1+1) which where isSquare(R,C1,C2) = true  
    

    You can use dynamic programming to solve this problem in polynomial time. Use suitable data structure for searching obstacle.

提交回复
热议问题