Choose the correct output and time complexity for the following code :
list< int > myList = { 2, 6, 12, 13, 15, 18, 20};
cout << binary_search(myList.begin(), myList.end(), 20) ;
shoudnt the time complexity be lograthmic and not linear
Choose the correct output and time complexity for the following code :
list< int > myList = { 2, 6, 12, 13, 15, 18, 20};
cout << binary_search(myList.begin(), myList.end(), 20) ;
shoudnt the time complexity be lograthmic and not linear
Since you are given a list, you cannot find the middle node(As is binary search) in constant time. You have to traverse the list in order to find the middle node. This is why complexity is linear.
If it was an array, then the complexity would be logarithmic.
oh alright thanks i will read more about list ds