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

@@ -6,7 +6,7 @@
#include "../utils/common.hpp"
/* 定数計算量 */
/* 定数 */
int constant(int n) {
int count = 0;
int size = 100000;
@@ -15,7 +15,7 @@ int constant(int n) {
return count;
}
/* 線形計算量 */
/* 線形 */
int linear(int n) {
int count = 0;
for (int i = 0; i < n; i++)
@@ -23,20 +23,20 @@ int linear(int n) {
return count;
}
/* 線形計算量(配列走査) */
/* 線形時間(配列走査) */
int arrayTraversal(vector<int> &nums) {
int count = 0;
// ループ回数は配列の長さに比例
// ループ回数は配列に比例する
for (int num : 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++;
@@ -45,29 +45,29 @@ int quadratic(int n) {
return count;
}
/* 二次計算量(バブルソート) */
/* 二次時間(バブルソート) */
int bubbleSort(vector<int> &nums) {
int count = 0; // カウンタ
// 外側ループ:未ソート範囲は [0, i]
int count = 0; // カウンタ
// 外側ループ:未ソート区間は [0, i]
for (int i = nums.size() - 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;
}
/* 指数計算量(ループ実装) */
/* 指数時間(ループ実装) */
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++;
@@ -78,14 +78,14 @@ int exponential(int n) {
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) {
@@ -95,14 +95,14 @@ int logarithmic(int n) {
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;
@@ -113,56 +113,56 @@ int linearLogRecur(int n) {
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);
}
return count;
}
/* ドライバーコード */
/* Driver Code */
int main() {
// n を変更して、さまざまな計算量で操作回数の変化傾向を体験可能
// n を変えて実行し、各計算量で操作回数がどう変化するかを確認できる
int n = 8;
cout << "入力データサイズ n = " << n << endl;
int count = constant(n);
cout << "定数計算量の操作回数 = " << count << endl;
cout << "定数オーダーの操作回数 = " << count << endl;
count = linear(n);
cout << "線形計算量の操作回数 = " << count << endl;
cout << "線形オーダーの操作回数 = " << count << endl;
vector<int> arr(n);
count = arrayTraversal(arr);
cout << "線形計算量の操作回数(配列走査) = " << count << endl;
cout << "線形オーダー(配列走査)の操作回数 = " << count << endl;
count = quadratic(n);
cout << "次計算量の操作回数 = " << count << endl;
cout << "乗オーダーの操作回数 = " << count << endl;
vector<int> nums(n);
for (int i = 0; i < n; i++)
nums[i] = n - i; // [n,n-1,...,2,1]
count = bubbleSort(nums);
cout << "次計算量の操作回数(バブルソート) = " << count << endl;
cout << "乗オーダー(バブルソート)の操作回数 = " << count << endl;
count = exponential(n);
cout << "指数計算量の操作回数(ループ実装) = " << count << endl;
cout << "指数オーダー(ループ実装)の操作回数 = " << count << endl;
count = expRecur(n);
cout << "指数計算量の操作回数(再帰実装) = " << count << endl;
cout << "指数オーダー(再帰実装)の操作回数 = " << count << endl;
count = logarithmic(n);
cout << "対数計算量の操作回数(ループ実装) = " << count << endl;
cout << "対数オーダー(ループ実装)の操作回数 = " << count << endl;
count = logRecur(n);
cout << "対数計算量の操作回数(再帰実装) = " << count << endl;
cout << "対数オーダー(再帰実装)の操作回数 = " << count << endl;
count = linearLogRecur(n);
cout << "線形対数計算量の操作回数(再帰実装) = " << count << endl;
cout << "線形対数オーダー(再帰実装)の操作回数 = " << count << endl;
count = factorialRecur(n);
cout << "階乗計算量の操作回数(再帰実装) = " << count << endl;
cout << "階乗オーダー(再帰実装)の操作回数 = " << count << endl;
return 0;
}
}