Linear Search Data Structure

12,062 views 19 slides Feb 14, 2015
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

Linear Search algorithem.


Slide Content

Presentation on Linear search Data Structure

Group Members MCS-13-08 Muhammed Talha MCS-13-03 Arslan Azam MCS-13-38 Aitazaz Ahsan MCS-13-39 Tayyaba Ghani MCS-13-22 Abida Bibi

Contents Introduction to Search What is Linear Search ? Example of Linear Search ? Pseudo code C++ Code linked list code of Linear Search Worst Case Best Case Discussion

Muhammed Talha Search & Linear Search

What is Search ? The  definition  of a  search  is the process of looking for something or someone Example : An example of a  search  is a quest to find a missing person

Linear Search : Algorithm involves checking all the elements of the array(or any other structure) one by one and in sequence until the desired result is found.

Linear Search Example If you are asked to find the name of the person having phone number say “1234” with the help of a telephone directory . Since telephone directory is sorted by name not by numbers,we have to go through each and every number of the directory

Pseudocode For all elements Check if it is equal to element being searched for. If it is ,return its position. else continue.

Arslan Azam Linear Search Example by C++ Program

C++ code void iterSearch (const double data [ ], int n,double key) //const for safety ,we want to keep array unchanged { for( int i =0;i<=n-1;i++) //looping through all elements of the array { if(data[ i ]==key) { cout <<key<<" found at index "<< i <<" of the array"<< endl ; break; //if element is found,come out of the loop } if( i ==n-1) //searched through the array,still not found cout <<"\n Element not found \n"; } }

Atizaz Ahsan Linear Search Example by using Linked List

Linear Search using Linked List void List::find() { int n, count = 0; cout <<"Enter data to find in the list : "; cin >>n; Node * tmp = head; while ( tmp != NULL ) { count = count + 1; if( n == tmp ->Data()) { cout <<"The data found on node number "<< count << endl ; break; } tmp = tmp ->Next(); } }

Abida Bibi Advantages of Linear Search

Advantages of Linear search If the first number in the directory is the number you were searching for ,then lucky you!!. ●Since you have found it on the very first page,now its not important for you that how many pages are there in the directory. ●Whether if it is of 1000 pages or 2000 pages it will take u same time to find you the number ,if it is at the very beginning . ●So it does not depends on no. on elements in the directory.Hence constant time .

Tayyaba Ghani Disadvantages of Linear Search

Disadvantages of Linear search It may happen that the number you are searching for is the last number of directory or if it is not in the directory at all. In that case you have to search the whole directory. Now number of elements will matter to you.if there are 500 pages ,you have to search 500;if it has 1000 you have to search 1000. Your search time is proportional to number of elements in the directory. No of elements No of comparisons to be done 15 15 600 600

Discussion 1.Sorted array is not needed. 2.Works fine for small number of elements .Search time increases with number of elements. 3.Elements with higher probability of being searched should be kept in the beginning.

Question ?

Thank You 
Tags