小编RB2*_*633的帖子

时间复杂度:嵌套“if-then-else”

我已经在Scheme 中编写了一个递归程序,但我无法获得它的时间复杂度。我相信结果是 O(log(n)),但我绝对不是这个时间复杂度的专家。你能帮我试着解决这个问题的复杂性吗?

这是我的伪代码:

function A {

for (int i = 0; i < length.list(); i++)
{
    if (list is null)
        output absolute value of result

    if (s2 < s1)
        recall function A, adding item to s2 value.
    else
        recall function A, adding item to s1 value.
}

}
Run Code Online (Sandbox Code Playgroud)

这是 Scheme 中的实际代码:

(define min-split (lambda (L s1 s2 mini)
           (cond 

             ((null? L)
              (if (> 0 mini)

                  (min-split L s1 s2 (- mini (+ mini mini)))

                  mini
                  )
                mini …
Run Code Online (Sandbox Code Playgroud)

time complexity-theory big-o if-statement

4
推荐指数
1
解决办法
6652
查看次数

标签 统计

big-o ×1

complexity-theory ×1

if-statement ×1

time ×1