Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions searching_algorithms/LinearSearch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# Linear Search is defined as a sequential search algorithm that starts at one end and goes through each element of a list until the desired element is found.
# Time complexity: O(N)


void linearSearch(int arr[], int n, int search)
{
int i;
for (i = 0; i < n; i++)
{
if (arr[i] == search)
{
printf("Element found at location: %d\n", i + 1);
break;
}
}
if (i == n)
{
printf("Not Found!\n");
}
}