mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 22:34:18 +08:00
Bug fixes and improvements (#1380)
* preorder, inorder, postorder -> pre-order, in-order, post-order * Bug fixes * Bug fixes * Update what_is_dsa.md * Sync zh and zh-hant versions * Sync zh and zh-hant versions. * Update performance_evaluation.md and time_complexity.md * Add @khoaxuantu to the landing page. * Sync zh and zh-hant versions * Add @ khoaxuantu to the landing page of zh-hant and en versions.
This commit is contained in:
@ -97,7 +97,9 @@ def linear_log_recur(n: int) -> int:
|
||||
"""线性对数阶"""
|
||||
if n <= 1:
|
||||
return 1
|
||||
count: int = linear_log_recur(n // 2) + linear_log_recur(n // 2)
|
||||
# 一分为二,子问题的规模减小一半
|
||||
count = linear_log_recur(n // 2) + linear_log_recur(n // 2)
|
||||
# 当前子问题包含 n 个操作
|
||||
for _ in range(n):
|
||||
count += 1
|
||||
return count
|
||||
@ -120,32 +122,32 @@ if __name__ == "__main__":
|
||||
n = 8
|
||||
print("输入数据大小 n =", n)
|
||||
|
||||
count: int = constant(n)
|
||||
count = constant(n)
|
||||
print("常数阶的操作数量 =", count)
|
||||
|
||||
count: int = linear(n)
|
||||
count = linear(n)
|
||||
print("线性阶的操作数量 =", count)
|
||||
count: int = array_traversal([0] * n)
|
||||
count = array_traversal([0] * n)
|
||||
print("线性阶(遍历数组)的操作数量 =", count)
|
||||
|
||||
count: int = quadratic(n)
|
||||
count = quadratic(n)
|
||||
print("平方阶的操作数量 =", count)
|
||||
nums = [i for i in range(n, 0, -1)] # [n, n-1, ..., 2, 1]
|
||||
count: int = bubble_sort(nums)
|
||||
count = bubble_sort(nums)
|
||||
print("平方阶(冒泡排序)的操作数量 =", count)
|
||||
|
||||
count: int = exponential(n)
|
||||
count = exponential(n)
|
||||
print("指数阶(循环实现)的操作数量 =", count)
|
||||
count: int = exp_recur(n)
|
||||
count = exp_recur(n)
|
||||
print("指数阶(递归实现)的操作数量 =", count)
|
||||
|
||||
count: int = logarithmic(n)
|
||||
count = logarithmic(n)
|
||||
print("对数阶(循环实现)的操作数量 =", count)
|
||||
count: int = log_recur(n)
|
||||
count = log_recur(n)
|
||||
print("对数阶(递归实现)的操作数量 =", count)
|
||||
|
||||
count: int = linear_log_recur(n)
|
||||
count = linear_log_recur(n)
|
||||
print("线性对数阶(递归实现)的操作数量 =", count)
|
||||
|
||||
count: int = factorial_recur(n)
|
||||
count = factorial_recur(n)
|
||||
print("阶乘阶(递归实现)的操作数量 =", count)
|
||||
|
Reference in New Issue
Block a user