PROGRAM:
//LINEAR SEARCH USING FUNCTIONS
#include
void linear(int [],int,int);
main()
{
int n,i,x,a[10];
printf("\nEnter the limit:");
scanf("%d",&n);
printf("\nEnter the elements:");
for(i=0;i { scanf("%d",&a[i]); } printf("\nEnter the element to be searched:"); scanf("%d",&x); linear(a,n,x); } void linear(int a[],int n,int x) { int i,flag=0; for(i=0;i { if(x==a[i]) { flag=1; break; } } if(flag==1) printf("\nElement %d is in the position %d",a[i],i+1); else printf("\nElement is not in the list"); }
Linear search is necessary when we must search unordered sets. Linear search times across huge sets can be improved significantly by dividing the set amongst two or more threads that can execute on independent CPU cores.
Linear search
1)in linear search it needs more space and time complexity. 2) in linear search if the key element is the last element and the search is from first element that is a worst case, or if the key element is the first element and the search is from last element then also is the worst case.
there is no basic symbol in flowchart
pictorial representation of a program is called a flowchart
( start ) -> / Write "Hello World" / -> ( end ) *try to search an example on google. *type "flowchart of hello world"
Sequential search of an object with in an array of objects is called as linear search.
The linear search algorithm is a special case of the brute force search.
There no advantages to linear search other than searching for the first (or last) nodes. Linear search takes linear time with an average O(n/2) for each search.
Running time of a linear search is O(n)
the compexity of linear search in worst case is f(n) = n+1
The linear search algorithm is a special case of the brute force search.
Linear search is necessary when we must search unordered sets. Linear search times across huge sets can be improved significantly by dividing the set amongst two or more threads that can execute on independent CPU cores.
1. Macro flowchart shows less information whereas micro flowchart shows more information. 2. Macro flowchart is easy to design as comparative to micro flowchart. 3. Macro flowchart is difficult to study and understand as comparative to micro flowchart.
Linear search
1)in linear search it needs more space and time complexity. 2) in linear search if the key element is the last element and the search is from first element that is a worst case, or if the key element is the first element and the search is from last element then also is the worst case.
there is no basic symbol in flowchart