1 Dec 2019

  • December 01, 2019
  • Amitraj
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.



/* C program to implement Linear Search or Sequential searching */

#include<stdio.h>
int main()
{
int a[100],i,n,s;
printf("Enter n values:");
scanf("%d",&n);
printf("Enter %d values:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter a no. to search:");
scanf("%d",&s);
for(i=0;i<n;i++)
{
if(a[i]==s)
{
printf("Number found..");
return 0;
}
}
printf("Number not found..");
return 0;
}

OUTPUT:-

1. Enter n values:5
Enter 5 values:69 45 1 6 21
Enter a no. to search:21

Number found..

2. Enter n values:5
Enter 5 values:7 9 14 85 56
Enter a no. to search:87

Number not found..

Related Posts:

  • Binary Search Tree Binary Search Tree ->  Binary Search Tree is a special kind of binary tree in which nodes are arranged in a specific order. -> A binary search tree is a useful data structure for fast addition and removal o… Read More
  • Collision in Hashing | Collision Resolution techniques Collision in Hashing When the hash value of a key maps to an already occupied Bucket of the hash table, it is called , Collision. Collision Resolution techniques Collision resolution techniques are the techniques used fo… Read More
  • Hashing Data Structure What is Hashing? -> Hashing is a well known technique to search any particular element among several elements. -> it minimizes the number of comparisions while performing the search. Advantages 1. Hashing is extre… Read More
  • Insertion Sort | Sorting Techniques in Data Structure 2. Insertion Sort -> Insertion sort is a simple sorting algorithm. -> This sorting method sorts the array by shifting elements one by one. -> It builds the final sorted array one item at a time. -> Insertion s… Read More
  • Bubble Sort | Sorting Techniques in Data Structure 1. Bubble Sort -> Bubble sort is a type of sorting. -> It is used for sorting 'n' (number of items) elements. -> It compares all the elements one by one and sorts them based on their values. -> In the above… Read More

Translate

Popular Posts