Linear Search and Binary Search
Linear Search and Binary Search
Presentation by
Ms. R. Rajalakshmi
Assistant Professor / IT
COURSE OUTCOMES
CO1: Describe various data structures and algorithms for problem
solving
CO2: Choose appropriate data structures and algorithms for better
problem solving.
CO3: Solve computational problems using efficient algorithms and data
structures
CO4: Discriminate the performance of various algorithms and its
background data structures
The searching of an element in the given array may be carried out in the
following two ways
It searches for an element by comparing it with each element of the array one by one.
Step 2 - Compare the search element with the first element in the list.
Step 3 - If both are matched, then display "Given element is found!!!" and
terminate the function
Step 4 - If both are not matched, then compare search element with the next
element in the list.
Step 5 - Repeat steps 3 and 4 until search element is compared with last element
in the list.
Step 6 - If last element in the list also doesn't match, then display "Element is not
found!!!" and terminate the function.
20CS243 - DATA STRUCTURES AND ALGORITHM ANALYSIS –MS. R. RAJALAKSHMI 7
Linear Search
Search Element: 11
3 6 7 11 32 33 53
0 1 2 3 4 5 6
Step: 1
Search element (11) is compared with the first element(3)
0 1 2 3 4 5 6
3 6 7 11 32 33 53
11
Both are not matching. So move to next element.
0 1 2 3 4 5 6
3 6 7 11 32 33 53
11
0 1 2 3 4 5 6
3 6 7 11 32 33 53
11
0 1 2 3 4 5 6
3 6 7 11 32 33 53
11
Both are matching. So we stop comparing and display element found at index 3
scanf("%d",&SElement);
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53
3 6 7 11 32 33 53