Re-translate the Japanese version (#1871)

* Retranslate Japanese docs with GPT-5.4

* Retranslate Japanese code with GPT-5.4
This commit is contained in:
Yudong Jin
2026-03-30 07:30:15 +08:00
committed by GitHub
parent fe6443235b
commit d7b2277d2b
1444 changed files with 83312 additions and 8363 deletions

View File

@@ -7,7 +7,7 @@
package chapter_computational_complexity;
public class time_complexity {
/* 定数計算量 */
/* 定数 */
static int constant(int n) {
int count = 0;
int size = 100000;
@@ -16,7 +16,7 @@ public class time_complexity {
return count;
}
/* 線形計算量 */
/* 線形 */
static int linear(int n) {
int count = 0;
for (int i = 0; i < n; i++)
@@ -24,20 +24,20 @@ public class time_complexity {
return count;
}
/* 線形計算量(配列走査) */
/* 線形時間(配列走査) */
static int arrayTraversal(int[] nums) {
int count = 0;
// ループ回数は配列の長さに比例
// ループ回数は配列に比例する
for (int num : nums) {
count++;
}
return count;
}
/* 二次計算量 */
/* 二乗階 */
static int quadratic(int n) {
int count = 0;
// ループ回数はデータサイズ n の二乗に比例
// ループ回数はデータサイズ n の二乗に比例する
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
count++;
@@ -46,29 +46,29 @@ public class time_complexity {
return count;
}
/* 二次計算量(バブルソート) */
/* 二次時間(バブルソート) */
static int bubbleSort(int[] nums) {
int count = 0; // カウンタ
// 外側ループ:未ソート範囲は [0, i]
int count = 0; // カウンタ
// 外側ループ:未ソート区間は [0, i]
for (int i = nums.length - 1; i > 0; i--) {
// 内側ループ:未ソート範囲 [0, i] の最大要素を範囲の右端にスワップ
// 内側ループ:未ソート区間 [0, i] の最大要素をその区間の最右端へ交換
for (int j = 0; j < i; j++) {
if (nums[j] > nums[j + 1]) {
// nums[j] と nums[j + 1] をスワップ
// nums[j] と nums[j + 1] を交換
int tmp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = tmp;
count += 3; // 要素のスワップには3つの個別操作が含まれる
count += 3; // 要素交換には 3 回の単位操作が含まれる
}
}
}
return count;
}
/* 指数計算量(ループ実装) */
/* 指数時間(ループ実装) */
static int exponential(int n) {
int count = 0, base = 1;
// セルは毎ラウンド2つに分裂し、数列 1, 2, 4, 8, ..., 2^(n-1) を形成
// 細胞は各ラウンドで 2 つに分裂し、数列 1, 2, 4, 8, ..., 2^(n-1) を形成する
for (int i = 0; i < n; i++) {
for (int j = 0; j < base; j++) {
count++;
@@ -79,14 +79,14 @@ public class time_complexity {
return count;
}
/* 指数計算量(再帰実装) */
/* 指数時間(再帰実装) */
static int expRecur(int n) {
if (n == 1)
return 1;
return expRecur(n - 1) + expRecur(n - 1) + 1;
}
/* 対数計算量(ループ実装) */
/* 対数時間(ループ実装) */
static int logarithmic(int n) {
int count = 0;
while (n > 1) {
@@ -96,14 +96,14 @@ public class time_complexity {
return count;
}
/* 対数計算量(再帰実装) */
/* 対数時間(再帰実装) */
static int logRecur(int n) {
if (n <= 1)
return 0;
return logRecur(n / 2) + 1;
}
/* 線形対数計算量 */
/* 線形対数時間 */
static int linearLogRecur(int n) {
if (n <= 1)
return 1;
@@ -114,54 +114,54 @@ public class time_complexity {
return count;
}
/* 階乗計算量(再帰実装) */
/* 階乗時間(再帰実装) */
static int factorialRecur(int n) {
if (n == 0)
return 1;
int count = 0;
// 1から n に分裂
// 1から n に分裂
for (int i = 0; i < n; i++) {
count += factorialRecur(n - 1);
}
return count;
}
/* ドライバーコード */
/* Driver Code */
public static void main(String[] args) {
// n を変更して、さまざまな計算量で操作回数の変化傾向を体験可能
// n を変えて実行し、各計算量で操作回数がどう変化するかを確認できる
int n = 8;
System.out.println("入力データサイズ n = " + n);
int count = constant(n);
System.out.println("定数計算量の操作回数 = " + count);
System.out.println("定数時間の操作回数 = " + count);
count = linear(n);
System.out.println("線形計算量の操作回数 = " + count);
System.out.println("線形時間の操作回数 = " + count);
count = arrayTraversal(new int[n]);
System.out.println("線形計算量の操作回数(配列走査) = " + count);
System.out.println("線形時間(配列走査)の操作回数 = " + count);
count = quadratic(n);
System.out.println("二次計算量の操作回数 = " + count);
System.out.println("2 次時間の操作回数 = " + count);
int[] nums = new int[n];
for (int i = 0; i < n; i++)
nums[i] = n - i; // [n,n-1,...,2,1]
count = bubbleSort(nums);
System.out.println("二次計算量の操作回数(バブルソート) = " + count);
System.out.println("2 次時間(バブルソート)の操作回数 = " + count);
count = exponential(n);
System.out.println("指数計算量の操作回数(ループ実装) = " + count);
System.out.println("指数時間(ループ実装)の操作回数 = " + count);
count = expRecur(n);
System.out.println("指数計算量の操作回数(再帰実装) = " + count);
System.out.println("指数時間(再帰実装)の操作回数 = " + count);
count = logarithmic(n);
System.out.println("対数計算量の操作回数(ループ実装) = " + count);
System.out.println("対数時間(ループ実装)の操作回数 = " + count);
count = logRecur(n);
System.out.println("対数計算量の操作回数(再帰実装) = " + count);
System.out.println("対数時間(再帰実装)の操作回数 = " + count);
count = linearLogRecur(n);
System.out.println("線形対数計算量の操作回数(再帰実装) = " + count);
System.out.println("線形対数時間(再帰実装)の操作回数 = " + count);
count = factorialRecur(n);
System.out.println("階乗計算量の操作回数(再帰実装) = " + count);
System.out.println("階乗時間(再帰実装)の操作回数 = " + count);
}
}
}