DFS (Depth-First Search) 깊이 우선 탐색
인접 행렬 (Adjacency Matrix) : 2차원 배열로 그래프 연결 관계 표현
인접 리스트 (Adjacency List) : 리스트로 그래프의 연결 관계 표현
# 인접 행렬
INF = 999999999
graph = [
[0, 7, 5],
[7, 0, INF],
[5, INF, 0]
]
# 인접 리스트
graph = [[] for _ in range(3)]
# node 0
graph[0].append((1,7))
graph[0].append((2,5))
# node 1
graph[1].append((0,7))
# node 2
graph[2].append((0,5))
'알고리즘 > Python' 카테고리의 다른 글
Python 연산자 (0) | 2020.09.07 |
---|