일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 30. Substring with Concatenation of All Words
- 시바견
- Decorator
- data science
- 파이썬
- Python Code
- LeetCode
- Generator
- Regular Expression
- Class
- 715. Range Module
- iterator
- 109. Convert Sorted List to Binary Search Tree
- shiba
- Protocol
- Substring with Concatenation of All Words
- Python Implementation
- attribute
- Python
- Convert Sorted List to Binary Search Tree
- t1
- kaggle
- 밴픽
- DWG
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- 43. Multiply Strings
- 컴퓨터의 구조
- concurrency
- 운영체제
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 |