what is the best method for search if the elements are not in sorted order. Which will take less time complexity?/
Search best method
Hey @yeswanth9487 if an arr in unsorted then the only way to find an element is linear search which has a time complexity of O(n).
if we use stl find is it will take less time than linear search?
For an unsorted array i think there is not stl. If its there can you please share me the code i will tell you.
#include <bits/stdc++.h> using namespace std; int main() { int a[]={1,5,2,6,3}; auto k=find(a,a+5,6); cout<<k-a; }
Ok okk the time complexity for find() function is O(log N) better the linear search.