Find function complexity

is find function equivalent to linear search?

am i supposed to use binary_search function here?..but it returns bool value…how to get index?

hi @akshitabansal321 u can use lower bound to get the first occurance of the value once u are sure the elemnt exits by binary_search function

For an array of size 1024, you can make 10 comparisons at maximum…does lower_bound function fulfill this condition?

yep, it uses binary search @akshitabansal321

why can’t we use only lower_bound function here?

suppose if the element is not there then it will return index of elemnt just greater than lower bound, so its better to check if exists then print the index else print -1 @akshitabansal321

and what about find function? why can’t we use find function only?

@akshitabansal321 its o(n)

ok. got it. thankyou

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.