728x90
topological sorting
-
위상 정렬(Topological Sorting)Computer Science/Algorithm 2021. 9. 25. 18:23
위상 정렬이란? ㆍ 순서가 정해져 있는 작업을 차례로 수행해야 할 때 그 순서를 결정해주기 위해 사용하는 알고리즘이다. ㆍ 큐, 스택 자료구조를 이용하여 구현이 가능하다. 위상 정렬의 처리 방식 구현 방법 그래프의 구성 class Graph { class Node { int data; LinkedList adjacentNodes; int indegree; Node(int data) { this.data = data; adjacentNodes = new LinkedList(); this.indegree = 0; } } Node[] nodes; Graph(int size) { nodes = new Node[size]; for (int i = 0; i < size; i++) nodes[i] = new Node..