设n是描述问题规模的非负整数,下面程序片段的时间复杂度是()。x=2;while

题库2022-08-02  31

问题 设n是描述问题规模的非负整数,下面程序片段的时间复杂度是()。x=2;while(x大于n/2)x=2*x;A.O(log2n)B.O(n)C.O(nlog2n)D.O(n^2)

选项 A.O(log2n)
B.O(n)
C.O(nlog2n)
D.O(n^2)

答案 A

解析 程序中执行最多的语句是“x=2*x”,也就是意味着2^x=n,求x。
转载请注明原文地址:https://tihaiku.com/congyezige/2408417.html

最新回复(0)