Polish the chapter

introduction, computational complexity.
This commit is contained in:
krahets
2023-08-20 14:51:39 +08:00
parent 5fb728b3d6
commit 2626de8d0b
87 changed files with 375 additions and 371 deletions

View File

@@ -160,35 +160,35 @@ public class time_complexity {
Console.WriteLine("输入数据大小 n = " + n);
int count = constant(n);
Console.WriteLine("常数阶的计算操作数量 = " + count);
Console.WriteLine("常数阶的操作数量 = " + count);
count = linear(n);
Console.WriteLine("线性阶的计算操作数量 = " + count);
Console.WriteLine("线性阶的操作数量 = " + count);
count = arrayTraversal(new int[n]);
Console.WriteLine("线性阶(遍历数组)的计算操作数量 = " + count);
Console.WriteLine("线性阶(遍历数组)的操作数量 = " + count);
count = quadratic(n);
Console.WriteLine("平方阶的计算操作数量 = " + count);
Console.WriteLine("平方阶的操作数量 = " + count);
int[] nums = new int[n];
for (int i = 0; i < n; i++)
nums[i] = n - i; // [n,n-1,...,2,1]
count = bubbleSort(nums);
Console.WriteLine("平方阶(冒泡排序)的计算操作数量 = " + count);
Console.WriteLine("平方阶(冒泡排序)的操作数量 = " + count);
count = exponential(n);
Console.WriteLine("指数阶(循环实现)的计算操作数量 = " + count);
Console.WriteLine("指数阶(循环实现)的操作数量 = " + count);
count = expRecur(n);
Console.WriteLine("指数阶(递归实现)的计算操作数量 = " + count);
Console.WriteLine("指数阶(递归实现)的操作数量 = " + count);
count = logarithmic((float)n);
Console.WriteLine("对数阶(循环实现)的计算操作数量 = " + count);
Console.WriteLine("对数阶(循环实现)的操作数量 = " + count);
count = logRecur((float)n);
Console.WriteLine("对数阶(递归实现)的计算操作数量 = " + count);
Console.WriteLine("对数阶(递归实现)的操作数量 = " + count);
count = linearLogRecur((float)n);
Console.WriteLine("线性对数阶(递归实现)的计算操作数量 = " + count);
Console.WriteLine("线性对数阶(递归实现)的操作数量 = " + count);
count = factorialRecur(n);
Console.WriteLine("阶乘阶(递归实现)的计算操作数量 = " + count);
Console.WriteLine("阶乘阶(递归实现)的操作数量 = " + count);
}
}

View File

@@ -8,7 +8,7 @@ namespace hello_algo.chapter_heap;
/* 大顶堆 */
class MaxHeap {
// 使用列表而非数组,这样无考虑扩容问题
// 使用列表而非数组,这样无考虑扩容问题
private readonly List<int> maxHeap;
/* 构造函数,建立空堆 */
@@ -70,7 +70,7 @@ class MaxHeap {
while (true) {
// 获取节点 i 的父节点
int p = parent(i);
// 若“越过根节点”或“节点无修复”,则结束堆化
// 若“越过根节点”或“节点无修复”,则结束堆化
if (p < 0 || maxHeap[i] <= maxHeap[p])
break;
// 交换两节点

View File

@@ -18,7 +18,7 @@ public class heap_sort {
ma = l;
if (r < n && nums[r] > nums[ma])
ma = r;
// 若节点 i 最大或索引 l, r 越界,则无继续堆化,跳出
// 若节点 i 最大或索引 l, r 越界,则无继续堆化,跳出
if (ma == i)
break;
// 交换两节点

View File

@@ -84,7 +84,7 @@ class AVLTree {
return leftRotate(node);
}
}
// 平衡树,无旋转,直接返回
// 平衡树,无旋转,直接返回
return node;
}