SlideShare a Scribd company logo
1 of 16
Download to read offline
Binary Search
comparison and
analysis
Binary Search
comparison and
analysis
RAMKRISHNA BHAGAT
MCA-2nd
Year
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.
●
The definition of a search is the process of looking for
something or someone.
●
Example : An example of a search is a quest to find a missing
person.
2
2
●
Searchingis 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.
Why do we need searching?
Types of Searching
Linear search
Binary search
2
3
Disadvantages of Linear Search
4
●
Linear search is slower then other
searching algorithm.
●
If the array is small then it is good to use
linear search.
●
If the array size is large then it is not good
to use linear search because linear search
takes a large amount of time to search as
the element is compared sequentially with
each and every element .
What is Binary Search ?
• Binary search is searching technique
which uses divide and conquer approach.
• In binary search we divide the array in two halves.
We find the element present at the middle index of
the array. Now we compare the element to be
searched with the element present at the middle
index.
5
●
We perform binary search only on a
sorted array. If the array is not sorted
the binary search fails to work.
Continued….
• If the element to be searched is less than the
element at the middle index ,we search in the left
half of the array otherwise we will search in the
right half.
6
●
We continue this process until
we find our element to be
searched.
●
Because binary search is faster than linear
search.
●
It is efficient because it eliminates half items at
each step: ½ then ¼ then 1/8.
●
It is also useful when we have a large array to be
searched whereas in linear search , we have to
search the whole array.
7
Why we need Binary Search ?
Example
2
8
9
10
11
Algorithm of Binary search
12
Step 1: Find middle element of the array.
Step 2: Compare the value of the middle element with the target value.
Step 3: If they match, it is returned.
Step 4: If the value is less or greater than the target, the search continues in the lower or
upper half of the array accordingly.
Step 5: The same procedure as in step 2-4 continues, but with a smaller part of the array. This
continues until the target element is found or until there are no elements left.
12
13
Disadvantages of Binary Search
●
In binary search the first and the
foremost thing is that the array should
be sorted.
●
If the array is not sorted then we have
to sort it first and then we have to
perform binary search. Because of this
the complexity of binary search will
increase.
13
Comparison between Linear and Binary Search
●
Linear search uses sequential approach.
●
Linear search slow working.
● Linear search does the sequential access
●
In linear search, the worst case complexity
is O(n)
●
Input data need not to be sorted in Linear
Search.
●
Binary search implements divide and
conquer approach.
●
Binary search is better and quite faster
●
Binary search access data randomly.
●
Binary search worst case complexity is
O(log n) .
●
Input data needs to be sorted in Binary
Search
14
Complexities of Linear and Binary Search
●
Since in Linear search we
compare the target value
with each and every
element of the array ,
therefore the complexity of
linear search is O(n).
●
At each iteration binary search
divides the array in two halves
so it is taking logarithmic time
to search the array. Therefore
the complexity of binary
search is O(log2 (n)).
15
16
Thanks!

More Related Content

What's hot

Bubble sort
Bubble sortBubble sort
Bubble sortManek Ar
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data StructureJeanie Arnoco
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Anand Ingle
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IMohamed Loey
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1asmhemu
 
Rahat & juhith
Rahat & juhithRahat & juhith
Rahat & juhithRj Juhith
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its typesRameesha Sadaqat
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting AlgorithmsRahul Jamwal
 

What's hot (20)

Bubble sort
Bubble sortBubble sort
Bubble sort
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Searching
SearchingSearching
Searching
 
Binary search
Binary searchBinary search
Binary search
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 
Selection sort
Selection sortSelection sort
Selection sort
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Binary search
Binary searchBinary search
Binary search
 
Sorting
SortingSorting
Sorting
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Rahat & juhith
Rahat & juhithRahat & juhith
Rahat & juhith
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 

Similar to Binary search

Searching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSelvaraj Seerangan
 
programming in C
programming in Cprogramming in C
programming in CADITHYAM19
 
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 algorithmJavedKhan524377
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxprakashvs7
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingThenmozhiK5
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithmstechnologygyan
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operationsbabuk110
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsFerdin Joe John Joseph PhD
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsAnushdika Jeganathan
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptxDr.Shweta
 
Binary search algorithm.pptx
Binary search  algorithm.pptxBinary search  algorithm.pptx
Binary search algorithm.pptxbhuvansaachi18
 
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 JYOTHISowmya Jyothi
 
Presentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptxPresentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptxKrishnanandmishra15
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searchingsajinis3
 

Similar to Binary search (20)

Searching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing Techniques
 
programming in C
programming in Cprogramming in C
programming in C
 
searching
searchingsearching
searching
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
 
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
 
Amitdsppt
AmitdspptAmitdsppt
Amitdsppt
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search Algorithms
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
seaching internal 2 ppt
seaching internal 2 pptseaching internal 2 ppt
seaching internal 2 ppt
 
Database Engine
Database EngineDatabase Engine
Database Engine
 
Binary search algorithm.pptx
Binary search  algorithm.pptxBinary search  algorithm.pptx
Binary search algorithm.pptx
 
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
 
Presentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptxPresentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptx
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 

More from Ramkrishna bhagat (7)

JAVA APPLETS
JAVA APPLETSJAVA APPLETS
JAVA APPLETS
 
DBTG MODEL
DBTG MODELDBTG MODEL
DBTG MODEL
 
IPV6 , ipv6 ,TCP/IP, TCP ,IP
IPV6 , ipv6 ,TCP/IP, TCP ,IPIPV6 , ipv6 ,TCP/IP, TCP ,IP
IPV6 , ipv6 ,TCP/IP, TCP ,IP
 
Data warehouse
Data warehouseData warehouse
Data warehouse
 
Graph Representation
Graph RepresentationGraph Representation
Graph Representation
 
22 ramkrishna
22 ramkrishna22 ramkrishna
22 ramkrishna
 
E-Ball Technology
E-Ball TechnologyE-Ball Technology
E-Ball Technology
 

Recently uploaded

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Binary search

  • 1. Binary Search comparison and analysis Binary Search comparison and analysis RAMKRISHNA BHAGAT MCA-2nd Year
  • 2. 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. ● The definition of a search is the process of looking for something or someone. ● Example : An example of a search is a quest to find a missing person. 2 2
  • 3. ● Searchingis 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. Why do we need searching? Types of Searching Linear search Binary search 2 3
  • 4. Disadvantages of Linear Search 4 ● Linear search is slower then other searching algorithm. ● If the array is small then it is good to use linear search. ● If the array size is large then it is not good to use linear search because linear search takes a large amount of time to search as the element is compared sequentially with each and every element .
  • 5. What is Binary Search ? • Binary search is searching technique which uses divide and conquer approach. • In binary search we divide the array in two halves. We find the element present at the middle index of the array. Now we compare the element to be searched with the element present at the middle index. 5 ● We perform binary search only on a sorted array. If the array is not sorted the binary search fails to work.
  • 6. Continued…. • If the element to be searched is less than the element at the middle index ,we search in the left half of the array otherwise we will search in the right half. 6 ● We continue this process until we find our element to be searched.
  • 7. ● Because binary search is faster than linear search. ● It is efficient because it eliminates half items at each step: ½ then ¼ then 1/8. ● It is also useful when we have a large array to be searched whereas in linear search , we have to search the whole array. 7 Why we need Binary Search ?
  • 9. 9
  • 10. 10
  • 11. 11
  • 12. Algorithm of Binary search 12 Step 1: Find middle element of the array. Step 2: Compare the value of the middle element with the target value. Step 3: If they match, it is returned. Step 4: If the value is less or greater than the target, the search continues in the lower or upper half of the array accordingly. Step 5: The same procedure as in step 2-4 continues, but with a smaller part of the array. This continues until the target element is found or until there are no elements left. 12
  • 13. 13 Disadvantages of Binary Search ● In binary search the first and the foremost thing is that the array should be sorted. ● If the array is not sorted then we have to sort it first and then we have to perform binary search. Because of this the complexity of binary search will increase. 13
  • 14. Comparison between Linear and Binary Search ● Linear search uses sequential approach. ● Linear search slow working. ● Linear search does the sequential access ● In linear search, the worst case complexity is O(n) ● Input data need not to be sorted in Linear Search. ● Binary search implements divide and conquer approach. ● Binary search is better and quite faster ● Binary search access data randomly. ● Binary search worst case complexity is O(log n) . ● Input data needs to be sorted in Binary Search 14
  • 15. Complexities of Linear and Binary Search ● Since in Linear search we compare the target value with each and every element of the array , therefore the complexity of linear search is O(n). ● At each iteration binary search divides the array in two halves so it is taking logarithmic time to search the array. Therefore the complexity of binary search is O(log2 (n)). 15