본문 바로가기

정리하기 이전 자료 ( before 20-11 )21

FloydWarshall 알고리즘 다익스트라 : 하나의 정점으로부터 출발했을 때 다른 모든 정점으로의 최단경로 플로이드 와샬 : 모든 정점에서부터 모든 정점으로의 최단경로 -> 거쳐가는 정점을 기준 import java.util.Scanner; public class Test{ static void floydWarshall(int number,int a[][]){ int d[][] = new int [number][number]; for(int i=0;i 2020. 5. 18.
동적 프로그래밍(Dynamic Programming) static int fibonacci(int n){ if(n==1) return 1; if(n==2) return 1; return fibonacci(n-1) + fibonacci(n-2); } public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); System.out.println(fibonacci(N)); } 피보나치 수열을 다음과 같은 로직으로 짠다면, 시간 복잡도는 2^n 이 나오게 된다. 예를 들어 Index 6의 값을 구한다고 가정해보자. .. 2020. 5. 9.
Stack and Queue Stack Stack stack = new Stack(); stack.add(1); stack.add(2); stack.add(3); stack.pop(); System.out.println(stack.peek()); if(!stack.empty()){ for(int i:stack){ System.out.println(i); } } ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ output: 2 // peek 1 2 add, pop , peek( Top의 값을 보는 method ) Queue Queue queue= new LinkedList(); queue.add(1); queue.add(2); queue.add(3); queue.add(4); queue.remove(); System.out.println(q.. 2020. 5. 8.
Kruskal algorithm Union-find algorithm #include int getParent(int parent[], int x) { if (parent[x] == x) return x; parent[x] = getParent(parent, parent[x]); return parent[x]; } void unionParent(int parent[], int a, int b){ a= getParent(parent,a); b= getParent(parent,b); if(a>b) parent[a]=b; else parent[b]=a; } int findParent(int parent[],int a, int b){ a= getParent(parent,a); b= getParent(parent,b); if(a==b) retu.. 2020. 4. 24.
String.split() 을 이용하여 , 값 받기 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); ArrayList al = new ArrayList(); int number = Integer.parseInt(br.readLine()); for(int i=0;i 2020. 4. 16.
인터페이스의 요소들 다음과 같은 Interface를 만들었다. public interface InterfaceTest { static void printStatic(){ System.out.println("interface static method"); printPrivateStatc(); } default void print(){ System.out.println("interface default method"); printPrivate(); printPrivateStatc(); } private void printPrivate(){ System.out.println("private interface method"); } private static void printPrivateStatc(){ System.out.prin.. 2020. 4. 13.
Naming Conventions 2. Classes naming conventions In Java, class names generally should be nouns, in title-case with the first letter of each separate word capitalized. e.g. public class ArrayList {} public class Employee {} public class Record {} public class Identity {} 클래스의 이름은 명사여야 한다. 3. Interfaces naming conventions In Java, interfaces names, generally, should be adjectives. Interfaces should be in titlecase .. 2020. 4. 6.
인터페이스 모두 Abstract method로 이루어져있다. 인터페이스에 선언한 변수는 모두 상수가 되고, 메서드는 전부 추상 메서드가 된다. public interface Calc{ int a = 3; // public static final int a = 3; int add(int num1,int num2) // abstract int add() } 이 때, int add(int num1,int num2) 을 보면 num1 , num2 를 받아서 두 수를 add 하고 int형으로 돌려줄 것이라는 것을 유추할 수 있다. Interface Vs Abstract class 결론부터 말하자면 인터페이스는 설계도로서의 계약서, 규약('명세(specification' 라고 흔히 말한다)이라고 생각하면 되고, 추상 클래스는.. 2020. 3. 30.