Professional Documents
Culture Documents
Linear Search: Data Structure and Algorithm
Linear Search: Data Structure and Algorithm
Linear Search: Data Structure and Algorithm
return -1; else cout << “Element is present at index “ << result;
} return 0;
int main(void)
TIME COMPLEXITY
A linear search scans one item at a time, without jumping to any item
The worst case complexity is O(n), sometimes known an O(n) search
Time taken to search elements keep increasing as the number of elements are
increased.
Worst-case performance
O(n)
Best-case performance
O(1)
Average performance
O(n/2)