This is a C Program to implement Linear Search Algorithm to find the minimum element in an array.

We have to create a C Program which finds the minimum element in an array using Linear Search Algorithm. We have to create a linear search function which will have array and its size as parameters and return the element whose value is smallest in the array.

**1. Average case: ** When the array size is more than 1 we have to traverse the whole array to find the minimum element.

If the input array has the data as {4, 6, 1, 2, 5, 3} then the minimum element in this array will be 1

**Average case time complexity: O(n)**

**2. Best Case:** When the array has only one element, so that will be the minimum.

If the input array has the data as {-3} then the minimum element in this array will be -3

**Best case time complexity: O(1)**

1. We first have to create an array of numbers by taking input from user. We have to input an array of numbers and then apply the linear search algorithm to find the minimum value element in an array.

2. In order to find out the minimum element from the array of numbers we assume the first element of an array to be the minimum.

3. After that we traverse the whole array from the beginning and if we encounter any element whose value is less than the value of the first element we’ll put that element as minimum element.

4. This process will continue till we have compared all the elements with each other. As a last step we return the smallest element from the array.

Here is source code of the C Program to find the minimum element in an array using Linear Search Algorithm. The program is successfully compiled and tested using Codeblocks gnu/gcc compiler on Windows 10. The program output is also shown below.

`/* C program to find the minimum element in an array using Linear Search */`

`#include <stdio.h>`

int min_linearsearch(int numbers[], int n)

`{`

int min = numbers[0];

int i;

for (i = 1; i <= n; i++)

`{`

if (min > numbers[i])

min = numbers[i];

`}`

return min;

`}`

int main() {

int n;

printf("Enter number of elements in array: ");

scanf("%d",&n);

int numbers[n];

int i;

int min ;

printf("Enter %d numbers : ", n);

printf("\n");

for (i = 0; i < n; i++)

`{`

scanf("%d", &numbers[i]);

`}`

min = min_linearsearch(numbers,n);

printf("\nMinimum number in the array is : %d\n", min);

return 0;

`}`

1. In Linear search, we search an element or value in a given array by traversing the array from the starting, till the desired element or value is found.

2. The array is searched sequentially and the position is returned if the key element to be searched is available in the array, otherwise -1 is returned.

3. Here in this C Program we have first created the array, after that we have assumed first element of array to be minimum.

4. We traverse the whole array and compare that element with rest of the elements in array and return the smallest element in the array using function **min_linearsearch(int numbers[]).**

1. Enter number of elements in array: 6 Enter 6 numbers : 4 6 1 2 5 3 Minimum number in the array is : 1 2. Enter number of elements in array: 1 Enter 1 numbers : -3 Minimum number in the array is : -3

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Books in C Programming, Data Structures and Algorithms.

**If you find any mistake above, kindly email to [email protected]**

**Related Posts:**

- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Check Computer Science Books
- Practice Computer Science MCQs
- Check C Books