mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 00:56:29 +08:00
build
This commit is contained in:
parent
8843a93605
commit
ca49da47f0
2 changed files with 2 additions and 28 deletions
|
@ -2548,7 +2548,7 @@ $$
|
|||
|
||||
对数阶常出现于基于分治策略的算法中,体现了“一分为多”和“化繁为简”的算法思想。它增长缓慢,是仅次于常数阶的理想的时间复杂度。
|
||||
|
||||
!!! tip
|
||||
!!! tip "$O(\log n)$ 的底数是多少?"
|
||||
|
||||
准确来说,“一分为 $m$”对应的时间复杂度是 $O(\log_m n)$ 。而通过对数换底公式,我们可以得到具有不同底数的、相等的时间复杂度:
|
||||
|
||||
|
|
|
@ -1333,33 +1333,7 @@ comments: true
|
|||
=== "Dart"
|
||||
|
||||
```dart title="binary_search_tree.dart"
|
||||
/* 插入节点 */
|
||||
void insert(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (_root == null) return;
|
||||
TreeNode? cur = _root;
|
||||
TreeNode? pre = null;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != null) {
|
||||
// 找到重复节点,直接返回
|
||||
if (cur.val == num) return;
|
||||
pre = cur;
|
||||
// 插入位置在 cur 的右子树中
|
||||
if (cur.val < num)
|
||||
cur = cur.right;
|
||||
// 插入位置在 cur 的左子树中
|
||||
else
|
||||
cur = cur.left;
|
||||
}
|
||||
// 插入节点
|
||||
TreeNode? node = TreeNode(num);
|
||||
if (pre!.val < num)
|
||||
pre.right = node;
|
||||
else
|
||||
pre.left = node;
|
||||
}
|
||||
|
||||
/* 删除节点 */
|
||||
/* 删除节点 */
|
||||
void remove(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (_root == null) return;
|
||||
|
|
Loading…
Reference in a new issue