Translate all code to English (#1836)

* Review the EN heading format.

* Fix pythontutor headings.

* Fix pythontutor headings.

* bug fixes

* Fix headings in **/summary.md

* Revisit the CN-to-EN translation for Python code using Claude-4.5

* Revisit the CN-to-EN translation for Java code using Claude-4.5

* Revisit the CN-to-EN translation for Cpp code using Claude-4.5.

* Fix the dictionary.

* Fix cpp code translation for the multipart strings.

* Translate Go code to English.

* Update workflows to test EN code.

* Add EN translation for C.

* Add EN translation for CSharp.

* Add EN translation for Swift.

* Trigger the CI check.

* Revert.

* Update en/hash_map.md

* Add the EN version of Dart code.

* Add the EN version of Kotlin code.

* Add missing code files.

* Add the EN version of JavaScript code.

* Add the EN version of TypeScript code.

* Fix the workflows.

* Add the EN version of Ruby code.

* Add the EN version of Rust code.

* Update the CI check for the English version  code.

* Update Python CI check.

* Fix cmakelists for en/C code.

* Fix Ruby comments
This commit is contained in:
Yudong Jin
2025-12-31 07:44:52 +08:00
committed by GitHub
parent 45e1295241
commit 2778a6f9c7
1284 changed files with 71557 additions and 3275 deletions

View File

@@ -6,7 +6,7 @@
#include "../utils/common.hpp"
/* Constant complexity */
/* Constant order */
int constant(int n) {
int count = 0;
int size = 100000;
@@ -15,7 +15,7 @@ int constant(int n) {
return count;
}
/* Linear complexity */
/* Linear order */
int linear(int n) {
int count = 0;
for (int i = 0; i < n; i++)
@@ -23,20 +23,20 @@ int linear(int n) {
return count;
}
/* Linear complexity (traversing an array) */
/* Linear order (traversing array) */
int arrayTraversal(vector<int> &nums) {
int count = 0;
// Loop count is proportional to the length of the array
// Number of iterations is proportional to the array length
for (int num : nums) {
count++;
}
return count;
}
/* Quadratic complexity */
/* Exponential order */
int quadratic(int n) {
int count = 0;
// Loop count is squared in relation to the data size n
// Number of iterations is quadratically related to the data size 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;
}
/* Quadratic complexity (bubble sort) */
/* Quadratic order (bubble sort) */
int bubbleSort(vector<int> &nums) {
int count = 0; // Counter
// Outer loop: unsorted range is [0, i]
for (int i = nums.size() - 1; i > 0; i--) {
// Inner loop: swap the largest element in the unsorted range [0, i] to the right end of the range
// Inner loop: swap the largest element in the unsorted range [0, i] to the rightmost end of that range
for (int j = 0; j < i; j++) {
if (nums[j] > nums[j + 1]) {
// Swap nums[j] and nums[j + 1]
int tmp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = tmp;
count += 3; // Element swap includes 3 individual operations
count += 3; // Element swap includes 3 unit operations
}
}
}
return count;
}
/* Exponential complexity (loop implementation) */
/* Exponential order (loop implementation) */
int exponential(int n) {
int count = 0, base = 1;
// Cells split into two every round, forming the sequence 1, 2, 4, 8, ..., 2^(n-1)
// Cells divide into two every round, forming sequence 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;
}
/* Exponential complexity (recursive implementation) */
/* Exponential order (recursive implementation) */
int expRecur(int n) {
if (n == 1)
return 1;
return expRecur(n - 1) + expRecur(n - 1) + 1;
}
/* Logarithmic complexity (loop implementation) */
/* Logarithmic order (loop implementation) */
int logarithmic(int n) {
int count = 0;
while (n > 1) {
@@ -95,14 +95,14 @@ int logarithmic(int n) {
return count;
}
/* Logarithmic complexity (recursive implementation) */
/* Logarithmic order (recursive implementation) */
int logRecur(int n) {
if (n <= 1)
return 0;
return logRecur(n / 2) + 1;
}
/* Linear logarithmic complexity */
/* Linearithmic order */
int linearLogRecur(int n) {
if (n <= 1)
return 1;
@@ -113,12 +113,12 @@ int linearLogRecur(int n) {
return count;
}
/* Factorial complexity (recursive implementation) */
/* Factorial order (recursive implementation) */
int factorialRecur(int n) {
if (n == 0)
return 1;
int count = 0;
// From 1 split into n
// Split from 1 into n
for (int i = 0; i < n; i++) {
count += factorialRecur(n - 1);
}
@@ -127,42 +127,42 @@ int factorialRecur(int n) {
/* Driver Code */
int main() {
// Can modify n to experience the trend of operation count changes under various complexities
// You can modify n to run and observe the trend of the number of operations for various complexities
int n = 8;
cout << "Input data size n = " << n << endl;
int count = constant(n);
cout << "Number of constant complexity operations = " << count << endl;
cout << "Constant order operation count = " << count << endl;
count = linear(n);
cout << "Number of linear complexity operations = " << count << endl;
cout << "Linear order operation count = " << count << endl;
vector<int> arr(n);
count = arrayTraversal(arr);
cout << "Number of linear complexity operations (traversing the array) = " << count << endl;
cout << "Linear order (array traversal) operation count = " << count << endl;
count = quadratic(n);
cout << "Number of quadratic order operations = " << count << endl;
cout << "Quadratic order operation count = " << 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 << "Number of quadratic order operations (bubble sort) = " << count << endl;
cout << "Quadratic order (bubble sort) operation count = " << count << endl;
count = exponential(n);
cout << "Number of exponential complexity operations (implemented by loop) = " << count << endl;
cout << "Exponential order (loop implementation) operation count = " << count << endl;
count = expRecur(n);
cout << "Number of exponential complexity operations (implemented by recursion) = " << count << endl;
cout << "Exponential order (recursive implementation) operation count = " << count << endl;
count = logarithmic(n);
cout << "Number of logarithmic complexity operations (implemented by loop) = " << count << endl;
cout << "Logarithmic order (loop implementation) operation count = " << count << endl;
count = logRecur(n);
cout << "Number of logarithmic complexity operations (implemented by recursion) = " << count << endl;
cout << "Logarithmic order (recursive implementation) operation count = " << count << endl;
count = linearLogRecur(n);
cout << "Number of linear logarithmic complexity operations (implemented by recursion) = " << count << endl;
cout << "Linearithmic order (recursive implementation) operation count = " << count << endl;
count = factorialRecur(n);
cout << "Number of factorial complexity operations (implemented by recursion) = " << count << endl;
cout << "Factorial order (recursive implementation) operation count = " << count << endl;
return 0;
}