private void listAll( int depth )
{
printName( depth ); // Print the name of the object
if( isDirectory( ) )
for each file c in this directory (for each child)
c.listAll( depth + 1 );
}
我尝试使用递归关系来诱导运行时间
正确的运行时间是 O(N)
我的分析表明它将是 O(N^2)
这是我的归纳
1. T(0) = (第一行) O(1)+(第二行) O(1)+(我们假设的孩子数是 N) N*(T(1)
2. T(0 ) = (第一行) O(1)+(第二行) O(1)+ N*(O(1)+O(1)+ N*(T(2))
3 随着这个归纳的进行,运行时间将是某种 O(N^2)
我的分析有什么问题???