feat(ko): add the Korean online edition (#2006)

* feat(ko): add the complete Korean online edition

* Use UTF-8 for Python CI output on Windows

* Remove print-book promotion from the Korean site

* fix(ko): preserve emphasis before Korean particles
This commit is contained in:
Yudong Jin
2026-10-29 03:46:43 +08:00
committed by GitHub
parent 71a773df64
commit 2f561d3d51
2072 changed files with 110884 additions and 102 deletions

View File

@@ -0,0 +1,117 @@
/**
* File: graph_adjacency_list.java
* Created Time: 2023-01-26
* Author: krahets (krahets@163.com)
*/
package chapter_graph;
import java.util.*;
import utils.*;
/* 인접 리스트로 구현한 무방향 그래프 클래스 */
class GraphAdjList {
// 인접 리스트의 key: 정점, value: 해당 정점의 모든 인접 정점
Map<Vertex, List<Vertex>> adjList;
/* 생성자 */
public GraphAdjList(Vertex[][] edges) {
this.adjList = new HashMap<>();
// 모든 정점과 간선을 추가한다
for (Vertex[] edge : edges) {
addVertex(edge[0]);
addVertex(edge[1]);
addEdge(edge[0], edge[1]);
}
}
/* 정점 개수 반환 */
public int size() {
return adjList.size();
}
/* 간선 추가 */
public void addEdge(Vertex vet1, Vertex vet2) {
if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)
throw new IllegalArgumentException();
// 간선 vet1 - vet2를 추가한다
adjList.get(vet1).add(vet2);
adjList.get(vet2).add(vet1);
}
/* 간선 삭제 */
public void removeEdge(Vertex vet1, Vertex vet2) {
if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)
throw new IllegalArgumentException();
// 간선 vet1 - vet2를 삭제한다
adjList.get(vet1).remove(vet2);
adjList.get(vet2).remove(vet1);
}
/* 정점 추가 */
public void addVertex(Vertex vet) {
if (adjList.containsKey(vet))
return;
// 인접 리스트에 새 연결 리스트를 추가한다
adjList.put(vet, new ArrayList<>());
}
/* 정점 삭제 */
public void removeVertex(Vertex vet) {
if (!adjList.containsKey(vet))
throw new IllegalArgumentException();
// 인접 리스트에서 정점 vet에 해당하는 연결 리스트를 삭제한다
adjList.remove(vet);
// 다른 정점의 연결 리스트를 순회하여 vet를 포함하는 모든 간선을 삭제한다
for (List<Vertex> list : adjList.values()) {
list.remove(vet);
}
}
/* 인접 리스트 출력 */
public void print() {
System.out.println("인접 리스트 =");
for (Map.Entry<Vertex, List<Vertex>> pair : adjList.entrySet()) {
List<Integer> tmp = new ArrayList<>();
for (Vertex vertex : pair.getValue())
tmp.add(vertex.val);
System.out.println(pair.getKey().val + ": " + tmp + ",");
}
}
}
public class graph_adjacency_list {
public static void main(String[] args) {
/* 무방향 그래프 초기화 */
Vertex[] v = Vertex.valsToVets(new int[] { 1, 3, 2, 5, 4 });
Vertex[][] edges = { { v[0], v[1] }, { v[0], v[3] }, { v[1], v[2] },
{ v[2], v[3] }, { v[2], v[4] }, { v[3], v[4] } };
GraphAdjList graph = new GraphAdjList(edges);
System.out.println("\n초기화한 후의 그래프");
graph.print();
/* 간선 추가 */
// 정점 1, 2는 각각 v[0], v[2]이다
graph.addEdge(v[0], v[2]);
System.out.println("\n간선 1-2를 추가한 후의 그래프");
graph.print();
/* 간선 삭제 */
// 정점 1, 3은 각각 v[0], v[1]이다
graph.removeEdge(v[0], v[1]);
System.out.println("\n간선 1-3을 삭제한 후의 그래프");
graph.print();
/* 정점 추가 */
Vertex v5 = new Vertex(6);
graph.addVertex(v5);
System.out.println("\n정점 6을 추가한 후의 그래프");
graph.print();
/* 정점 삭제 */
// 정점 3은 v[1]이다
graph.removeVertex(v[1]);
System.out.println("\n정점 3을 삭제한 후의 그래프");
graph.print();
}
}

View File

@@ -0,0 +1,131 @@
/**
* File: graph_adjacency_matrix.java
* Created Time: 2023-01-26
* Author: krahets (krahets@163.com)
*/
package chapter_graph;
import utils.*;
import java.util.*;
/* 인접 행렬로 구현한 무방향 그래프 클래스 */
class GraphAdjMat {
List<Integer> vertices; // 정점 리스트의 원소는 정점 값을, 인덱스는 정점 인덱스를 나타낸다
List<List<Integer>> adjMat; // 인접 행렬의 행과 열 인덱스는 정점 인덱스에 해당한다
/* 생성자 */
public GraphAdjMat(int[] vertices, int[][] edges) {
this.vertices = new ArrayList<>();
this.adjMat = new ArrayList<>();
// 정점 추가
for (int val : vertices) {
addVertex(val);
}
// 간선 추가
// edges의 원소는 정점 인덱스, 즉 vertices 원소의 인덱스를 나타낸다
for (int[] e : edges) {
addEdge(e[0], e[1]);
}
}
/* 정점 개수 반환 */
public int size() {
return vertices.size();
}
/* 정점 추가 */
public void addVertex(int val) {
int n = size();
// 정점 리스트에 새 정점의 값을 추가한다
vertices.add(val);
// 인접 행렬에 행 하나를 추가한다
List<Integer> newRow = new ArrayList<>(n);
for (int j = 0; j < n; j++) {
newRow.add(0);
}
adjMat.add(newRow);
// 인접 행렬에 열 하나를 추가한다
for (List<Integer> row : adjMat) {
row.add(0);
}
}
/* 정점 삭제 */
public void removeVertex(int index) {
if (index >= size())
throw new IndexOutOfBoundsException();
// 정점 리스트에서 인덱스 index의 정점을 제거한다
vertices.remove(index);
// 인접 행렬에서 인덱스 index의 행을 삭제한다
adjMat.remove(index);
// 인접 행렬에서 인덱스 index의 열을 삭제한다
for (List<Integer> row : adjMat) {
row.remove(index);
}
}
/* 간선 추가 */
// 매개변수 i, j는 vertices 원소의 인덱스에 해당한다
public void addEdge(int i, int j) {
// 인덱스가 범위를 벗어나거나 서로 같은 경우를 처리한다
if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)
throw new IndexOutOfBoundsException();
// 무방향 그래프의 인접 행렬은 주대각선에 대해 대칭이며, (i, j) == (j, i)를 만족한다
adjMat.get(i).set(j, 1);
adjMat.get(j).set(i, 1);
}
/* 간선 삭제 */
// 매개변수 i, j는 vertices 원소의 인덱스에 해당한다
public void removeEdge(int i, int j) {
// 인덱스가 범위를 벗어나거나 서로 같은 경우를 처리한다
if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)
throw new IndexOutOfBoundsException();
adjMat.get(i).set(j, 0);
adjMat.get(j).set(i, 0);
}
/* 인접 행렬 출력 */
public void print() {
System.out.print("정점 리스트 = ");
System.out.println(vertices);
System.out.println("인접 행렬 =");
PrintUtil.printMatrix(adjMat);
}
}
public class graph_adjacency_matrix {
public static void main(String[] args) {
/* 무방향 그래프 초기화 */
// edges의 원소는 정점 인덱스, 즉 vertices 원소의 인덱스를 나타낸다
int[] vertices = { 1, 3, 2, 5, 4 };
int[][] edges = { { 0, 1 }, { 0, 3 }, { 1, 2 }, { 2, 3 }, { 2, 4 }, { 3, 4 } };
GraphAdjMat graph = new GraphAdjMat(vertices, edges);
System.out.println("\n초기화한 후의 그래프");
graph.print();
/* 간선 추가 */
// 정점 1, 2의 인덱스는 각각 0, 2이다
graph.addEdge(0, 2);
System.out.println("\n간선 1-2를 추가한 후의 그래프");
graph.print();
/* 간선 삭제 */
// 정점 1, 3의 인덱스는 각각 0, 1이다
graph.removeEdge(0, 1);
System.out.println("\n간선 1-3을 삭제한 후의 그래프");
graph.print();
/* 정점 추가 */
graph.addVertex(6);
System.out.println("\n정점 6을 추가한 후의 그래프");
graph.print();
/* 정점 삭제 */
// 정점 3의 인덱스는 1이다
graph.removeVertex(1);
System.out.println("\n정점 3을 삭제한 후의 그래프");
graph.print();
}
}

View File

