970 views
3 votes
3 votes
I am having a doubt in this question.

The binary search algorithm is implemented using recursion. Then the space complexity is :-

(1) O( 1 )

(2) O( n )

(3) O( logn )

(4) O(n logn )

According to me, the answer should be option 2.

Please explain the solution as well.

1 Answer

–1 votes
–1 votes
As question is talking about space complexity of binary search algo it would be O(1). it dosen't take any extra space to perform search because we have to apply Binary search algo on given input of array with distinct and sorted elements.

 

Space Complexity refers to the magnitude of auxiliary space your program takes to process the input. That is after main() how much extra space it is taking.

Related questions

5 votes
5 votes
2 answers
1
Shivani gaikawad asked Aug 17, 2018
1,015 views
What is the space complexity of the following code?$O(logn)$ $O(n)$$O(nlogn)$ $O(1)$
0 votes
0 votes
0 answers
3
rahul sharma 5 asked Dec 8, 2016
701 views
What is the best case and worst case time complexity for Euclid's algorithm?Let numbers be a and bAs per my understandingBest case - If a and b are multiple :0(1).Worst c...