프로그래밍/Algorithm & Structure
19.12.25) Algorithm - Recursive Maze
DevJun
2019. 12. 25. 23:33
출처 : KOCW 부경대학교 권오흠 교수 알고리즘 강의
목차
- 미로찾기 재귀적 사고
- Psudocode
핵심
- 연습! 연습!
미로찾기 재귀적 사고
현재 위치에서 출구까지 가는 경로가 있으려면
- 현재 좌표가 출구거나
- 이웃한 셀들 중 하나에서 현재 위치를 지나지 않고 출구로 가는 방법이 있거나.
Psudocode
boolean findPath(x, y) {
if (x,y) is either on the wall or a visited cell
return false;
else if (x,y) is the exit
return true;
else
mark (x,y) as a visited cell;
for each neighbouring cell (x', y') of (x,y) do
if findPath(x', y')
return true;
return false;
}