Searching & Analysis
Searching & Analysis
SEARCHING,
TECHNIQUES
&
ANALYSIS
NAME – ROHAN
CONTENT
WHAT IS SEARCHING?
EXPLANATION WITH EXAMPLE
SEARCHING TECHNIQUES!
LINEAR SEARCH
BINARY SEARCH
INTERPOLATION SEARCH
LINEAR SEARCH
ALGORITHM & SYNTAX
HOW LINEAR SEARCH WORKS ?
ADVANTAGES / DISADVANTAGES
Searching
Linear Search
Binary Search
Interpolation
Search
Linear Search (sequential search)
4 •Set i to i+1
5 •Go to step 2
8 •Exit
How Linear Search works ?
Now see the working of the linear search algorithm.
Let’s take an sorted array. It will be easy to understand the working of
linear search with an example.
• Let the Element of Array are-
0 1 2 3 4 5 6
3 8 15 22 28 31 49
0 1 2 3 4 5 6
3 8 15 22 28 31 49
Now, starts from the first element and compare K with each element of the array.
0 1 2 3 4 5 6
3 8 15 22 28 31 49
K=3
The value of K, i.e. 8 is not matched with the first element of the array. So, move to the next
element. And follow the same process untill the respective element is found.
0 1 2 3 4 5 6
3 8 15 22 28 31 49
K=8
0 1 2 3 4 5 6
3 8 15 22 28 31 49
K=15
0 1 2 3 4 5 6
3 8 15 22 28 31 49
K=22
0 1 2 3 4 5 6
3 8 15 22 28 31 49
K=28
Now the element to be searched is found. So algorithm will return the index of the
element matched.
WORKING OF BINARY & SEQUENTIAL SEARCH
ADVANTAGES OF LINEAR SRACH
&
N K
A KEEP
T H
LEARNING