1 1 vote What is the order of growth of $\texttt{foo}$ in terms of $\texttt{n}$, where $\texttt{n}$ is the length of $\texttt{lst}$?Assume slicing a list and calling $\texttt{len}$ both take constant time.def foo(lst, i): mid = len(lst) // 2 if mid == 0: return lst elif i > 0: return foo(lst[mid:], -1) else: return foo(lst[:mid], 1)What is the tight order of growth?$\Theta(\log n)$$\Theta(n)$$\Theta(n \log n)$$\Theta(n^2)$ Algorithms goclasses goclasses-da-dpp goclasses-da-dpp-day-217 python-&-dsa goclasses-python-&-dsa-practice-questions time-complexity + – GO Classes 113 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
1 1 vote In each call, only one recursive call is made.The input list is reduced to half:$n \rightarrow n/2 \rightarrow n/4 \rightarrow n/8 \rightarrow ... \rightarrow 1$The number of times we can divide $n$ by $2$ before reaching $1$ is $\log n$.Since each call does constant work, the total complexity is:$\Theta(\log n)$Correct Answer: A GO Classes answered Jul 6 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Each step reduces the remaining search space by half. That gives us logarithmic time. For tight order of growth, we can see that it cannot take less than logarithmic time because the halving is never shortcircuited to constant work. And it will never take more than logarithmic time because each step definitely halves the search space. So we get $\Theta(\log n)$ Answer: A Meticulous_March answered Jul 6 • edited Jul 6 by Meticulous_March Meticulous_March comment Share Follow 0 reply Please log in or register to add a comment.