0 0 votes What is the order of growth of $\texttt{foo}$ in terms of $\texttt{n}$, where $\texttt{n}$ is the length of $\texttt{lst}$?Assume that slicing a list and calling $\texttt{len}$ on a list can both be done in 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)$\mathrm{\Theta(1)}$$\mathrm{\Theta(log n)}$$\mathrm{\Theta(n)}$$\mathrm{\Theta(n log n)}$$\mathrm{\Theta(n²)}$ Algorithms goclasses goclasses-da-dpp goclasses-da-dpp-day-216 python-&-dsa goclasses-python-&-dsa-practice-questions + – GO Classes 130 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes In every recursive call, the function keeps only half of the list.$\texttt{foo(lst[mid:], -1)}$or:$\texttt{foo(lst[:mid], 1)So the input size changes like this:$\texttt{n -> n/2 -> n/4 -> n/8 -> ... -> 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 order of growth is:$\mathrm{\Theta(log n)}$Therefore, the correct option is B. GO Classes answered Jul 4 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Answer: B Meticulous_March answered Jul 5 Meticulous_March comment Share Follow 0 reply Please log in or register to add a comment.