SlideShare une entreprise Scribd logo
1  sur  10
Sequential Search
&
Binary Search
By:
Solanki Gaurav P. 15COD05
Nikam Rohit P.15COD08
Patel Hemanshu B.15COD14
Jena Akshay.15COD19
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.
Types of searching
• Unordered linear/ sequential search
• Sorted/ Ordered linear/ sequential search
• Binary search
• Symbol tables and Hashing
• String searching algorithms
Unordered linear/ Sequential search
• Let us assume that given an array whose elements order is not known.That
means that the element of array are not sorted. In this case, to search for an
element we have to scan the complete array and see if the element is there
in given list or not.
Unordered linear/ Sequential search
int unorderedlinearsearch (int A[], int n, int data)
{
for (int i=0; i<n; i++)
{
if(A[i] == data)
return i;
}
return -1;
}
Search No. 405 from the given array
15 75 65405 551 1535 77 80
First of all compare the element to be searched with the index
element of array.
51 !=405 So move to next element.
15 !=405 Move to next element.
75 != 405 Move to next element.
35 !=405 move to next element.
405 ==405 SEARCH COMPLETE.
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.
Search Number 75 from Array using binary
search
15 25 65
75 > 45
45 555 9535 75 85
According to
algorithm, first find
middle element of
your array.
MID= LOW+HIGH/2
Check if search
element and middle
element are same?
If yes your search is
over.
75 ≠ 45
If not equal then
Check if search
element is greater or
smaller than middle
value.
75 == 75
If search element is
greater than mid
element then make
mid + 1 low value and
find middle value
Search Complete
LOW MID HIGHMIDLOW

Contenu connexe

Tendances

Tendances (20)

Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Data structures
Data structuresData structures
Data structures
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 
Quick sort
Quick sortQuick sort
Quick sort
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Linked List
Linked ListLinked List
Linked List
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 

Similaire à Binary search

Linear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmLinear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithm
JavedKhan524377
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
babuk110
 
seaching internal 2 ppt
seaching internal 2 pptseaching internal 2 ppt
seaching internal 2 ppt
SubhrasisBiswal1
 

Similaire à Binary search (20)

Linear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithmLinear Search for design and analysis of algorithm
Linear Search for design and analysis of algorithm
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Linear Search in Oops.pptx
Linear Search in Oops.pptxLinear Search in Oops.pptx
Linear Search in Oops.pptx
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
 
programming in C
programming in Cprogramming in C
programming in C
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
 
arrays in c
arrays in carrays in c
arrays in c
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
Searching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing Techniques
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
unit II_2_i.pptx
unit II_2_i.pptxunit II_2_i.pptx
unit II_2_i.pptx
 
Searching and sorting
Searching  and sortingSearching  and sorting
Searching and sorting
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
seaching internal 2 ppt
seaching internal 2 pptseaching internal 2 ppt
seaching internal 2 ppt
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
 
searching
searchingsearching
searching
 
Binary search
Binary search Binary search
Binary search
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
cs702 ppt.ppt
cs702 ppt.pptcs702 ppt.ppt
cs702 ppt.ppt
 

Dernier

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Binary search

  • 1.
  • 2. Sequential Search & Binary Search By: Solanki Gaurav P. 15COD05 Nikam Rohit P.15COD08 Patel Hemanshu B.15COD14 Jena Akshay.15COD19
  • 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. Types of searching • Unordered linear/ sequential search • Sorted/ Ordered linear/ sequential search • Binary search • Symbol tables and Hashing • String searching algorithms
  • 6. Unordered linear/ Sequential search • Let us assume that given an array whose elements order is not known.That means that the element of array are not sorted. In this case, to search for an element we have to scan the complete array and see if the element is there in given list or not.
  • 7. Unordered linear/ Sequential search int unorderedlinearsearch (int A[], int n, int data) { for (int i=0; i<n; i++) { if(A[i] == data) return i; } return -1; }
  • 8. Search No. 405 from the given array 15 75 65405 551 1535 77 80 First of all compare the element to be searched with the index element of array. 51 !=405 So move to next element. 15 !=405 Move to next element. 75 != 405 Move to next element. 35 !=405 move to next element. 405 ==405 SEARCH COMPLETE.
  • 9. 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.
  • 10. Search Number 75 from Array using binary search 15 25 65 75 > 45 45 555 9535 75 85 According to algorithm, first find middle element of your array. MID= LOW+HIGH/2 Check if search element and middle element are same? If yes your search is over. 75 ≠ 45 If not equal then Check if search element is greater or smaller than middle value. 75 == 75 If search element is greater than mid element then make mid + 1 low value and find middle value Search Complete LOW MID HIGHMIDLOW