Professional Documents
Culture Documents
Searching an element in
the list
Linear binary
search search
2
Linear search:
Comparing each element of list with the element which we want
to search or
passing through each element of the list
3
Write a
4
Binary search
This search algorithm works on the principle of divide and conquer.
Condition in binary
search
Array must be sorted
6
li=[14 ,
18,19,24,34,43,54,56,78,78]
Let the element to search is x=18:
14 18 19 24 34 43 54 56 78 78
14 18 19 24 34 43 54 56 78 78
14 18 19 24 34 43 54 56 78 78
14 18 19 24 34 43 54 56 78 78
14 18 19 24 34 43 54 56 78 78
14 18 19 24 34 43 54 56 78 78
14 18 19 24 34 43 54 56 78 78
Lb=m+1=0+1=1
Ub=1 (no change)
So , m=(lb+ub)//2= (1+1)//2=1
14 18 19 24 34 43 54 56 78 78
Checl if x= =li[m]
return m
11
search
the list 12
[12,13,17,15,29,20,23]
1. USING LINEAR
SEARCH
2.USINg BINARY
SEARCH
13
THANK YOU