STL Algorithms QUIZ

STL Algorithms QUIZ - Q.2

Time complexity of Binary search is O(log(n)) but in the answer it is given that time complexity linear in the size of list
which is O(n). I am not able to understand it .

Time complexity of Binary in list or linked list is linear. This is because we need last element and to find index of last element in linked list takes o(n) time (In array takes o(1) times), Thats why in only and only list, BS takes o(n) time. Thats why BS is not preferable on lists.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.