Retranslate the complete Japanese online edition from Chinese (#2008)

* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
This commit is contained in:
Yudong Jin
2026-10-30 02:12:26 +08:00
committed by GitHub
parent 455e8c1281
commit 7257641e0e
1987 changed files with 23531 additions and 23261 deletions

View File

@@ -24,7 +24,7 @@ public class complexity_exercises {
return n + SumRecur(n - 1);
}
/* 線形時間のループ */
/* 線形オーダーのループ */
int LinearLoop(int n) {
int res = 0;
for (int i = 0; i < n; i++) {
@@ -33,7 +33,7 @@ public class complexity_exercises {
return res;
}
/* 二次時間のループ */
/* 二次オーダーのループ */
int QuadraticLoop(int n) {
int res = 0;
for (int i = 0; i < n; i++) {
@@ -44,7 +44,7 @@ public class complexity_exercises {
return res;
}
/* 対数時間のループ */
/* 対数オーダーのループ */
int LogarithmicLoop(int n) {
while (n > 1) {
n /= 2;

View File

@@ -10,7 +10,7 @@ public class iteration {
/* for ループ */
int ForLoop(int n) {
int res = 0;
// 1, 2, ..., n-1, n を順に加算する
// ループで 1, 2, ..., n-1, n の和を求める
for (int i = 1; i <= n; i++) {
res += i;
}
@@ -21,7 +21,7 @@ public class iteration {
int WhileLoop(int n) {
int res = 0;
int i = 1; // 条件変数を初期化する
// 1, 2, ..., n-1, n を順に加算する
// ループで 1, 2, ..., n-1, n の和を求める
while (i <= n) {
res += i;
i += 1; // 条件変数を更新する
@@ -29,11 +29,11 @@ public class iteration {
return res;
}
/* while ループ(2回更新) */
/* while ループ(2 回の更新) */
int WhileLoopII(int n) {
int res = 0;
int i = 1; // 条件変数を初期化する
// 1, 4, 10, ... を順に加算する
// ループで 1, 4, 10, ... の和を求める
while (i <= n) {
res += i;
// 条件変数を更新する
@@ -46,9 +46,9 @@ public class iteration {
/* 二重 for ループ */
string NestedForLoop(int n) {
StringBuilder res = new();
// i = 1, 2, ..., n-1, n とループする
// i = 1, 2, ..., n-1, n のループ
for (int i = 1; i <= n; i++) {
// j = 1, 2, ..., n-1, n とループする
// j = 1, 2, ..., n-1, n のループ
for (int j = 1; j <= n; j++) {
res.Append($"({i}, {j}), ");
}
@@ -56,20 +56,20 @@ public class iteration {
return res.ToString();
}
/* Driver Code */
/* 実行用コード */
[Test]
public void Test() {
int n = 5;
int res;
res = ForLoop(n);
Console.WriteLine("\nfor ループの合計結果 res = " + res);
Console.WriteLine("\nfor ループで求めた和 res = " + res);
res = WhileLoop(n);
Console.WriteLine("\nwhile ループの合計結果 res = " + res);
Console.WriteLine("\nwhile ループで求めた和 res = " + res);
res = WhileLoopII(n);
Console.WriteLine("\nwhile ループ(2回更新)の合計結果 res = " + res);
Console.WriteLine("\nwhile ループ(2 回の更新)で求めた和 res = " + res);
string resStr = NestedForLoop(n);
Console.WriteLine("\n二重 for ループの走査結果 " + resStr);

View File

@@ -12,25 +12,25 @@ public class recursion {
// 終了条件
if (n == 1)
return 1;
// 再帰:再帰呼び出し
// 往路:再帰呼び出し
int res = Recur(n - 1);
// 帰りがけ:結果を返す
// 復路:結果を返す
return n + res;
}
/* 反復で再帰を模擬する */
/* 反復を使って再帰を再現する */
int ForLoopRecur(int n) {
// 明示的なスタックを使ってシステムコールスタックを模擬する
// 明示的なスタックを使って、システムの呼び出しスタックを再現する
Stack<int> stack = new();
int res = 0;
// 再帰:再帰呼び出し
// 往路:再帰呼び出し
for (int i = n; i > 0; i--) {
// 「スタックへのプッシュ」で「再帰」を模擬する
// 「プッシュ操作」で再帰の「往路」を再現する
stack.Push(i);
}
// 帰りがけ:結果を返す
// 復路:結果を返す
while (stack.Count > 0) {
// 「スタックから取り出す操作」で「帰り」をシミュレート
// 「ポップ操作」で再帰の「復路」を再現する
res += stack.Pop();
}
// res = 1+2+3+...+n
@@ -51,26 +51,26 @@ public class recursion {
// 終了条件 f(1) = 0, f(2) = 1
if (n == 1 || n == 2)
return n - 1;
// f(n) = f(n-1) + f(n-2) を再帰的に呼び出す
// 再帰呼び出し f(n) = f(n-1) + f(n-2)
int res = Fib(n - 1) + Fib(n - 2);
// 結果 f(n) を返す
return res;
}
/* Driver Code */
/* 実行用コード */
[Test]
public void Test() {
int n = 5;
int res;
res = Recur(n);
Console.WriteLine("\n再帰関数の合計結果 res = " + res);
Console.WriteLine("\n再帰関数で求めた和 res = " + res);
res = ForLoopRecur(n);
Console.WriteLine("\n反復で再帰をシミュレートした合計結果 res = " + res);
Console.WriteLine("\n反復で再帰を再現して求めた和 res = " + res);
res = TailRecur(n, 0);
Console.WriteLine("\n末尾再帰関数の合計結果 res = " + res);
Console.WriteLine("\n末尾再帰関数で求めた和 res = " + res);
res = Fib(n);
Console.WriteLine("\nフィボナッチ数列の第 " + n + " 項は " + res);

View File

@@ -9,55 +9,55 @@ namespace hello_algo.chapter_computational_complexity;
public class space_complexity {
/* 関数 */
int Function() {
// 何らかの処理を行う
// 何らかの処理を実行する
return 0;
}
/* 定数階 */
/* 定数オーダー */
void Constant(int n) {
// 定数、変数、オブジェクトは O(1) の空間を占める
// 定数、変数、オブジェクトは O(1) の領域を使用する
int a = 0;
int b = 0;
int[] nums = new int[10000];
ListNode node = new(0);
// ループ内の変数は O(1) の空間を占める
// ループ内の変数は O(1) の領域を使用する
for (int i = 0; i < n; i++) {
int c = 0;
}
// ループ内の関数は O(1) の空間を占める
// ループ内の関数は O(1) の領域を使用する
for (int i = 0; i < n; i++) {
Function();
}
}
/* 線形階 */
/* 線形オーダー */
void Linear(int n) {
// 長さ n の配列は O(n) の空間を使用
// 長さ n の配列は O(n) の領域を使用する
int[] nums = new int[n];
// 長さ n のリストは O(n) の空間を使用
// 長さ n のリストは O(n) の領域を使用する
List<ListNode> nodes = [];
for (int i = 0; i < n; i++) {
nodes.Add(new ListNode(i));
}
// 長さ n のハッシュテーブルは O(n) の空間を使用
// 長さ n のハッシュテーブルは O(n) の領域を使用する
Dictionary<int, string> map = [];
for (int i = 0; i < n; i++) {
map.Add(i, i.ToString());
}
}
/* 線形時間(再帰実装) */
/* 線形オーダー(再帰による実装) */
void LinearRecur(int n) {
Console.WriteLine("再帰 n = " + n);
if (n == 1) return;
LinearRecur(n - 1);
}
/* 二乗階 */
/* 二次オーダー */
void Quadratic(int n) {
// 行列は O(n^2) の空間を使用する
// 行列は O(n^2) の領域を使用する
int[,] numMatrix = new int[n, n];
// 二次元リストは O(n^2) の空間を使用
// 二次元リストは O(n^2) の領域を使用する
List<List<int>> numList = [];
for (int i = 0; i < n; i++) {
List<int> tmp = [];
@@ -68,7 +68,7 @@ public class space_complexity {
}
}
/* 二次時間(再帰実装) */
/* 二次オーダー(再帰による実装) */
int QuadraticRecur(int n) {
if (n <= 0) return 0;
int[] nums = new int[n];
@@ -76,7 +76,7 @@ public class space_complexity {
return QuadraticRecur(n - 1);
}
/* 指数時間(完全二分木の構築) */
/* 指数オーダー(パーフェクト二分木の構築) */
TreeNode? BuildTree(int n) {
if (n == 0) return null;
TreeNode root = new(0) {
@@ -89,12 +89,12 @@ public class space_complexity {
[Test]
public void Test() {
int n = 5;
// 定数階
// 定数オーダー
Constant(n);
// 線形階
// 線形オーダー
Linear(n);
LinearRecur(n);
// 二乗階
// 二次オーダー
Quadratic(n);
QuadraticRecur(n);
// 指数オーダー

View File

@@ -8,13 +8,13 @@ namespace hello_algo.chapter_computational_complexity;
public class time_complexity {
void Algorithm(int n) {
int a = 1; // +0(テクニック 1)
a += n; // +0(テクニック 1)
// +n(テクニック 2)
int a = 1; // +0(コツ 1)
a += n; // +0(コツ 1)
// +n(コツ 2)
for (int i = 0; i < 5 * n + 1; i++) {
Console.WriteLine(0);
}
// +n*n(テクニック 3)
// +n*n(コツ 3)
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < n + 1; j++) {
Console.WriteLine(0);
@@ -22,26 +22,26 @@ public class time_complexity {
}
}
// アルゴリズム A の時間計算量: 定数時間
// アルゴリズム A の時間計算量:定数オーダー
void AlgorithmA(int n) {
Console.WriteLine(0);
}
// アルゴリズム B の時間計算量: 線形時間
// アルゴリズム B の時間計算量:線形オーダー
void AlgorithmB(int n) {
for (int i = 0; i < n; i++) {
Console.WriteLine(0);
}
}
// アルゴリズム C の時間計算量: 定数時間
// アルゴリズム C の時間計算量:定数オーダー
void AlgorithmC(int n) {
for (int i = 0; i < 1000000; i++) {
Console.WriteLine(0);
}
}
/* 定数階 */
/* 定数オーダー */
int Constant(int n) {
int count = 0;
int size = 100000;
@@ -50,7 +50,7 @@ public class time_complexity {
return count;
}
/* 線形階 */
/* 線形オーダー */
int Linear(int n) {
int count = 0;
for (int i = 0; i < n; i++)
@@ -58,20 +58,20 @@ public class time_complexity {
return count;
}
/* 線形時間(配列を走査) */
/* 線形オーダー(配列の走査) */
int ArrayTraversal(int[] nums) {
int count = 0;
// ループ回数は配列長に比例する
// ループの回数は配列の長さに比例する
foreach (int num in nums) {
count++;
}
return count;
}
/* 二乗階 */
/* 二次オーダー */
int Quadratic(int n) {
int count = 0;
// ループ回数はデータサイズ n の二乗に比例する
// ループの回数はデータの大きさ n の二乗に比例する
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
count++;
@@ -80,27 +80,27 @@ public class time_complexity {
return count;
}
/* 二次時間(バブルソート) */
/* 二次オーダー(バブルソート) */
int BubbleSort(int[] nums) {
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] を交換する
(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);
count += 3; // 要素交換には 3 回の単位操作が含まれる
count += 3; // 要素の交換は 3 回の単位操作からなる
}
}
}
return count;
}
/* 指数時間(ループ実装) */
/* 指数オーダー(ループによる実装) */
int Exponential(int n) {
int count = 0, bas = 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 < bas; j++) {
count++;
@@ -111,13 +111,13 @@ public class time_complexity {
return count;
}
/* 指数時間(再帰実装) */
/* 指数オーダー(再帰による実装) */
int ExpRecur(int n) {
if (n == 1) return 1;
return ExpRecur(n - 1) + ExpRecur(n - 1) + 1;
}
/* 対数時間(ループ実装) */
/* 対数オーダー(ループによる実装) */
int Logarithmic(int n) {
int count = 0;
while (n > 1) {
@@ -127,13 +127,13 @@ public class time_complexity {
return count;
}
/* 対数時間(再帰実装) */
/* 対数オーダー(再帰による実装) */
int LogRecur(int n) {
if (n <= 1) return 0;
return LogRecur(n / 2) + 1;
}
/* 線形対数時間 */
/* 線形対数オーダー */
int LinearLogRecur(int n) {
if (n <= 1) return 1;
int count = LinearLogRecur(n / 2) + LinearLogRecur(n / 2);
@@ -143,11 +143,11 @@ public class time_complexity {
return count;
}
/* 階乗時間(再帰実装) */
/* 階乗オーダー(再帰による実装) */
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);
}
@@ -156,40 +156,40 @@ public class time_complexity {
[Test]
public void Test() {
// n を変えて実行し、各計算量で操作回数がどう変化するかを確認できる
// n を変更して実行し、各計算量で操作回数がどのように変化するか確かめられる
int n = 8;
Console.WriteLine("入力データサイズ n = " + n);
Console.WriteLine("入力データの大きさ n = " + n);
int count = Constant(n);
Console.WriteLine("定数時間の操作回数 = " + count);
Console.WriteLine("定数オーダーの操作回数 = " + count);
count = Linear(n);
Console.WriteLine("線形時間の操作回数 = " + count);
Console.WriteLine("線形オーダーの操作回数 = " + count);
count = ArrayTraversal(new int[n]);
Console.WriteLine("線形時間(配列の走査)の操作回数 = " + count);
Console.WriteLine("線形オーダー(配列の走査)の操作回数 = " + count);
count = Quadratic(n);
Console.WriteLine("二乗時間の操作回数 = " + count);
Console.WriteLine("二次オーダーの操作回数 = " + 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);
Console.WriteLine("二乗時間(バブルソート)の操作回数 = " + count);
Console.WriteLine("二次オーダー(バブルソート)の操作回数 = " + count);
count = Exponential(n);
Console.WriteLine("指数時間(ループ実装)の操作回数 = " + count);
Console.WriteLine("指数オーダー(ループによる実装)の操作回数 = " + count);
count = ExpRecur(n);
Console.WriteLine("指数時間(再帰実装)の操作回数 = " + count);
Console.WriteLine("指数オーダー(再帰による実装)の操作回数 = " + count);
count = Logarithmic(n);
Console.WriteLine("対数時間(ループ実装)の操作回数 = " + count);
Console.WriteLine("対数オーダー(ループによる実装)の操作回数 = " + count);
count = LogRecur(n);
Console.WriteLine("対数時間(再帰実装)の操作回数 = " + count);
Console.WriteLine("対数オーダー(再帰による実装)の操作回数 = " + count);
count = LinearLogRecur(n);
Console.WriteLine("線形対数時間(再帰実装)の操作回数 = " + count);
Console.WriteLine("線形対数オーダー(再帰による実装)の操作回数 = " + count);
count = FactorialRecur(n);
Console.WriteLine("階乗時間(再帰実装)の操作回数 = " + count);
Console.WriteLine("階乗オーダー(再帰による実装)の操作回数 = " + count);
}
}

View File

@@ -7,15 +7,15 @@
namespace hello_algo.chapter_computational_complexity;
public class worst_best_time_complexity {
/* 要素が { 1, 2, ..., n } で、順序がシャッフルされた配列を生成 */
/* 要素が { 1, 2, ..., n } で、順序をシャッフルした配列を生成する */
int[] RandomNumbers(int n) {
int[] nums = new int[n];
// 配列 nums = { 1, 2, 3, ..., n } を生成
// 配列 nums = { 1, 2, 3, ..., n } を生成する
for (int i = 0; i < n; i++) {
nums[i] = i + 1;
}
// 配列要素をランダムにシャッフル
// 配列の要素をランダムに並べ替える
for (int i = 0; i < nums.Length; i++) {
int index = new Random().Next(i, nums.Length);
(nums[i], nums[index]) = (nums[index], nums[i]);
@@ -23,11 +23,11 @@ public class worst_best_time_complexity {
return nums;
}
/* 配列 nums 内で数値 1 のインデックスを探す */
/* 配列 nums 内で数値 1 のインデックスを探索する */
int FindOne(int[] nums) {
for (int i = 0; i < nums.Length; i++) {
// 要素 1 が配列の先頭にあるとき、最良時間計算量 O(1) となる
// 要素 1 が配列の末尾にあるとき、最悪時間計算量 O(n) となる
// 要素 1 が配列の先頭にある場合、最良時間計算量 O(1) となる
// 要素 1 が配列の末尾にある場合、最悪時間計算量 O(n) となる
if (nums[i] == 1)
return i;
}
@@ -35,15 +35,15 @@ public class worst_best_time_complexity {
}
/* Driver Code */
/* 実行用コード */
[Test]
public void Test() {
for (int i = 0; i < 10; i++) {
int n = 100;
int[] nums = RandomNumbers(n);
int index = FindOne(nums);
Console.WriteLine("\n配列 [ 1, 2, ..., n ] をシャッフルした後 = " + string.Join(",", nums));
Console.WriteLine("数字 1 のインデックスは " + index);
Console.WriteLine("\n配列 [ 1, 2, ..., n ] をシャッフルした結果 = " + string.Join(",", nums));
Console.WriteLine("数値 1 のインデックスは " + index);
}
}
}