Professional Documents
Culture Documents
Data Structure - Presentation Slides - Group 9
Data Structure - Presentation Slides - Group 9
Data Structure - Presentation Slides - Group 9
Data Structure
BY: GROUP 9 18 41 61
2
Data Structure
TOPIC: SEARCHING
Contents
Searching
Linear
Data Structure
SEARCHING
The process of finding a specific data item/record from a list is known as Searching Searching is one of the most important operation performed on Data Structures. This is the fundamental operation on data structures like Arrays, Linked Lists & Trees
Data Structure
Computers stores large amount of data. Retrieval of individual record is required. For efficient storage Fast Searching is needed. Operations like Insertion, Deletion etc are dependant upon searching.
Data item will be first searched Then operation will be performed on it.
5
Data Structure
TYPES
Sequential -Hina Binary -Anam
6
Searching
Searching
SEQUENTIAL SEARCH
Data Structure
Straight
forward technique to search specified item in an unordered list is called Sequential searching
Data Structure
METHOD
Consecutively
check every
value
Until
Data Structure
SET LOC= -1 [Enter value that is to be searched] INPUT ITEM REEAT STEP -4 FOR I =1 TO N IF ITEM =ABC [I] THEN LOC = I PRINT Data found at location, LOC EXIT END IF [End of step -3 loop] IF LOC =-1 THEN PRINT Item not Found Exit ENDF IF
9
SPECIFIC PIECE OF PROGRAM DEMONSTRATING USAGE OF SEQUENTIAL SEARCHING: 0,1,2,3.9. GIVEN VALUES
Data Structure
//member function to search data from array void seq ::search(int n) { int I , loc =-1; i=0; While (i<=9) { If(n==a[i]) { loc=i+1; cout<<Data found in location=<<loc; break; } I++ } if (loc= =-1) cout<<Data not found; }s
10
Data Structure
BINARY SEARCHING
A binary search begins by searching the required value from the middle of the list. It is a more efficient technique to search a specific item from list of items. Mostly used for relatively large lists or table of records that are sorted in ascending or descending order.
11
Data Structure
METHOD
If the required value is in the middle of the list then search process terminates at that point. If the list is sorted in ascending order and the required value is greater than the value at the middle, the control goes to the higher value to search the required value. Vice versa For less than the value at the middle. In both cases, half of the list is searched to find the required value.
12
SET LOC = -1 [Enter value to be searched] INPUT ITEM MID = (1+N)/2 IF ITEM = ABC[MID] THEN PRINT Value found at middle EXIT END IF [search towards rights] IF ITEM >ABC[MID] THEN REPEAT FOR I = MID+1 TO N BY 1 IF ITEM = ABC [I] THEN PRINT "Value at position", I EXIT
Data Structure 13
Data Structure
ALGORITHM CONTINUED
END IF ELSE [Check towards left] REPEAT FOR I = MID -1 TO 1 BY -1 IF ITEM = ABC [I] THEN PRINT "Value at position", I EXIT END IF IF LOC = -1 THEN PRINT "Data not found" EXIT
14
SPECIFIC PIECE OF PROGRAM DEMONSTRATING USAGE OF BINARY SEARCHING: 0,1,2,3.9. GIVEN VALUES
Data Structure
//member function find item from array void bin ::bsearch(int item) { int mid, loc; loc = -1; mid = (0+9)/2; if (item == a[mid]) { cout<<"Required value found a mid"; return; } if (item > a[mid]) { for (int i = mid +1 ;i<=9;i++)
15
Data Structure
PROGRAM CONTINUED
if (item== a[i]) {loc =i +1; break;} } else { for(int i = mid;i>=0;i --) if (item==a[i]) { loc = i+1; break; } } if(loc== -1) cout<<"Data not found"; else cout<<"Data found at location = "<<loc; }
16
Data Structure
Data Structure