题目
单项选择题
Recr_4 Identify the recurrence relation for the binary_search function described below, which recursively searches for a value in a sorted list.
选项
A.T(n) = \begin{cases} \Theta(1) & \text{if } n <2 \\2T\left(n-1\right) + \Theta(1) & \text{otherwise}\end{cases}
B.T(n) = \begin{cases} \Theta(1) & \text{if } n <2 \\T\left(n-1\right) + \Theta(n) & \text{otherwise}\end{cases}
C.T(n) = \begin{cases} \Theta(1) & \text{if } n <2 \\2T\left(\frac{n}{2}\right) + \Theta(1) & \text{otherwise}\end{cases}
D.T(n) = \begin{cases} \Theta(1) & \text{if } n <2 \\T\left(\frac{n}{2}\right) + \Theta(1) & \text{otherwise}\end{cases}
E.T(n) = \begin{cases} \Theta(1) & \text{if } n <2 \\T\left(\frac{n}{2}\right) + \Theta(n) & \text{otherwise}\end{cases}
F.T(n) = \begin{cases} \Theta(1) & \text{if } n <2 \\T\left(n-1\right) + \Theta(1) & \text{otherwise}\end{cases}
查看解析
标准答案
Please login to view
思路分析
To begin, restate what is being asked: identify the recurrence relation for a binary_search function that recursively searches a sorted list.
Option 1 evaluates the cost as 2T(n-1) + Θ(1). This would correspond to two recursive calls on size n-1, which is not how binary search operates; binary search halves the problem size, not processes two nearly full-sized subproblems. Therefore this option mischaracterizes the branching factor.
Option 2 proposes T(n-1) + Θ(n). Here the non-recursive ......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
Recr_Q_6 What is the recurrence relation for the quick_sort function given below in the average case scenario as described below?
Ms_7 Consider the recurrence relation for recursive algorithm \(T(n)\) given by: T(n) = \begin{cases} \Theta(1) & \text{if } n < 2 \\9T\left(\frac{n}{3}\right) + \Theta(n) & \text{otherwise}\end{cases} What is the run time complexity of this algorithm? The Master Theorem is provided below. Use it as you see fit:
Recr_12 Identify the recurrence relation for the function shown below.
zyBooks_17_1 Suppose a recursive function's runtime is T(n−1)+Θ(n){"version":"1.1","math":"T(n-1) + \Theta(n)"} How many levels will the recursion tree have?
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!