| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- shiba
- 운영체제
- t1
- 프로그래머스
- 30. Substring with Concatenation of All Words
- data science
- Substring with Concatenation of All Words
- kaggle
- Class
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 밴픽
- 시바견
- DWG
- iterator
- Regular Expression
- Python Code
- concurrency
- Python
- 715. Range Module
- 43. Multiply Strings
- Decorator
- 컴퓨터의 구조
- attribute
- Protocol
- LeetCode
- Convert Sorted List to Binary Search Tree
- Python Implementation
- Generator
Archives
- Today
- Total
Scribbling
위상 정렬 본문
위상 정렬: 방향 그래프의 모든 노드를 '방향성에 거스르지 않도록' 순서대로 나열하는 알고리즘
def topology_sort():
result = []
q = deque()
"""
진입 차수가 0인 node를 queue에 삽입
"""
for i in range(1, v+1):
if indegree_list[i] == 0:
q.append(i)
while q:
now = q.popleft()
result.append(now)
"""
queue에서 꺼낸 node와 연결된 모든 node 간의 간선을 제거 후
진입 차수가 0인 node를 queue에 삽입
"""
for nxt in graph[now]:
indegree_list[nxt] -= 1
if indegree_list[nxt] == 0:
q.append(nxt)
print(result)'Computer Science > Algorithms & Data Structures' 카테고리의 다른 글
| Priority Queue (0) | 2021.12.22 |
|---|---|
| KMP 문자열 검색 알고리즘 (0) | 2021.08.29 |
| 신장 트리, 최소 신장 트리, Kruskal Algorithm (0) | 2021.08.13 |
| 무향/방향 그래프 내 Cycle 판별 (0) | 2021.08.12 |
| 서로소 집합 알고리즘 (0) | 2021.08.12 |