TechArena Community What is linear search in data structure?

#1
04-01-2011
 Member Join Date: Dec 2010 Posts: 12
What is linear search in data structure?

Hey friends, I want to know the basic topics of data structure you can say the starting topic of data structure. I am thinking to learn data structure but before that I want to know the basics of data structure. If I could know some of the basic topics of data structure then I could have some basic knowledge about it. So, if anybody having any data regarding this topic then please let me know.
#2
04-01-2011
 Member Join Date: Apr 2009 Posts: 484
Re: What is linear search in data structure?

This is simplest method of searching. In this method, the element to be found is sequentially searched in the list. This method can be applied to a sorted list or unsorted list. Searching in case of Sorted list starts from 0th elements and continues until the element is found or an element whose value is greater than the value being searched is reached. You might find this searching method as the simplest as it is the first topic of data structure and it is quite easy to understand.
#3
04-01-2011
 Member Join Date: May 2009 Posts: 503
Re: What is linear search in data structure?

Code:
``` Declare array AA
store elements in to array AA
take nmber to be searched from user and store in num
repeat for i=o to l(ength of AA)-1
check       if AA[i]==num
come out of loop
repeat step  6 to 7
check  if i== 1o
else
print : num found at location i
end of loop```
#4
04-01-2011
 Member Join Date: May 2009 Posts: 532
Re: What is linear search in data structure?

Code:
```#include <stdio.h>
#include <conio.h>

void main( )
{
int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1,
90, 3 } ;
int i, num ;
clrscr( ) ;
printf ( "Enter number to search: " ) ;
scanf ( "%d", &num ) ;
for ( i = 0 ; i <= 9 ; i++ )
{
if ( arr[i] == num )
break ;
}

if ( i == 10 )
printf ( "Number is not present in the
array." ) ;
else
printf ( "The number is at position %d in the array.", i ) ;

getch( ) ;
}```

 Tags: