
MST,MCST (Minimun_Cost Spanning Tree) (์ต์๋น์ฉ ์ ์ฅํธ๋ฆฌ) Spanning Tree : undirected graph์์ n๊ฐ์ ๋ชจ๋ ์ ์ ๊ณผ n-1๊ฐ์ ๊ฐ์ ์ผ๋ก ๋ง๋ค์ด์ง ํธ๋ฆฌ ์ํ(traversal)๋ฅผ ํ๋ฉด n-1๊ฐ์ ๊ฐ์ ์ ์ด๋ํ๋ฉฐ ๋ชจ๋ ์ ์ ์ ๋ฐฉ๋ฌธํ๋ฏ๋ก spanning tree๋ฅผ ์์ฑํ๋ค. DFS๋ก ์์ฑ๋๋ฉด DFST(Depth First Spanning Tree, ๊น์ด์ฐ์ ์ ์ฅํธ๋ฆฌ), BFS๋ก ์์ฑ๋๋ฉด BFST(Breadth First Spanning Tree, ๋๋น์ฐ์ ์ ์ฅํธ๋ฆฌ)๋ผ๊ณ ํ๋ค. weighted undirected graph์์ ๋ชจ๋ ๋ ธ๋๋ฅผ ํฌํจํ๊ณ cycle์ด ์์ผ๋ฉฐ weight์ ํฉ์ด ์ต์์ธ ํธ๋ฆฌ๋ฅผ MST or MCST(Minimum Cost Spannin..

DFS (Depth First Search) (๊น์ด ์ฐ์ ํ์) LIFO(Last-In First-Out), Stack ํ์ฉ PseudoCode recursive non-recursive 1 non-recursive 2 ์์ Input Output ์ฒซ ์ค์ ์ ์ ์ ๊ฐ์ N๊ณผ ๊ฐ์ ์ ๊ฐ์ M์ด ์ฃผ์ด์ง๋๋ค. ๋ค์ M์ค์ ๊ฐ์ ์ ๊ด๊ณ ์์์ ์ u์ ๋์ฐฉ์ ์ v๊ฐ ์ฃผ์ด์ง๋๋ค. ์ ๋ ฅ์ ๋ฐ๋ฅธ ๊น์ด ์ฐ์ ํ์ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํฉ๋๋ค. import java.util.*; public class Test { static boolean edge[][]; static boolean visited[]; static int n; static int m; public static void main(String args[]) { Sca..

Two Pointer 2๊ฐ์ ์ง์ (ํฌ์ธํฐ)์ ์ฎ๊ฒจ๊ฐ๋ฉฐ ๋ต์ ๊ตฌํ๋ค. ์์ฐจ์ ์ ๊ทผ ๋ฑ์ด ์๊ตฌ๋๋ ํน์ํ ์ํฉ์์ ์ฌ์ฉ๋๋ค. ex) ์ ๋ ฌ๋ ๋ ๋ฐฐ์ด์ ํ๋์ ์ ๋ ฌ๋ ๋ฐฐ์ด๋ก ํฉ์น ๋(Merge Sort์์ ์ฌ์ฉ๋จ), ์ด๋ค ๋ฐฐ์ด์ ์ฐ์ ๋ถ๋ถ์งํฉ์ ์์ํฉ์ด k์ธ ๊ฒฝ์ฐ๋ฅผ ์ฐพ๋ ๊ฒฝ์ฐ ๋ฑ ... ์์ธํ ๋ด์ฉ์ Merge Sort ๋ถ๋ถ ์ฐธ๊ณ Sliding Window Two pointer์ ๋น์ทํ์ง๋ง, ๋ ํฌ์ธํฐ ์ฌ์ด์ ๊ธธ์ด๊ฐ ๊ณ ์ ๋์ด์๋ค๋ ์ฐจ์ด๊ฐ ์๋ค. Input Output ์ฒซ ๋ฒ์งธ ์ค์๋ ๋ฐฐ์ด D์ ์์์ ๊ฐ์ N๊ณผ ์๋์ฐ ์ฌ์ด์ฆ K ๊ฐ ์ฃผ์ด์ง๊ณ , ๋ ๋ฒ์งธ ์ค์๋ ๋ฐฐ์ด์ ์์ Di๊ฐ ์ฃผ์ด์ง๋๋ค. (Di ๋ ์์ฐ์) ๋ฐฐ์ด D์ ๊ธธ์ด๊ฐ K์ธ ์ฐ์๋ถ๋ถ์งํฉ์ ์์ ํฉ์ ์ต๋๊ฐ์ ์ถ๋ ฅํฉ๋๋ค. import java.util...

Shell Sort (์ ธ ์ ๋ ฌ) https://gmlwjd9405.github.io/2018/05/08/algorithm-shell-sort.html ์ผ์ ๊ฐ๊ฒฉ์ผ๋ก ๋ถ๋ถ์งํฉ์ ๊ตฌ์ฑํ๊ณ , ๊ฐ ๋ถ๋ถ์งํฉ์ ๋ํด ์ฝ์ ์ ๋ ฌ์ ์ํ. ๊ฐ๊ฒฉ์ ์ค์ฌ๊ฐ๋ฉฐ ๋ฐ๋ณต. ๋ถ๋ถ์งํฉ์ ๋ง๋๋ ๊ธฐ์ค์ด ๋๋ ๊ฐ๊ฒฉ ๊ฐ์ ๋ฐ๋ผ ์ฑ๋ฅ ์ข์ฐ ์ผ๋ฐ์ ์ผ๋ก ์๊ฐ ๋ณต์ก๋๋ O(n1.25~1.5)๋ก ์ธก์ ์ฝ์ ์ ๋ ฌ๋ณด๋ค๋ ๊ฐ์ ๋ ๋ฐฉ๋ฒ import java.lang.Math; import java.util.Scanner;; public class Test { public static void printArray(int[] arr) { for(int i=0; i

Quick Sort (ํต ์ ๋ ฌ) ๊ธฐ์ค๊ฐ(pivot)์ ์ก๊ณ , pivot๋ณด๋ค ์์์๋ ์ขpartition์ผ๋ก ํฐ์๋ ์ฐpartition์ผ๋ก ๋ณด๋ธ๋ค. ๋ค์ ์ข/์ฐpartition์์ ๊ฐ๊ฐ pivot์ ์ค์ ํ๊ณ ์ข/์ฐpartition์ผ๋ก ๋๋๋ค. ์ด๋ฌํ ๊ณผ์ ๋ฐ๋ณต divide & conquer pivot์ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ด ๋ค์ํ๊ณ , ์ด์ ๋ฐ๋ผ ์ฑ๋ฅ์ด ๊ฒฐ์ ๋๋ค. (pivot์ ์ข์ฐ๋๊ฐ ๋๋ ์ค์๊ฐ์ผ๋ก ๋ฑ๋ฑ..) ํ๊ท ์๊ฐ ๋ณต์ก๋ : O(nlog2n) ์ต์ ์๊ฐ ๋ณต์ก๋ : O(n2) ๊ตฌํ๋ฐฉ๋ฒ์ด ์ ๊ฐ๊ฐ, ๋ค์ํ๋ค import java.lang.Math; import java.util.Scanner;; public class Test { public static void printArray(int[] arr) { f..

Selection Sort (์ ํ ์ ๋ ฌ) 0๋ฒ์งธ ์๋ฆฌ์ '1๋ฒ์งธ-N-1๋ฒ์งธ ์ค์์ ๊ฐ์ฅ ์์ ๊ฐ'์ ๊ตํ, 1๋ฒ์งธ ์๋ฆฌ์ '2๋ฒ์งธ-N-1๋ฒ์งธ ์ค์์ ๊ฐ์ฅ ์์ ๊ฐ'์ ๊ตํ, ... ํ๊ท /์ต์ ์๊ฐ ๋ณต์ก๋ : O(n2) import java.lang.Math; import java.util.Scanner;; public class Test { public static void printArray(int[] arr) { for(int i=0; i

Sieve of of Eratosthenes (์๋ผํ ์คํ ๋ค์ค์ ์ฒด) ์์ํ๋ณ ์๊ณ ๋ฆฌ์ฆ ํ์ํ ๋ฒ์์ ๋ฐฐ์ด ์์ฑํ, 2๋ถํฐ ์์ํด์ ์ฐจ๋ก๋๋ก ๋ฐฐ์๋ค์ ์์๊ฐ ์๋๊ฒ์ผ๋ก ์ฒดํฌ ์ต์ ํ ์ฒซ๋ฒ์งธ ๋ฐ๋ณต๋ฌธ์ ๋ฒ์๋ฅผ 1-N์ด ์๋ 1-sqrt(N)์ผ๋ก ๋ฐ๊ฟ ์๋ ํฅ์ ๊ฐ๋ฅ. A์ ์ฝ์๋ฅผ ๊ตฌํ ๋ 1-sqrt(A)๊น์ง๋ง ๊ตฌํ๋ฉด ๋๋๊ฒ์ ์๋ช ํ๋ค. ํด๋น๋ฒ์๋ด์์ N๋ฒ์งธ ์์๋ฅผ ๊ตฌํ๋ ๊ฒฝ์ฐ๋ผ๋ฉด, 1-N๊น์ง ๋ชจ๋ ๋๋ ค์ผํ๊ฒ ์ง๋ง ํด๋น๋ฒ์๋ด์์ ํน์ ์ซ์ N์ด ์์์ธ์ง ํ๋ณํ๋ ๊ฒฝ์ฐ๋ผ๋ฉด, 1-sqrt(N)์ผ๋ก ์ต์ ํ ๊ฐ๋ฅ. import java.lang.Math; import java.util.Scanner;; public class Test { private final static int MAX = 50; static boolea..
- Total
- Today
- Yesterday
- reversing
- Stack
- sort
- webhacking.kr
- dfs
- socket
- bfs
- ํ๋ก๊ทธ๋๋จธ์ค
- mysql
- ๋ฆฌ๋ฒ์ฑ
- Android
- ์ฐ์ํ ํ ํฌ์ฝ์ค
- OneToMany
- Vo
- ๊ฐ๋ฐ์
- ์นํดํน
- FRAGMENT
- Data Structure
- Algorithm
- Android Studio
- javascript
- JPA
- brute-force
- queue
- ํด์ธ์ฌํ
- ํ๊ณ
- graph
- C
- git
- Java
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |