how to use binary search stl to search in half part of array only like from 0 to mid-1?
How to use binary search stl to search in half part of array only like from 0 to mid-1?
hello @Prabhleen_sheenu
it should be
for array
binary_search(a,a+mid,key);
for vector
binary_search(a.begin(),a.begin()+mid,key);
sir ,please check this code.in line 20,25 i want to use binary search stl output should be 1 but output is 0.
thank you 
you can not apply binary search directly because array is not sorted.
also binary search stl work only on sorted array.
from a[0] to a[pivot -1] and a[pivot] to a[n-1] arrays are sorted
so can we apply binary search in two parts?
for that u need to find pivot and then u can use bsearch
yes sir i have find the value of pivot. my doubt is how to use binary search stl in this case? please check line 20,25 of my code.pivot value is in line 14. thank you 
u were comparing index with key but actuall u should compare values present at that indexes
corrected line ->
![]()
sorry my mistake.
sir can you please tell me how can i modify my line 20,25 so that output is index of the element searched
Sample Input
5 4 5 1 2 3 2
Sample Output
3
just increment ur pivot value by 1 and it will work.
sorry to bother you sir but the code is not working for this test case and the other test case of the question.can you please explain why the output is 0
Sample Input
5 4 5 1 2 3 2
Sample Output
3
your find index is not working correctly,
it is giving 0 as pivot,
correct it
sir i think the output is 0 because of return -1 in line 28 but if i do not write it then warning: control reaches end of non-void function [-Wreturn-type] . please help
check this->
ohh nice. Thank you sir 