Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Linear Search

1 topic · 28 Nov 2026
1

Linear Search

Algorithm › Search

Check each element one by one. Works on unsorted data. Time O(n), space O(1).

C++
int linearSearch(int arr[], int n, int key) {
    for (int i = 0; i < n; i++)
        if (arr[i] == key) return i;   // found: return index
    return -1;                         // not found
}