Linear Search
Linear Search
Time Complexity:
Best Case (O(1)) → If the target is the first element.
Worst Case (O(n)) → If the target is at the end or not present.
Average Case (O(n)) → On average, it checks half the elements.
Implementation in JavaScript
Pros & Cons
✅ Pros:
✔ Works on both sorted and unsorted arrays.
✔ Easy to implement.
✔ No extra space required (in-place search).
❌ Cons:
❌ Slow for large datasets.
❌ Not efficient compared to binary search for sorted data.
Company: Google
Software: Google Chrome (Web Browser)
Source: chatGPT.