Suppose :
int arr[10]; // you have O(n ) linear algorithm for search
but when you use :
std::vector<int> V;
Question is : What's Algorithm complexity for searching behind of impelentation of vector?
Suppose :
int arr[10]; // you have O(n ) linear algorithm for search
but when you use :
std::vector<int> V;
Question is : What's Algorithm complexity for searching behind of impelentation of vector?
Searching in an array and std::vector
is O( n )
not O( log n )
O( log n )
will be achieved only when array/std::vector
is sorted.
std::vector
implementation doesn't include any searching algorithm, however to get O( log n )
you first need to sort it and then perform binary search, this is same as with an array too.