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

@ -124,32 +124,32 @@ const n = 8;
console.log('输入数据大小 n = ' + n);
let count = constant(n);
console.log('常数阶的计算操作数量 = ' + count);
console.log('常数阶的操作数量 = ' + count);
count = linear(n);
console.log('线性阶的计算操作数量 = ' + count);
console.log('线性阶的操作数量 = ' + count);
count = arrayTraversal(new Array(n));
console.log('线性阶(遍历数组)的计算操作数量 = ' + count);
console.log('线性阶(遍历数组)的操作数量 = ' + count);
count = quadratic(n);
console.log('平方阶的计算操作数量 = ' + count);
console.log('平方阶的操作数量 = ' + count);
let nums = new Array(n);
for (let i = 0; i < n; i++) nums[i] = n - i; // [n,n-1,...,2,1]
count = bubbleSort(nums);
console.log('平方阶(冒泡排序)的计算操作数量 = ' + count);
console.log('平方阶(冒泡排序)的操作数量 = ' + count);
count = exponential(n);
console.log('指数阶(循环实现)的计算操作数量 = ' + count);
console.log('指数阶(循环实现)的操作数量 = ' + count);
count = expRecur(n);
console.log('指数阶(递归实现)的计算操作数量 = ' + count);
console.log('指数阶(递归实现)的操作数量 = ' + count);
count = logarithmic(n);
console.log('对数阶(循环实现)的计算操作数量 = ' + count);
console.log('对数阶(循环实现)的操作数量 = ' + count);
count = logRecur(n);
console.log('对数阶(递归实现)的计算操作数量 = ' + count);
console.log('对数阶(递归实现)的操作数量 = ' + count);
count = linearLogRecur(n);
console.log('线性对数阶(递归实现)的计算操作数量 = ' + count);
console.log('线性对数阶(递归实现)的操作数量 = ' + count);
count = factorialRecur(n);
console.log('阶乘阶(递归实现)的计算操作数量 = ' + count);
console.log('阶乘阶(递归实现)的操作数量 = ' + count);

View File

@ -70,7 +70,7 @@ class MaxHeap {
while (true) {
// 获取节点 i 的父节点
const p = this.#parent(i);
// 当“越过根节点”或“节点无修复”时,结束堆化
// 当“越过根节点”或“节点无修复”时,结束堆化
if (p < 0 || this.#maxHeap[i] <= this.#maxHeap[p]) break;
// 交换两节点
this.#swap(i, p);
@ -102,7 +102,7 @@ class MaxHeap {
let ma = i;
if (l < this.size() && this.#maxHeap[l] > this.#maxHeap[ma]) ma = l;
if (r < this.size() && this.#maxHeap[r] > this.#maxHeap[ma]) ma = r;
// 若节点 i 最大或索引 l, r 越界,则无继续堆化,跳出
// 若节点 i 最大或索引 l, r 越界,则无继续堆化,跳出
if (ma === i) break;
// 交换两节点
this.#swap(i, ma);

View File

@ -17,7 +17,7 @@ function siftDown(nums, n, i) {
if (r < n && nums[r] > nums[ma]) {
ma = r;
}
// 若节点 i 最大或索引 l, r 越界,则无继续堆化,跳出
// 若节点 i 最大或索引 l, r 越界,则无继续堆化,跳出
if (ma === i) {
break;
}

View File

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