scheme - 查找调用许多过程的过程的增长顺序

标签 scheme lisp big-o sicp

这段代码创建了一个平衡二叉搜索树,它是两个平衡二叉搜索树的交集。

(define (intersection-tree t1 t2)
    (list->tree (intersection-set (tree->list-2 t1) (tree->list-2 t2))))
  • tree->list-2 将树展平为有序集。它需要 Theta(N)。
  • intersection-settakes takes takes two sets and creates a new set with the intersection of the 两个输入集。它需要 Theta(N)。
  • list->tree 将新创建的集合变成平衡的二叉搜索树。取 Theta(N)。

也就是说,我有一个过程调用 4 个采用 Theta(N) 的过程(列表-> 树、交叉集、两个树-> 列表)。我猜所有这些都需要 4N。忽略常数因子,它变成 Theta(N)。说相交树过程采用 Theta(N) 是否正确?

最佳答案

您的猜测是正确的,因为在您的函数中每个子任务仅执行一次,使用 Theta(N),对于恒定次数,交集树过程使用 Theta(N)。

关于scheme - 查找调用许多过程的过程的增长顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34960540/

相关文章:

macros - Racket 中的宏定义宏?

lisp - 根据列表中的对添加两个或多个列表

math - LDL 形式的 Cholesky 分解的时间复杂度

c++ - C++中的小型可读方案解释器?

Emacs lisp 定义语法

delphi - 使用FPC : Recursive data structures编写Scheme解释器

algorithm - 就您的计算方式而言,冒泡排序算法的时间复杂度如何导致 O(n^2)?

scheme - Lisp/Scheme 中的引号与字符串相同吗?

string - 循环遍历 lisp 中的字符串以获取字母字符或空格

python - 如果 n 是正整数,Max(n, log(n, 2)) 应该返回 n 吗?