Which of the following algorithm structures would lead to the recurrence equation T(n) = T(n-1)+O(1), for the worst-case time cost on data of size n?单项选择题
登录即可查看完整答案
我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。
类似问题
What is the asymptotic behavior of T(n) = T(n/2) + O(1)? Select the tightest bound that holds.
Given the following pseudocode, derive the recurrence relation that represents its time complexity. def fibonacci(n): if (n==0 or n==1): return n return fibonacci(n - 1) + fibonacci(n - 2)Let b and c represent constant values. What is the base case and recurrence step?
Question textConsider the following algorithm. Assume the input is a positive integer. [table] 1 2 3 4 5678 | function FUNC(n) if n < 4 then return 3 * n else count = 0 for i = 1 to n do count = count + i return count + FUNC(n/4) * FUNC(n/4) [/table] The recurrence relation for the running time of this function can be expressed as , where and are expressions and and are their conditions under which they apply. Fill in the correct general case and base case to replace X/X' and Y/Y' below (no need to solve the relation, or give its time complexity). You may assume that a, b, c, d, e and f are constants of your choosing should you need them for the recurrence. Do not forget to include the condition on where each case would be applicable in the box on the right. General case (X if X'): Answer 1 Question 1[input] if Answer 2 Question 1[input] Base case (Y if Y'): Answer 3 Question 1[input] if Answer 4 Question 1[input]
The function ComputeSum receives a positive integer n as the input and returns the value ComputeSum(n) If n = 1, then Return(3) y := ComputeSum(n - 1) Return( ? ) What is the correct value for the algorithm to return?
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!