@@ -0,0 +1,55 @@
/**
* File: graph_bfs.java
* Created Time: 2023-02-12
* Author: krahets (krahets@163.com)
*/
package chapter_graph;
import java.util.*;
import utils.*;
public class graph_bfs {
/* 너비 우선 순회 */
// 지정한 정점의 모든 인접 정점을 얻기 쉽도록 그래프를 인접 리스트로 표현한다
static List<Vertex> graphBFS(GraphAdjList graph, Vertex startVet) {
// 정점 순회 순서
List<Vertex> res = new ArrayList<>();
// 방문한 정점을 기록하는 해시 집합
Set<Vertex> visited = new HashSet<>();
visited.add(startVet);
// 큐를 사용하여 BFS를 구현한다
Queue<Vertex> que = new LinkedList<>();
que.offer(startVet);
// 정점 vet에서 시작하여 모든 정점을 방문할 때까지 반복한다
while (!que.isEmpty()) {
Vertex vet = que.poll(); // 큐 맨 앞의 정점을 꺼낸다
res.add(vet); // 방문한 정점을 기록한다
// 해당 정점의 모든 인접 정점을 순회한다
for (Vertex adjVet : graph.adjList.get(vet)) {
if (visited.contains(adjVet))
continue; // 이미 방문한 정점은 건너뛴다
que.offer(adjVet); // 방문하지 않은 정점만 큐에 삽입한다
visited.add(adjVet); // 해당 정점을 방문했다고 표시한다
}
}
// 정점 순회 순서를 반환한다
return res;
}
public static void main(String[] args) {
/* 무방향 그래프 초기화 */
Vertex[] v = Vertex.valsToVets(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
Vertex[][] edges = { { v[0], v[1] }, { v[0], v[3] }, { v[1], v[2] }, { v[1], v[4] },
{ v[2], v[5] }, { v[3], v[4] }, { v[3], v[6] }, { v[4], v[5] },
{ v[4], v[7] }, { v[5], v[8] }, { v[6], v[7] }, { v[7], v[8] } };
GraphAdjList graph = new GraphAdjList(edges);
System.out.println("\n초기화한 후의 그래프");
graph.print();
/* 너비 우선 순회 */
List<Vertex> res = graphBFS(graph, v[0]);
System.out.println("\n너비 우선 순회(BFS)의 정점 순서");
System.out.println(Vertex.vetsToVals(res));
}
}

View File

@@ -0,0 +1,51 @@
/**
* File: graph_dfs.java
* Created Time: 2023-02-12
* Author: krahets (krahets@163.com)
*/
package chapter_graph;
import java.util.*;
import utils.*;
public class graph_dfs {
/* 깊이 우선 순회 보조 함수 */
static void dfs(GraphAdjList graph, Set<Vertex> visited, List<Vertex> res, Vertex vet) {
res.add(vet); // 방문한 정점을 기록한다
visited.add(vet); // 해당 정점을 방문했다고 표시한다
// 해당 정점의 모든 인접 정점을 순회한다
for (Vertex adjVet : graph.adjList.get(vet)) {
if (visited.contains(adjVet))
continue; // 이미 방문한 정점은 건너뛴다
// 인접 정점을 재귀적으로 방문한다
dfs(graph, visited, res, adjVet);
}
}
/* 깊이 우선 순회 */
// 지정한 정점의 모든 인접 정점을 얻기 쉽도록 그래프를 인접 리스트로 표현한다
static List<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {
// 정점 순회 순서
List<Vertex> res = new ArrayList<>();
// 방문한 정점을 기록하는 해시 집합
Set<Vertex> visited = new HashSet<>();
dfs(graph, visited, res, startVet);
return res;
}
public static void main(String[] args) {
/* 무방향 그래프 초기화 */
Vertex[] v = Vertex.valsToVets(new int[] { 0, 1, 2, 3, 4, 5, 6 });
Vertex[][] edges = { { v[0], v[1] }, { v[0], v[3] }, { v[1], v[2] },
{ v[2], v[5] }, { v[4], v[5] }, { v[5], v[6] } };
GraphAdjList graph = new GraphAdjList(edges);
System.out.println("\n초기화한 후의 그래프");
graph.print();
/* 깊이 우선 순회 */
List<Vertex> res = graphDFS(graph, v[0]);
System.out.println("\n깊이 우선 순회(DFS)의 정점 순서");
System.out.println(Vertex.vetsToVals(res));
}
}