手机扫码访问

导航
您当前的位置:首页 > 高教类 > 工学类
问题:

[单选题]

Li Lei and Han Meimei have different opinions regarding the linear time complexity in the video lecture.对于视频中线性递归的时间复杂度,A、B两位同学有不同的看法。f4n答案窝(daanwo.com)-大学作业答案分享平台

Li Lei aggrees to the video, the complexity is O(n) because there are n instances each requiring O(1) execution time. A同学赞同视频中的算法,由于单个递归实例需要O(1)时间完成,共有n个实例,所以整个算法的复杂度是O(n)。f4n答案窝(daanwo.com)-大学作业答案分享平台

However, Han Meimei believes the time for sum(A,n) to be O(n) instead of O(1), since it's still executing even when calling sum(A,n-1), leading to a total time complexity of (n+n−1+...+3+2+1=O(n2. You agree with 但B同学认为,当sum(A,n)函数中调用sum(A,n-1)时,sum(A,n)仍在执行,因此sum(A,n)的完成时间不是O(1)而是O(n),依此计算,整个算法的复杂度应该为()。n+n−1+...+3+2+1=O(n2)。请问哪位同学对了?f4n答案窝(daanwo.com)-大学作业答案分享平台

ALi Lei A同学f4n答案窝(daanwo.com)-大学作业答案分享平台

BHan Meimei B同学f4n答案窝(daanwo.com)-大学作业答案分享平台

答案解析:

相关问题
关于我们 | 用户指南 | 版权声明 | 给我留言 | 联系我们 | 积分商城 | 答案求助 | 网站地图
Copyright © 2020 www.daanwo.com All Rights Reserved