본문 바로가기

ALGORITHMS/BFS vs DFS

when to BFS vs DFS

BFS

- 최단경로/미로찾기 --> 거리 구할때 GRAPH[nx][ny] = GRAPH[x][y] + 1 업데이트 --> return GRAPH[N-1][M-1] inside WHILE loop 

- BFS로 모든 노드 방문하는 법 --> nested for loop and call BFS()

Good time complexity but bad space complexity

DFS

- 완전탐색 (Brute Force Search All)

- 조합/순열 --> 모든 경우의 수 [모든 노드 방문] 

- BACKTRACKING (with some condition)

- Good space complexity but bad time complexity (recursion & must visit all nodes)

'ALGORITHMS > BFS vs DFS' 카테고리의 다른 글

BFS vs DFS [adj. matrix]  (0) 2022.06.19
BFS vs DFS [adj. list]  (0) 2022.06.19