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:
Yudong Jin
2024-05-31 16:39:06 +08:00
committed by GitHub
parent 39a6890b7e
commit 3f4220de81
91 changed files with 1709 additions and 181 deletions

View File

@ -90,11 +90,11 @@ int main() {
/* 获取栈的长度 */
int size = stack->size;
printf("栈的长度 size = %d\n", size);
printf("栈的长度 size = %d\n", size);
/* 判断是否为空 */
bool empty = isEmpty(stack);
printf("栈是否为空 = %stack\n", empty ? "true" : "false");
printf("栈是否为空 = %s\n", empty ? "true" : "false");
// 释放内存
delArrayStack(stack);

View File

@ -19,7 +19,7 @@ fun merge(nums: IntArray, left: Int, mid: Int, right: Int) {
while (i <= mid && j <= right) {
if (nums[i] <= nums[j])
tmp[k++] = nums[i++]
else
else
tmp[k++] = nums[j++]
}
// 将左子数组和右子数组的剩余元素复制到临时数组中

View File

@ -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)

View File

@ -5,7 +5,7 @@ Author: Xuan Khoa Tu Nguyen (ngxktuzkai2000@gmail.com)
=end
### 带约束爬楼梯:动态规划 ###
def climbing_stairs_backtrack(n)
def climbing_stairs_constraint_dp(n)
return 1 if n == 1 || n == 2
# 初始化 dp 表,用于存储子问题的解
@ -26,6 +26,6 @@ end
if __FILE__ == $0
n = 9
res = climbing_stairs_backtrack(n)
res = climbing_stairs_constraint_dp(n)
puts "#{n} 阶楼梯共有 #{res} 种方案"
end