SlideShare a Scribd company logo
Sequential & binary, linear search
LINEAR BINARY
SEARCH
What is searching?
• In computer science, searching is the process of finding an item with
specified properties from a collection of items.The items may be stored as
records in a database, simple data elements in arrays, text in files, nodes in
trees, vertices and edges in graphs, or maybe be elements in other search
place.
Why do we need searching?
• Searching is one of the core computer science algorithms. We know that
today’s computers store a lot of information.To retrieve this information
proficiently we need very efficient searching algorithms.
Binary Search
• Let us consider a problem of searching a word in a dictionary.Typically, we
directly go to some approximate page[say, middle page] start searching
from that point. If the name that we are searching is same then the search is
complete. If the page is before the selected pages then apply the process for
the first half otherwise apply the same process for the second half. Binary
search also works in the same way.The algorithm applying such strategy is
referred as binary search algorithm.
Sequential or Linear search
Sequential & binary, linear search
Sequential & binary, linear search
BINARY SEARCH
1 5 8 2412 36 48 876754
ENTER THE ARRAY ELEMENTS
ENTER THE NUMBER TO BE SEARCHED
36
M[0] M[1] M[2] M[3] M[4] M[5] M[6] M{7] M[8] M[9]
BINARY SEARCH
1 5 8 2412 36 48 876754
ENTER THE NUMBER TO BE SEARCHED 36
M[0] M[1] M[2] M[3] M[4] M[5] M[6] M{7] M[8] M[9]
LB UB
P=LB+UB/2
24
STEP 1
FIND THE MIDDLE ELEMENT
P=0+9/2
24 36<
36 48 54 67 87
THE SEARCH ELEMENT LIES IN THE UB
0 1 2 3 4
COMPARING SEARCH WITH MIDDLE ELEMENT
STEP 2
P=LB+UB/2 54
54 > 36
36 48
STEP 3
DIVIDE THE ARRAY FURTHER
COMPARING SEARCH WITH MIDDLE ELEMENT
THE SEARCH ELEMENT LIES IN THE LB
3636
=
NUMBER FOUND
STEP 4
36 48
MIDDLE ELEMENT IS COMPARED WITH THE ELEMENTS IN THE ARRAY
#include<stdio.h>
int main(){
int a[10],i,n,m,c=0,l,u,mid;
printf("Enter the size of an array: ");
scanf("%d",&n);
printf("Enter the elements in ascending order:
");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("Enter the number to be search: ");
scanf("%d",&m);
CODE
l=0,u=n-1;
while(l<=u){
mid=(l+u)/2;
if(m==a[mid]){
c=1;
break;
}
else if(m<a[mid]){
u=mid-1;
}
else
l=mid+1;
}
if(c==0)
printf("The number is not found.");
else
printf("The number is found.");
return 0;
}
Enter the elements of the array in ascending order
12
Enter the elements of the array in ascending order
23
Enter the elements of the array in ascending order
34
Enter the elements of the array in ascending order
45
Enter the elements of the array in ascending order
56
Enter the elements of the array in ascending order
67
Enter the elements of the array in ascending order
78
Enter the elements of the array in ascending order
89
Enter the elements of the array in ascending order
98
Enter the elements of the array in ascending order
100
Enter the number to be searched
67
found
binary search Use/Application
LINEAR SEARCH
10 46 8 996 2 34 19578
ENTER THE NUMBER TO BE SEARCHED
2
M[0] M[1] M[2] M[3] M[4] M[5] M[6] M{7] M[8] M[9]
LINEAR SEARCH
10 46 8 996 2 34 19578
2 2 2 2 2 2
THE NUMBER IS FOUND IN THE 6TH POSITION
#include <stdio.h>
int main()
{
int array[100], search, c, n;
printf("Enter the number of elements in arrayn");
scanf("%d",&n);
printf("Enter %d integer(s)n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
CODE
printf("Enter the number to searchn");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* if required element found */
{
printf("%d is present at location %d.n", search, c+1);
break;
}
}
if (c == n)
printf("%d is not present in array.n", search);
return 0;
}
Sequential & binary, linear search
Sequential & binary, linear search
Sequential & binary, linear search

More Related Content

PPTX
Linear Search Data Structure
Talha Shaikh
 
PPTX
Searching
Ashim Lamichhane
 
PPTX
Binary search in data structure
Meherul1234
 
PPT
Searching algorithms
Trupti Agrawal
 
PPTX
sorting and searching.pptx
ParagAhir1
 
PPTX
Searching, Sorting and Hashing Techniques
Selvaraj Seerangan
 
PDF
03 Linear Arrays Memory Representations .pdf
KkSingh64
 
PPT
Counting Sort and Radix Sort Algorithms
Sarvesh Rawat
 
Linear Search Data Structure
Talha Shaikh
 
Searching
Ashim Lamichhane
 
Binary search in data structure
Meherul1234
 
Searching algorithms
Trupti Agrawal
 
sorting and searching.pptx
ParagAhir1
 
Searching, Sorting and Hashing Techniques
Selvaraj Seerangan
 
03 Linear Arrays Memory Representations .pdf
KkSingh64
 
Counting Sort and Radix Sort Algorithms
Sarvesh Rawat
 

What's hot (20)

PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPT
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
PPT
Hash table
Rajendran
 
PPTX
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
PPT
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
PDF
Sorting Algorithms
Mohammed Hussein
 
PPTX
Data structure - Graph
Madhu Bala
 
PPTX
Binary Search Tree
sagar yadav
 
PPTX
Hashing
Amar Jukuntla
 
PPTX
Breadth First Search & Depth First Search
Kevin Jadiya
 
PDF
Array data structure
maamir farooq
 
PPT
Heaps
Hafiz Atif Amin
 
PDF
Iterations and Recursions
Abdul Rahman Sherzad
 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
 
PPTX
Demonstrate interpolation search
manojmanoj218596
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPT
Doubly linked list
chauhankapil
 
PPTX
Heap tree
JananiJ19
 
PPTX
Bubble Sort Algorithm Presentation
AhmedAlbutty
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Hash table
Rajendran
 
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Sorting Algorithms
Mohammed Hussein
 
Data structure - Graph
Madhu Bala
 
Binary Search Tree
sagar yadav
 
Hashing
Amar Jukuntla
 
Breadth First Search & Depth First Search
Kevin Jadiya
 
Array data structure
maamir farooq
 
Iterations and Recursions
Abdul Rahman Sherzad
 
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Demonstrate interpolation search
manojmanoj218596
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Doubly linked list
chauhankapil
 
Heap tree
JananiJ19
 
Bubble Sort Algorithm Presentation
AhmedAlbutty
 
heap Sort Algorithm
Lemia Algmri
 
Ad

Viewers also liked (20)

PPTX
Searching linear &amp; binary search
nikunjandy
 
PPT
Linear and Bianry search
Daffodil International University
 
PPT
Data Structures - Searching & sorting
Kaushal Shah
 
PPSX
Linear and binary search
Arjunsinh Jadeja
 
PPT
Linear Search & Binary Search
Reem Alattas
 
PDF
Linear search algorithm
NeoClassical
 
PDF
5. organisasi indeks sequential
Renol Doang
 
PPTX
Sd bab 3 (pencarian)
Nm Aditya Danger
 
PDF
Algoritma dan Struktur Data - Sequential Search
KuliahKita
 
DOCX
Sequential
bataleon
 
PPTX
Sequential Search
Putra Andry
 
PDF
Time complexity (linear search vs binary search)
Kumar
 
PPTX
Binary search
Raghu nath
 
PPTX
Data Structures
Nitesh Bichwani
 
PPTX
Binary search
Gaurav Solanki
 
PPTX
Levels of management
Sweetp999
 
PPTX
Search algorithms master
Hossam Hassan
 
PPT
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
PPTX
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPT
Management Information System (MIS)
Navneet Jingar
 
Searching linear &amp; binary search
nikunjandy
 
Linear and Bianry search
Daffodil International University
 
Data Structures - Searching & sorting
Kaushal Shah
 
Linear and binary search
Arjunsinh Jadeja
 
Linear Search & Binary Search
Reem Alattas
 
Linear search algorithm
NeoClassical
 
5. organisasi indeks sequential
Renol Doang
 
Sd bab 3 (pencarian)
Nm Aditya Danger
 
Algoritma dan Struktur Data - Sequential Search
KuliahKita
 
Sequential
bataleon
 
Sequential Search
Putra Andry
 
Time complexity (linear search vs binary search)
Kumar
 
Binary search
Raghu nath
 
Data Structures
Nitesh Bichwani
 
Binary search
Gaurav Solanki
 
Levels of management
Sweetp999
 
Search algorithms master
Hossam Hassan
 
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Management Information System (MIS)
Navneet Jingar
 
Ad

Similar to Sequential & binary, linear search (20)

PPT
Searching in c language
CHANDAN KUMAR
 
DOCX
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
PPTX
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
PPTX
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
PPTX
Binary search algorithm.pptx
bhuvansaachi18
 
PPTX
Linear and binary search
JeoJoyA
 
PPT
Searching
Muhammad Farhan
 
PPTX
Binary search Algorithm
FazalRehman79
 
PDF
Searching
A. S. M. Shafi
 
PPTX
Unit 2 Searching and Sorting Technique.pptx
Vaibhav Parjane
 
PPTX
Searching and Sorting Unit II Part I.pptx
Dr. Madhuri Jawale
 
PPTX
unit II_2_i.pptx
HODElex
 
PPTX
Searching Algorithm.pptx
SUGUNA49
 
PPTX
Searching in DSA that follow a dsa searching.pptx
StephenRobert15
 
PDF
Binary search
Ramkrishna bhagat
 
PPTX
Dsa – data structure and algorithms searching
sajinis3
 
PPTX
placement preparation for Array Searching.pptx
upasnatiwari10
 
PPTX
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 
Searching in c language
CHANDAN KUMAR
 
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
Binary search algorithm.pptx
bhuvansaachi18
 
Linear and binary search
JeoJoyA
 
Searching
Muhammad Farhan
 
Binary search Algorithm
FazalRehman79
 
Searching
A. S. M. Shafi
 
Unit 2 Searching and Sorting Technique.pptx
Vaibhav Parjane
 
Searching and Sorting Unit II Part I.pptx
Dr. Madhuri Jawale
 
unit II_2_i.pptx
HODElex
 
Searching Algorithm.pptx
SUGUNA49
 
Searching in DSA that follow a dsa searching.pptx
StephenRobert15
 
Binary search
Ramkrishna bhagat
 
Dsa – data structure and algorithms searching
sajinis3
 
placement preparation for Array Searching.pptx
upasnatiwari10
 
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 

Recently uploaded (20)

PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PDF
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
TumwineRobert
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PDF
Introducing Procurement and Supply L2M1.pdf
labyankof
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Understanding operators in c language.pptx
auteharshil95
 
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Cardiovascular Pharmacology for pharmacy students.pptx
TumwineRobert
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
Introducing Procurement and Supply L2M1.pdf
labyankof
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 

Sequential & binary, linear search

  • 3. What is searching? • In computer science, searching is the process of finding an item with specified properties from a collection of items.The items may be stored as records in a database, simple data elements in arrays, text in files, nodes in trees, vertices and edges in graphs, or maybe be elements in other search place.
  • 4. Why do we need searching? • Searching is one of the core computer science algorithms. We know that today’s computers store a lot of information.To retrieve this information proficiently we need very efficient searching algorithms.
  • 5. Binary Search • Let us consider a problem of searching a word in a dictionary.Typically, we directly go to some approximate page[say, middle page] start searching from that point. If the name that we are searching is same then the search is complete. If the page is before the selected pages then apply the process for the first half otherwise apply the same process for the second half. Binary search also works in the same way.The algorithm applying such strategy is referred as binary search algorithm.
  • 9. BINARY SEARCH 1 5 8 2412 36 48 876754 ENTER THE ARRAY ELEMENTS ENTER THE NUMBER TO BE SEARCHED 36 M[0] M[1] M[2] M[3] M[4] M[5] M[6] M{7] M[8] M[9]
  • 10. BINARY SEARCH 1 5 8 2412 36 48 876754 ENTER THE NUMBER TO BE SEARCHED 36 M[0] M[1] M[2] M[3] M[4] M[5] M[6] M{7] M[8] M[9] LB UB
  • 11. P=LB+UB/2 24 STEP 1 FIND THE MIDDLE ELEMENT P=0+9/2
  • 12. 24 36< 36 48 54 67 87 THE SEARCH ELEMENT LIES IN THE UB 0 1 2 3 4 COMPARING SEARCH WITH MIDDLE ELEMENT STEP 2
  • 13. P=LB+UB/2 54 54 > 36 36 48 STEP 3 DIVIDE THE ARRAY FURTHER COMPARING SEARCH WITH MIDDLE ELEMENT THE SEARCH ELEMENT LIES IN THE LB
  • 14. 3636 = NUMBER FOUND STEP 4 36 48 MIDDLE ELEMENT IS COMPARED WITH THE ELEMENTS IN THE ARRAY
  • 15. #include<stdio.h> int main(){ int a[10],i,n,m,c=0,l,u,mid; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements in ascending order: "); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); CODE
  • 17. Enter the elements of the array in ascending order 12 Enter the elements of the array in ascending order 23 Enter the elements of the array in ascending order 34 Enter the elements of the array in ascending order 45 Enter the elements of the array in ascending order 56 Enter the elements of the array in ascending order 67 Enter the elements of the array in ascending order 78 Enter the elements of the array in ascending order 89 Enter the elements of the array in ascending order 98 Enter the elements of the array in ascending order 100 Enter the number to be searched 67 found
  • 19. LINEAR SEARCH 10 46 8 996 2 34 19578 ENTER THE NUMBER TO BE SEARCHED 2 M[0] M[1] M[2] M[3] M[4] M[5] M[6] M{7] M[8] M[9]
  • 20. LINEAR SEARCH 10 46 8 996 2 34 19578 2 2 2 2 2 2 THE NUMBER IS FOUND IN THE 6TH POSITION
  • 21. #include <stdio.h> int main() { int array[100], search, c, n; printf("Enter the number of elements in arrayn"); scanf("%d",&n); printf("Enter %d integer(s)n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); CODE
  • 22. printf("Enter the number to searchn"); scanf("%d", &search); for (c = 0; c < n; c++) { if (array[c] == search) /* if required element found */ { printf("%d is present at location %d.n", search, c+1); break; } } if (c == n) printf("%d is not present in array.n", search); return 0; }