Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 잘 짜인 코드
- 독립기념일
- 스크래치
- 프로그래밍
- Snap!
- control flow
- 미국
- Operating System
- scheduling policy
- 여행
- The beauty and Joy of computing
- 영어논문
- Scratch
- Jupyter Notebook
- 코딩
- xv6
- 직업으로서의 정치 서평
- list
- concurrency
- 균형의 정치
- Lock
- 7월4일
- 버클리
- Deep Learning
- 운영체제 강의
- CLRS
- 푸드트럭
- Process
- 맛집
- insertion Sort
Archives
- Today
- Total
여행다니는 펭귄
Breadth-First Search 본문
BFS Search Algorithm
def BFS(start):
Set L_i = [] for i = 1,..,n
L_0 = {start}
for i = 0,...,n-1:
for u in L_i:
for each v in u.neighbor:
if v.state = unvisited:
mark v as visited, and put in L_i+1
Running Time은 O(n+m)으로 DFS와 같습니다.
Application - Shortest Path
만약 Weight이 걸려 있지 않는 그래프의 경우 시작점으로부터의 최단 거리를 알 수 있습니다.
Application - Bipratite Graph
Biparatite Graph란 연결된 노드가 모드 Bipartite한 경우입니다.
이 Graph가 만약 Not Bipartite하다면 cycle of odd length를 찾을 수 있습니다.
그래서 BFS로 어떻게 Bipartite를 검증할까요?
아까 Visited Node에는 Coloring을 하지 말라고 했는데 Visited Node지만 Neighbor인 Node에 대해서는 색이 같은지 다른지를 알아봄으로써 이를 검증할 수 있습니다.
'컴퓨터 > CLRS' 카테고리의 다른 글
Depth-first search (0) | 2021.12.12 |
---|---|
Chapter 4. Randomized Algorithms (3) (0) | 2021.10.13 |
Chapter 4. Randomized Algorithms (2) (0) | 2021.10.11 |
Chapter 4. Randomized Algorithms (1) (0) | 2021.10.10 |
Chapter 3. Linear Time Sorting (0) | 2021.10.03 |