algorithms-BFS&DFS-start.md

🏑

BFS & DFS : Triversal technique

1. BFS, Breadth First Search

| good | shortest path, closer nodes | | ---- | --------------------------- | | bad | more memory |

2. DFS, Depth for Search

| good | less memory, does path exist | | ---- | ---------------------------- | | bad | can get slow |

BFS vs DFS

| | BFS | DFS | | -------------- | --------------------------- | -------------------------- | | 상황 | μ΅œλ‹¨ 경둜, κ°€μž₯ κ°€κΉŒμš΄ λ…Έλ“œ | 길이 μ‘΄μž¬ν•˜λŠ”μ§€ μ—¬λΆ€ | | κ΅¬ν˜„ 방식 | 큐(queue) | μŠ€νƒ(stack) λ˜λŠ” μž¬κ·€ ν•¨μˆ˜ | | 탐색 μˆœμ„œ | λ„ˆλΉ„ μš°μ„  | 깊이 μš°μ„  | | 탐색 λ°©ν–₯ | μˆ˜ν‰ | 수직 | | μ΅œλ‹¨ 경둜 탐색 | κ°€λŠ₯ | λΆˆκ°€λŠ₯ | | 곡간 λ³΅μž‘λ„ | O(V) (V: λ…Έλ“œ 수) | O(V) (V: λ…Έλ“œ 수) | | μ‹œκ°„ λ³΅μž‘λ„ | O(V + E) (E: κ°„μ„  수) | O(V + E) (E: κ°„μ„  수) |

Quiz

| quiz | reply | answer | explain | | ------------------------------------------------------------ | ----- | ------ | ------------------------------------------- | | If you know a solution is not far from the root of the tree. | BFS | BFS | | | If the tree is very deep and solutions are rare. | DFS | BFS | DFS will take long if the tree is very deep | | If the tree is very wide. | BFS | DFS | BFS will need too much memory | | If solutions are frequent but located deep in the tree. | DFS | DFS | | | determining whether a path exists between two roads. | DFS | DFS | | | Finding the shortest path. | BFS | BFS | |


NextPage