알고리즘
-
DFS(깊이 우선 탐색)Computer Science/Algorithm 2021. 9. 25. 10:57
DFS란? ㆍ DFS는 깊이 우선 탐색으로 그래프의 탐색 방법 중 하나이다. ㆍ 갈 수 있는 만큼 최대한 깊이 가고, 더 이상 갈 곳이 없다면 이전 정점으로 돌아가는 방식으로 그래프를 순회하는 방식이다. ㆍ 스택 자료구조를 통해 구현할 수 있다. DFS의 그래프 순회 방식 구현 방법 그래프의 구성 class Graph { class Node { int data; LinkedList adjacentNodes; boolean marked; Node(int data) { this.data = data; adjacentNodes = new LinkedList(); this.marked = false; } } Node[] nodes; Graph(int size) { nodes = new Node[size]; fo..
-
다양한 정렬 알고리즘Computer Science/Algorithm 2021. 9. 25. 10:47
정렬 알고리즘의 종류 ㆍ 선택 정렬 ㆍ 삽입 정렬 ㆍ 쉘 정렬 ㆍ 계수 정렬 ㆍ 기수 정렬 ㆍ 병합 정렬 (Top-Down) ㆍ 병합 정렬 (Bottom-Up) 구현 방법 추상 클래스 public abstract class AbstractSort { public static void sort(Comparable[] a) { }; /** compare the size of two elements */ protected static boolean less(Comparable v, Comparable w) { return v.compareTo(w) < 0; } /** change two elements */ protected static void exch(Comparable[] a, int i, int j) ..