0% found this document useful (0 votes)
5 views2 pages

9. Implement Linear Search Algorithm

The document outlines an experiment to implement the Linear Search Algorithm using 'C' programming. It explains the concept of searching for an element in a list, differentiating between successful and unsuccessful searches, and introduces both Linear and Binary Search methods. The provided program demonstrates how to perform a linear search on an unordered list and outputs the location of the searched item or indicates if it is not found.

Uploaded by

tuba.khan7575
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

9. Implement Linear Search Algorithm

The document outlines an experiment to implement the Linear Search Algorithm using 'C' programming. It explains the concept of searching for an element in a list, differentiating between successful and unsuccessful searches, and introduces both Linear and Binary Search methods. The provided program demonstrates how to perform a linear search on an unordered list and outputs the location of the searched item or indicates if it is not found.

Uploaded by

tuba.khan7575
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT NO.

9
Aim: Implement Linear Search Algorithm.

LO:LO4: Students will be able to select appropriate searching techniques for given problems

Software: ‘C’ Programming

Theory: Searching is the process of finding some particular element in the list. If the element is
present in the list, then the process is called successful and the process returns the location of that
element, otherwise the search is called unsuccessful.
There are two popular search methods that are widely used in order to search some item into the list.
However, choice of the algorithm depends upon the arrangement of the list.
 Linear Search
 Binary Search

Linear Search: Linear search is the simplest search algorithm and often called sequential search. In
this type of searching, we simply traverse the list completely and match each element of the list with
the item whose location is to be found. If the match found then location of the item is returned
otherwise the algorithm return NULL. Linear search is mostly used to search an unordered list in
which the items are not sorted.

Program:

#include<stdio.h>

void main ()

int a[10] = {10, 23, 40, 1, 2, 0, 14, 13, 50, 9};

int item, i,flag;

printf("\nEnter Item which is to be searched\n");

scanf("%d",&item);

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

{
if(a[i] == item)

flag = i+1;

break;

else

flag = 0;

if(flag != 0)

printf("\nItem found at location %d\n",flag);

else

printf("\nItem not found\n");

Output:

Conclusion: We have implemented Linear Search Algorithm using 'C' programming.

You might also like