DFS vs BFS

FrugalBoy
2025.02.04조회수 4회

FrugalBoy
구독자 5명구독중 12명
Wanna live like a frugal boy
For the genetically superior, success is easier to attain.
But it is by no means guaranteed.
After all, there is no gene for fate
-Gattaca-


특정 문제들은 bfs로 풀때 TLE로 안풀린다
내가 생각한 이유:
bfs는 2d matrix에서 4방향을 검색하면서 나아간다
하지만
dfs의 경우 특정조건을 만족하는 경우로 한방향을 빠르게 골라 직선형태로 이리저리 빠르게 나아간다
둘의 움직임 볼수 있는 사이트
https://sjunhong.github.io/algorithm-visualizer/
따라서 데이터가 많을때 bfs에서 TLE가 나오는게 dfs에서 나오지 않을때가 있음
아래 2문제는 bfs로 풀면 tle나오는 유형들임
https://leetcode.com/problems/count-sub-islands/description/
https://leetcode.com/problems/word-search/description/