Skip to content

Commit 4ebaeca

Browse files
committed
Quartz sync: Jul 4, 2025, 2:39 PM
1 parent b1fd777 commit 4ebaeca

File tree

8 files changed

+117
-54
lines changed

8 files changed

+117
-54
lines changed

content/Computer Science/1 Foundations & Theory/Algorithms/Named Algorithms/Eulerian Path.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ aliases:
66
- 오일러 경로
77
---
88
- 그래프의 모든 간선을 정확히 한 번씩 지나가는 경로
9+
- 쾨니히스베르크의 다리 문제
910
- 시작점 != 끝점 일 수 있다
10-
- Eulerian Circuit
11-
- 시작점 == 끝점
11+
- 시작점
12+
- 차수가 홀수
13+
- 중간 저점
14+
- 차수가 짝수
15+
- 끝점
16+
- 차수가 홀수
17+
- 일반화
18+
- 홀수 차수가 없거나, 오직 두 개만 존재해야 한다
19+
- 모든 정점이 짝수 차수라면 오일러 순환이 존재
20+
- $O(n^2)$
21+
- 오일러 순환 (Eulerian Circuit or Cycle)
22+
- 시작점 == 끝점
23+
- 오일러 그래프
24+
- 오일러 순환이 존재하는 그래프
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description:
3+
aliases:
4+
- 해밀톤 경로
5+
created: 2025-07-03
6+
modified: 2025-07-03
7+
---
8+
9+
- 해밀톤 경로
10+
- [[Eulerian Path|오일러 경로]]처럼 간선이 아닌, 모든 정점을 한 번만 지나는 경로
11+
- 해밀톤 순환 (Hamiltonian Cycle or Circuit)
12+
- 시작점과 끝점이 같은 해밀턴 경로
13+
- 해밀톤 순환을 찾는 알고리즘은 존재하지 않는다
14+
- 전수조사(Exhaustive search) 해야함
15+
- $O(x^n)$
16+
- $x$ - 간선의 수
17+
- $n$ - 정점의 수
18+
- [[Traveling Salesman Problem]]
19+
- 비용이 최소인 해밀톤 순환을 찾는 문제
20+
- [Icosian calculus](https://en.wikipedia.org/wiki/Icosian_calculus)
21+
- ![[image-Hamiltonian Path.png|400]]

content/Computer Science/1 Foundations & Theory/Algorithms/Named Algorithms/Knuth–Morris–Pratt Algorithm.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ aliases:
77
- kmp algorithm
88
---
99

10-
- 접두사, 접미사로 문자열 일치 판별
10+
- 일반적인 bruteforce 패턴 판별
11+
- $O(N * M)$
12+
- KMP는 접두사, 접미사로 문자열 일치 판별
1113
- $O(N+M)$
1214
- [[Two Pointers]] 기법
1315
- `j`
@@ -19,6 +21,11 @@ aliases:
1921
- `i`
2022
- 접미사 인덱스
2123
- 한칸씩 이동하면서 일치 판별
24+
- `table`
25+
- 매칭 실패했을 때 어디까지 pattern index를 돌아갈지 정보가 담긴 배열
26+
- 이전 일치지점에서 시작
27+
- 0이라면 처음부터 다시 매칭
28+
- 값이 있다는건 그 값까지 이미 일치함을 보장
2229
- ```cpp
2330
vector<int> make_table(const string& pattern){
2431
vector<int> table(pattern.size(), 0);
Loading
Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
---
2-
created: 2025/5/07 14:29:20
3-
modified: 2025/5/07 14:32:10
2+
description:
3+
aliases:
4+
- tsp
5+
created: 2025-05-18
6+
modified: 2025-07-04
47
---
8+
- TSP is a touchstone for many general heuristics devised for combinatorial optimization such as [genetic algorithms](https://en.wikipedia.org/wiki/Genetic_algorithm "Genetic algorithm")[simulated annealing](https://en.wikipedia.org/wiki/Simulated_annealing "Simulated annealing")[tabu search](https://en.wikipedia.org/wiki/Tabu_search "Tabu search")[ant colony optimization](https://en.wikipedia.org/wiki/Ant_colony_optimization "Ant colony optimization")[river formation dynamics](https://en.wikipedia.org/w/index.php?title=River_formation_dynamics&action=edit&redlink=1 "River formation dynamics (page does not exist)") (see [swarm intelligence](https://en.wikipedia.org/wiki/Swarm_intelligence "Swarm intelligence")), and the [cross entropy method](https://en.wikipedia.org/wiki/Cross_entropy_method "Cross entropy method").
9+
- DP (recursive)
510
- DP + Bit mask
6-
- `dp[current][visited]`
7-
- 현재 도시가 current이고, visited는 지금까지 방문한 도시의 집합
8-
- visited는 비트마스크 (0 ~ 2ⁿ - 1)로 표현
9-
- ```peusudo
10-
function tsp(current, visited):
11-
// 모든 조합이라는 것은 다 돌았다는 뜻
12-
if visited == all_visited_mask((1 << N) - 1):
13-
// 마지막에서 처음으로 가는 비용이 있다는 것은 돌아 갈 수 있다는 말
14-
if cost[current][start] > 0:
15-
return cost[current][start] // 돌아가는 비용
16-
else:
17-
// 돌아가지 못함으로
18-
return INF // 못 돌아감
19-
20-
// 이미 구한 값이 있으면 얼리 리턴 (not initial value ex: -1)
21-
if dp[current][visited] is already computed:
22-
return dp[current][visited]
23-
24-
dp[current][visited] = INF
25-
26-
// 모든 도시에 대해서
27-
for next in 0 to N-1:
28-
// 조합에 없는 도시만 비트마스크로 추출, 거리가 있다면 dp 없데이트
29-
if city 'next' is not visited and cost[current][next] > 0:
30-
dp[current][visited] = min(
31-
dp[current][visited],
32-
tsp(next, visited | (1 << next)) + cost[current][next]
33-
)
34-
35-
return dp[current][visited]
36-
- 전이 공식
37-
- `mask`: 방문한 도시 집합
38-
- `last`: 마지막 방문 도시
39-
- `dp[mask][last]` = mask를 돌고 last에서 끝날 때 최소 비용
40-
- ```cpp
41-
dp[1<<0][0] = 0;
42-
for(mask = 0 ; mask < 1<<N; mask++)
43-
for(last = 0; last < N; last++){
44-
if(!(mask & 1 << last)) continue;
45-
for(next = 0; next < N; next++){
46-
if(mask & 1 << next) continue;
47-
newMask = mask | (1<<next);
48-
dp[newMask][next] = min(
49-
dp[newMask][next],
50-
dp[mask][last] + dist[last][next]
51-
);
52-
}
53-
}
11+
-  Held-Karp 알고리즘
12+
- `dp[current][visited]`
13+
- 현재 도시가 current이고, visited는 지금까지 방문한 도시의 집합
14+
- visited는 비트마스크 (0 ~ 2ⁿ - 1)로 표현
15+
- ```peusudo
16+
function tsp(current, visited):
17+
// 모든 조합이라는 것은 다 돌았다는 뜻
18+
if visited == all_visited_mask((1 << N) - 1):
19+
// 마지막에서 처음으로 가는 비용이 있다는 것은 돌아 갈 수 있다는 말
20+
if cost[current][start] > 0:
21+
return cost[current][start] // 돌아가는 비용
22+
else:
23+
// 돌아가지 못함으로
24+
return INF // 못 돌아감
25+
26+
// 이미 구한 값이 있으면 얼리 리턴 (not initial value ex: -1)
27+
if dp[current][visited] is already computed:
28+
return dp[current][visited]
29+
30+
dp[current][visited] = INF
31+
32+
// 모든 도시에 대해서
33+
for next in 0 to N-1:
34+
// 조합에 없는 도시만 비트마스크로 추출, 거리가 있다면 dp 없데이트
35+
if city 'next' is not visited and cost[current][next] > 0:
36+
dp[current][visited] = min(
37+
dp[current][visited],
38+
tsp(next, visited | (1 << next)) + cost[current][next]
39+
)
40+
41+
return dp[current][visited]
42+
- 전이 공식
43+
- `mask`: 방문한 도시 집합
44+
- `last`: 마지막 방문 도시
45+
- `dp[mask][last]` = mask를 돌고 last에서 끝날 때 최소 비용
46+
- ```cpp
47+
dp[1<<0][0] = 0;
48+
for(mask = 0 ; mask < 1<<N; mask++){
49+
for(last = 0; last < N; last++){
50+
if(!(mask & 1 << last)) continue; // last가 이미 있다면 패스
51+
52+
for(next = 0; next < N; next++){
53+
if(mask & 1 << next) continue; // next가 이미 있다면 패스
54+
55+
newMask = mask | (1<<next);
56+
57+
dp[newMask][next] = min(
58+
dp[newMask][next],
59+
dp[mask][last] + dist[last][next]
60+
);
61+
}
62+
}
63+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description:
3+
aliases:
4+
created: 2025-07-03
5+
modified: 2025-07-03
6+
---
7+
8+
-
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
---
2-
description:
2+
description:
33
aliases:
4+
- Binary Indexed Tree
5+
- 펜윅 트리
6+
- 인덱스 트리
47
created: 2025-07-02
58
modified: 2025-07-02
69
---
710

811
- 마지막 비트 크기로 현재 인덱스의 '저장 개수' 계산
912
- `i & -i`
13+
- ![[image-Fenwick tree (index tree).png|800]]
1014
- ```cpp
1115
int tree[sum_size];
1216

123 KB
Loading

0 commit comments

Comments
 (0)