Linear Search is the simplest searching algorithm that checks each element of the list sequentially until the desired element is found or the list ends.
int linearSearch(int arr[], int n, int key) {
for (int i = 0; i < n; i++) {
if (arr[i] == key)
return i;
}
return -1;
}
Linear search is suitable for small or unsorted datasets but is inefficient when data size increases.
Take quizzes related to this topic and see where you stand!
Start Quiz Now