data structure- presentation slides- group 9
TRANSCRIPT
-
7/30/2019 Data Structure- Presentation Slides- Group 9
1/18
PRESENTATIONOF
DATA STRUCTURE
Data Structure
1
-
7/30/2019 Data Structure- Presentation Slides- Group 9
2/18
BY: GROUP 9
1841
61
Data Structure
2
-
7/30/2019 Data Structure- Presentation Slides- Group 9
3/18
TOPIC: SEARCHING
Contents
SearchingLinear Searching
Sequential Searching
Data Structure
3
-
7/30/2019 Data Structure- Presentation Slides- Group 9
4/18
SEARCHING
The process of finding a specific data
item/record from a list is known as Searching
Searching is one of the most important operationperformed on Data Structures.
This is the fundamental operation on datastructures like Arrays, Linked Lists & Trees
Data Structure
4
-
7/30/2019 Data Structure- Presentation Slides- Group 9
5/18
Computers stores large amount of data.
Retrieval of individual record is required.
For efficient storage Fast Searching isneeded.
Operations like Insertion, Deletion etc aredependant upon searching.
Data item will be first searched Thenoperation will be performed on it.
Data Structure
5
-
7/30/2019 Data Structure- Presentation Slides- Group 9
6/18
TYPES
Sequential Searching
-Hina
Binary Searching-Anam
Data Structure
6
-
7/30/2019 Data Structure- Presentation Slides- Group 9
7/18
SEQUENTIAL SEARCH
Straight forward technique to
search specified item in an
unordered list is called
Sequential searching
Data Structure
7
-
7/30/2019 Data Structure- Presentation Slides- Group 9
8/18
METHOD
Consecutively check every
value
Until work we find desire value
Data Structure
8
-
7/30/2019 Data Structure- Presentation Slides- Group 9
9/18
ALGORITHM- SEQUENTIAL SEARCHING
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
Data Structure
9
-
7/30/2019 Data Structure- Presentation Slides- Group 9
10/18
SPECIFIC PIECE OF PROGRAM DEMONSTRATING USAGE
OF SEQUENTIAL SEARCHING: 0,1,2,3.9. GIVEN VALUES
//member function to search data from array
void seq ::search(int n)
{
int I , loc =-1;
i=0;
While (i
-
7/30/2019 Data Structure- Presentation Slides- Group 9
11/18
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.
Data Structure
11
-
7/30/2019 Data Structure- Presentation Slides- Group 9
12/18
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.
Data Structure
12
-
7/30/2019 Data Structure- Presentation Slides- Group 9
13/18
ALGORITHM- BINARY SEARCHING
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 Structure13
-
7/30/2019 Data Structure- Presentation Slides- Group 9
14/18
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
Data Structure
14
-
7/30/2019 Data Structure- Presentation Slides- Group 9
15/18
SPECIFIC PIECE OF PROGRAM DEMONSTRATING USAGE
OF BINARY SEARCHING: 0,1,2,3.9. GIVEN VALUES
//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
-
7/30/2019 Data Structure- Presentation Slides- Group 9
16/18
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
-
7/30/2019 Data Structure- Presentation Slides- Group 9
17/18
ANY
QUESTIONS
? ? ?
Data Structure
17
-
7/30/2019 Data Structure- Presentation Slides- Group 9
18/18
THANK YOU
MAAM
Data Structure
18