Skip to content

Commit

Permalink
Update tarjans_scc.py
Browse files Browse the repository at this point in the history
  • Loading branch information
parkgwanjong committed Dec 6, 2018
1 parent 173cf95 commit f20f99e
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions graphs/tarjans_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

def tarjan(g):
"""
Tarjan's algo for finding strongly connected components in a directed graph
유향 그래프에서 강하게 연결된 구성 요소를 찾는 데 필요한 Tarjan의 알고리즘
Uses two main attributes of each node to track reachability, the index of that node within a component(index),
and the lowest index reachable from that node(lowlink).
     도달 가능성, 구성 요소 내의 해당 노드 색인 (색인) 및
해당 노드에서 도달 할 수있는 가장 낮은 색인 (하위 링크)을
추적하기 위해 각 노드의 두 가지 주요 속성을 사용합니다.
We then perform a dfs of the each component making sure to update these parameters for each node and saving the
nodes we visit on the way.
     그런 다음 각 구성 요소의 dfs를 수행하여 각 노드에 대해
이러한 매개 변수를 업데이트하고 방문하는 노드를 저장합니다.
If ever we find that the lowest reachable node from a current node is equal to the index of the current node then it
must be the root of a strongly connected component and so we save it and it's equireachable vertices as a strongly
connected component.
     현재 노드에서 도달 할 수있는 가장 낮은 노드가 현재 노드의
인덱스와 같은 경우 강하게 연결된 구성 요소의 루트 여야하며
저장하기 때문에 강하게 연결된 구성 요소로 도달 가능한 정점을 얻습니다.
Complexity: strong_connect() is called at most once for each node and has a complexity of O(|E|) as it is DFS.
Therefore this has complexity O(|V| + |E|) for a graph G = (V, E)
     복잡성 : strong_connect ()는 각 노드에 대해
한 번만 호출되며 DFS이므로 O (| E |)의 복잡성이 있습니다.
따라서 이것은 그래프 G = (V, E)에 대한 복잡도 O (| V | + | E |)를 갖습니다.
"""

Expand All @@ -27,8 +30,8 @@ def tarjan(g):
lowlink_of = index_of[:]

def strong_connect(v, index, components):
index_of[v] = index # the number when this node is seen
lowlink_of[v] = index # lowest rank node reachable from here
index_of[v] = index #이 노드를 볼 때 번호
lowlink_of[v] = index # 여기에서 도달 할 수있는 최저 등급 노드
index += 1
stack.append(v)
on_stack[v] = True
Expand Down Expand Up @@ -68,7 +71,7 @@ def create_graph(n, edges):


if __name__ == '__main__':
# Test
# 테스트
n_vertices = 7
source = [0, 0, 1, 2, 3, 3, 4, 4, 6]
target = [1, 3, 2, 0, 1, 4, 5, 6, 5]
Expand Down

0 comments on commit f20f99e

Please sign in to comment.