0% found this document useful (0 votes)
177 views

Linear Search

Linear search, also called sequential search, is a simple search algorithm that finds an element in a list by sequentially checking each element of the list until a match is found or the whole list has been searched. It involves sequentially checking each element of the list one by one starting from the first element until the desired element is found or the entire list has been traversed. The best case occurs when the element is found at the first position and the worst case occurs when the element is not found in the list. Some advantages of linear search are that it is simple and efficient for small lists, and no sorting of items is required. Some disadvantages are that it is not suitable for large lists, requires more comparisons, and takes more time to

Uploaded by

Gauri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views

Linear Search

Linear search, also called sequential search, is a simple search algorithm that finds an element in a list by sequentially checking each element of the list until a match is found or the whole list has been searched. It involves sequentially checking each element of the list one by one starting from the first element until the desired element is found or the entire list has been traversed. The best case occurs when the element is found at the first position and the worst case occurs when the element is not found in the list. Some advantages of linear search are that it is simple and efficient for small lists, and no sorting of items is required. Some disadvantages are that it is not suitable for large lists, requires more comparisons, and takes more time to

Uploaded by

Gauri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Echo Topic : Searching

Q. write short notes on searching ?


Ans:- Searching :- Searching is a process of finding an element within
the list of elements start in any order or randomly . Searching particular
element is one of the most applications of computers. Searching is
divided into two categories linear and binary search.
Classification of searching
Internal Vs. external searching :-
if the records to be searched are stored in main memory ,is called
internal searching . On the other hand if the records are stored fin files on
disk or tape i.e. on secondary memory is called external searching.
Static Vs. dynamic searching
Here static means that the contents of the table are unchangeable while
dynamic refers to the verifying contents of the table that can by
frequently changed.
Echo Topic : Linear Search
Q . What is sequential searching or linear searching . Write a
program for linear search .
OR
What do you mean by linear search . Write a program to implement
the concept of linear search .
Ans :- linear searching :- The simplest search technique is the
sequential or linear search. In this technique we begin with the first
element of the list and then search the list sequentially until either we
find the specified data item or we reach end of the list. A search will be
unsuccessful if all the elements are accessed and the desired element is
not found.

In sequential search , the best case occur when the item is found in first
position and worth case occur when element not found in the list.
Program for Linear Search
#include<iostream.h>
#include<conio.h>
int main( )
{
int a[10];
int n,i,x,p=0;
cout<<"\n enter the value of n:";
cin>>n;
cout<<"\n enter the values:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n which element you want to search:";
cin>>x;
for(i=0;i<n;i++)
{
if(a[i]==x)
{
p=1;
break;
}
}
if(p==1)
{
cout<<"\n element is found at location:"<<(i+1);
}
else
{
cout<<"\n element is not found:";
}
}

Q . :-write down the advantages &disadvantages of linear search


method?
Advantage Of Linear Search
1. It is simple and easy method.
2. It is efficient for small lists.
3. In linear search no sorting of items is required.
Disadvantage of linear search
1. It is not suitable for large number of elements.
2. It requires more comparisons .
3. It taking more to search a desired element . if the list contain large
number of elements .

You might also like