mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-15 02:40:58 +08:00
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:
@@ -18,21 +18,21 @@ def function() -> int:
|
||||
|
||||
|
||||
def constant(n: int):
|
||||
"""Constant complexity"""
|
||||
"""Constant order"""
|
||||
# Constants, variables, objects occupy O(1) space
|
||||
a = 0
|
||||
nums = [0] * 10000
|
||||
node = ListNode(0)
|
||||
# Variables in a loop occupy O(1) space
|
||||
# Variables in the loop occupy O(1) space
|
||||
for _ in range(n):
|
||||
c = 0
|
||||
# Functions in a loop occupy O(1) space
|
||||
# Functions in the loop occupy O(1) space
|
||||
for _ in range(n):
|
||||
function()
|
||||
|
||||
|
||||
def linear(n: int):
|
||||
"""Linear complexity"""
|
||||
"""Linear order"""
|
||||
# A list of length n occupies O(n) space
|
||||
nums = [0] * n
|
||||
# A hash table of length n occupies O(n) space
|
||||
@@ -42,30 +42,30 @@ def linear(n: int):
|
||||
|
||||
|
||||
def linear_recur(n: int):
|
||||
"""Linear complexity (recursive implementation)"""
|
||||
print("Recursive n =", n)
|
||||
"""Linear order (recursive implementation)"""
|
||||
print("Recursion n =", n)
|
||||
if n == 1:
|
||||
return
|
||||
linear_recur(n - 1)
|
||||
|
||||
|
||||
def quadratic(n: int):
|
||||
"""Quadratic complexity"""
|
||||
# A two-dimensional list occupies O(n^2) space
|
||||
"""Quadratic order"""
|
||||
# A 2D list occupies O(n^2) space
|
||||
num_matrix = [[0] * n for _ in range(n)]
|
||||
|
||||
|
||||
def quadratic_recur(n: int) -> int:
|
||||
"""Quadratic complexity (recursive implementation)"""
|
||||
"""Quadratic order (recursive implementation)"""
|
||||
if n <= 0:
|
||||
return 0
|
||||
# Array nums length = n, n-1, ..., 2, 1
|
||||
# Array nums length is n, n-1, ..., 2, 1
|
||||
nums = [0] * n
|
||||
return quadratic_recur(n - 1)
|
||||
|
||||
|
||||
def build_tree(n: int) -> TreeNode | None:
|
||||
"""Exponential complexity (building a full binary tree)"""
|
||||
"""Exponential order (build full binary tree)"""
|
||||
if n == 0:
|
||||
return None
|
||||
root = TreeNode(0)
|
||||
@@ -77,14 +77,14 @@ def build_tree(n: int) -> TreeNode | None:
|
||||
"""Driver Code"""
|
||||
if __name__ == "__main__":
|
||||
n = 5
|
||||
# Constant complexity
|
||||
# Constant order
|
||||
constant(n)
|
||||
# Linear complexity
|
||||
# Linear order
|
||||
linear(n)
|
||||
linear_recur(n)
|
||||
# Quadratic complexity
|
||||
# Quadratic order
|
||||
quadratic(n)
|
||||
quadratic_recur(n)
|
||||
# Exponential complexity
|
||||
# Exponential order
|
||||
root = build_tree(n)
|
||||
print_tree(root)
|
||||
|
||||
Reference in New Issue
Block a user