전체 글 606

[Spring Data JPA] 3-1. Defining Query Methods (2)

4. Repository Methods Returning Collections or IterablesStreamable스트림을 제공하는 인터페이스Iterable을 확장스트림을 비병렬로 처리할 수 있게 함. (filter(), map() 등의 스트림 메서드 사용 가능)예제더보기interface PersonRepository extends Repository { Streamable findByFirstnameContaining(String firstname); Streamable findByLastnameContaining(String lastname);}Streamable result = repository .findByFirstnameContaining("av") .and(repos..

[Spring Data JPA] 3-1. Defining Query Methods (1)

1. Query Lookup Strategies@EnableJpaRepositories (queryLookupStrategy)queryLookupStrategy 옵션설명CREATE_IF_NOT_FOUND (기본값)선언된 쿼리(@Query 등)이 있으면 사용하고, 없으면 메서드 이름 기반으로 쿼리 생성CREATE무조건 메서드 이름 기반으로 쿼리 생성 (어노테이션 선언 무시)USE_DECLARED_QUERY선언된 쿼리(@Query 등)만 사용, 없으면 애플리케이션 시작 시 예외 발생 2. Query CreationQuery Builder 기반 생성메서드 이름을 추론하여 JPQL Query를 생성합니다. Parsing Query Method Name요소설명예시subject쿼리 목적 (메서드 도입부)find, ..

[Spring Data JPA] 3-7. Repository query keywords

1. Supported query method subject keywordsfind…Byread…Byget…Byquery…Bysearch…Bystream…ByGeneral query method - can be used in combination with additional keywordsReturn type: the repository type- Collection, Streamable subtype, result wrapper (Page, GeoResults, store-specific)exists…ByExists projectionReturn type: booleancount…ByCount projectionReturn type: booleandelete…Byremove…ByDelete que..

[고급 알고리즘] Dynamic Programming: Travelling salesman problem

1. Travelling salesman problem 여러 도시들이 있고 한 도시에서 다른 도시로 이동하는 비용이 모두 주어졌을 떄, 모든 도시들을 단 한 번만 방문하고 원래 시작점으로 돌아오는데 드는 최소 거리 구하기 그래프 이론 각 변에 가중치가 주어진 완전 그래프에서 가장 작은 가중치를 가진 해밀턴 순환 구하기 2. brute-force (permutation. NP) time complexity $O(n!)$ 3. dynamic programming (Held-Karp algorithm) 동작 원리 초기화 모든 도시를 1부터 n까지 번호 매기기 임의의 도시를 시작점으로 선택 상태 정의 $g(S, e)$ : 출발지에서 S에 포함된 모든 도시를 거쳐 e에 도달하는 최단 경로의 길이 최솟값 계산 (재..

Algorithm 2024.03.01

[고급 알고리즘] Dynamic Programming: String

1. Longest Common Subsequence (LCS. 최장 공통 수열)두 수열의 공통 부분 수열 중, 가장 긴 수열을 찾는 문제입니다. 부분 수열주어진 수열에서 몇 개의 원소를 선택해 만든 수열✅ 원소의 순서는 원래 수열에서의 순서를 유지해야 함 점화식${\displaystyle LCS\left(X_{i},Y_{j}\right)={\begin{cases}\emptyset &{\mbox{ if }}\ i=0{\mbox{ or }}j=0\\{\textrm {}}LCS\left(X_{i-1},Y_{j-1}\right)+1&{\mbox{ if }}x_{i}=y_{j}\\{\mbox{longest}}\left(LCS\left(X_{i},Y_{j-1}\right),LCS\left(X_{i-1},Y_{j}..

Algorithm 2024.03.01

[고급 알고리즘] Dynamic Programming: Knapsack Problem

1. Knapsack Problem (배낭 문제)베낭에 담을 수 있는 최대 무게가 정해져 있고, 무게와 가치가 있는 짐들을 배낭에 넣을 때 가치의 합이 최대가 되도록 짐 채우기 0-1 Knapsack Problem각 짐을 넣거나 넣지 않는 선택을 할 수 있음짐별로 한 번만 선택할 수 있음✅ $m[0, w] = 0$✅ $m[i, w] = m[i-1, w] \quad \text{if } w_{i} > w$➡️ $m[i, w] = \max(m[i-1, w], m[i-1, w-w_{i}] + v_{i}) \quad \text{if } w_{i} \leqslant w$ 2. 풀이코드더보기costs = new int[N+1];volumes = new int[N+1];dp = new int[N+1][K+1];for..

Algorithm 2024.03.01

[고급 알고리즘] Dynamic Programming: Fibonacci

1. Fibonacci (피보나치 수열)직전 두 항의 합인 수열입니다. (첫째항과 둘째항은 1) 점화식$fib(n) = fib(n-1) + fib(n-2)$ 예시: $fib(5)$$fib(4)+fib(3)$$(fib(3)+fib(2)) + (fib(2)+fib(1))$$((fib(2)+fib(1)) + (fib(1)+fib(0))) + ((fib(1)+fib(0)) + fib(1)$$(((fib(1)+fib(0)) + fib(1)) + (fib(1)+fib(0))) + ((fib(1)+fib(0)) + fib(1))$ 2. 풀이 코드더보기public int fibDP(int n) { if (n == 0) return 0; if (n == 1) return 1; if (memo[n]..

Algorithm 2024.03.01