简体   繁体   English

如何解决递归T(n)= T(n-1)+…T(1)+1?

[英]How to solve the recurrence T(n)=T(n-1) + … T(1) +1?

I need to find the complexity of an algorithm that involves the recurrence: 我需要找到涉及递归的算法的复杂性:

T(n) = T(n-1) + ... + T(1) + 1

T(n) is the time it takes to solve a problem of size n . T(n)是解决大小为n的问题所花费的时间。

The master method doesn't apply here and I can't make a guess to use the substitution method (I don't want to use the substitution method anyway). 主方法不适用于此处,我无法猜测使用替代方法(无论如何我都不想使用替代方法)。 I'm left with recursion tree method. 我剩下的是递归树方法。

Since the number of children of each node isn't a constant, I'm finding it hard to keep track of how much each node contributes. 由于每个节点的子节点数量不是恒定的,因此我很难跟踪每个节点的贡献量。 What is the underlying pattern? 潜在的模式是什么?

I understand that I have to find the number of nodes in a tree in which each node ( k ) has for its children all nodes numbered from 1 to k-1 . 我知道我必须找到树中的节点数,其中每个节点( k )的子节点都有从1到k-1编号的所有节点。

Is it also possible to find the exact time T(n) given that formula? 给定该公式,是否还可以找到准确的时间T(n)

Since T(n-1) = T(n-2) + ... + T(1) + 1 由于T(n-1) = T(n-2) + ... + T(1) + 1

T(n) = T(n-1) + T(n-2) + ... + T(1) + 1
     = T(n-1) + T(n-1)
     = 2*T(n-1)

and T(1) = 1 => T(n) = 2^(n-1) T(1) = 1 => T(n) = 2^(n-1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM