SlideShare a Scribd company logo
BINARY SEARCH
GROUP 1
EDEN ROSE CONICAN
LESHE SENINA
GREEZE LEE OMANDAM
JHON MARK ALIPOYO
MACGEREM ANRO PAGLINAWAN
INTRODUCTION
• Binary search is search algorithm that finds the position of a target value within a
sorted array.
• Binary search is also known as half-interval search or logarithmic search.
• Binary search algorithm works on the principle of Divide and Conquer.
• Binary search can be implemented on only sorted list of elements.
Binary search is a searching algorithm for finding an element’s position in a sorted array.
In this approach, the element is always searched in the middle of a portion of an array.
Binary search can be implemented only on a sorted list of items. If the elements are not
sorted already, we need to sort them first.
BINARY SEARCH WORKING
Binary Search Algorithms can be implemented in two ways which are discussed below:
1. Iterative Method
2. Recursive Method
1. ITERATIVE METHOD
• The iterative binary search method is a highly efficient algorithm for finding a specific
target value within a sorted array. It works by repeatedly dividing the search interval in
half, eliminating half of the remaining elements in each steps.
Here how it functions:
1. Initialization
• Start with the entire arrays as the search interval, defining the leftmost index (low) and
rightmost index (high).
• Set the middle index (mid) to the middle of the interval.
2. Iteration:
• Comparison: Compare the target value with the element at the middle index (mid).
- If the target value is equal to the middle element, the search is successful, and the index (mid) is
returned.
- If the target value is less than the middle element, the search continues in the left half of the interval
(low to mid – 1).
- If the target value is greater than the middle element, the search continues in the right half of the
interval (mid + 1 to high).
3. Updating the Search Interval:
• In each iteration, the search interval is halved based on the comparison result.
• If the target value is less than the middle element, the right boundary (high) becomes mid -1.
• If the target value is greater than the middle element, the left boundary (low) becomes mid + 1.
4. Termination:
• The search continues until the left index (low) becomes greater than the right index (high), indicating
that the target value is not present in the array. In this case, the search returns -1.
2. RECURSIVE METHOD
• The recursive binary search algorithms is a powerful and elegant approach to efficiently
finding a target value in a sorted array. It works by repeatedly dividing the search interval
in half, eliminating half of the remaining elements in each steps.
Here how it functions:
1. Base Case:
• If the left index (low) becomes greater than the right index (high), it means that the
target value is not present in the array. In this case, the function returns -1.
2. Recursive Steps:
• Calculate the middle index (mid) of the search interval.
• Compare the target value with the element at the middle index:
- If the target value is equal to the middle element, the search is successful, and the index (mid) is returned.
- If the target value is less than the middle element, recursively search the left half of the array (low to mid -1).
- If the target value is greater than the middle element, recursively search the right half of the array (mid + 1 to
high).
3. Recursion:
• The function calls itself with updated search intervals (low and high) based on the comparison result,
effectively dividing the problem into smaller subproblems.
DIVIDE AND CONQUER
• Divide and Conquer is the most well-known algorithm strategy.
• A Divide and Conquer algorithm works by recursively breaking down a problem into
two or more sub-problems of the same or related type, until this become simple enough
to be solved directly.
• The solutions to the sub-problems are then combine to give a solution to the original
problem.
EXAMPLE :
• Consider an Array:
A
0 1 2 3 4 5 6 7 8
min mid = ( min + max)/2 max
If(37 == a[mid]) return mid
Else if(37<a[mid]) max=mid-1
Else if(37>a[mid]) min=mid+1
20 35 37 40 45 50 51 55 67
ALGORITHM
Input :
A sorted array
N size of array
Key value to be searched
BinarySearch(a,key,n) :
Set min=0
Set max=n-1
while (min < max)
Set mid = (min+max)/2
ALGORITHM
If(key ==A(mid)
Return mid
Else if(key<A[mid])
Set max= mid – 1
Else
Set min= mid + 1
End if
End while
Retun (-1)
TIME COMPLEXITY
• The running times complexity for Binary Search
are of three types:-
In Worst Case , Time Complexity : O(log n)
In Average Case, Time Complexity : O(log n)
In Best Case , Time Complexity : O(1)
ADVANTAGE
• Binary Search is an optimal searching algorithm using
which we can desired element very efficiently.
DISADVANTAGE
Binary Search algoritm requires the list to be sorted.
Then only method is Applicable.
APPLICATION
• The Binary Search is an efficient searching method and used to search
record from database.
• For solving non-linear equations with one unknown this method to used.
THANK YOU!
Ad

Recommended

PPTX
Binary search Algorithm
FazalRehman79
 
PPTX
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
PPTX
Binary.pptx
hasantahamid15
 
PPTX
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
PPTX
Binary search
AparnaKumari31
 
PPT
Searching
Muhammad Farhan
 
PDF
Binary Search.pdf
Snehasish8
 
PPTX
an Introduction to binary search algorithm
prosper201893
 
PPTX
Binary search algorithm.pptx
bhuvansaachi18
 
PPT
Binary Search
kunj desai
 
PPTX
Binary search
sana younas
 
PPTX
Binary Searching Algorithm PowerPoint Presentation
NicoleAngelaGilaRamo
 
PPT
Binary search in ds
chauhankapil
 
PPT
Chapter 11 ds
Hanif Durad
 
PPTX
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
PPTX
data_structure_Chapter two_computer.pptx
Mohammed472103
 
PPTX
Binary search in data structure
Meherul1234
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
DOCX
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
PDF
Linear and Binary Search
WinNie Sjr
 
PDF
Binary search algorithm
maamir farooq
 
PDF
binary search
Abdelrahman Saleh
 
PPTX
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 
PDF
Binary search
Ramkrishna bhagat
 
PPTX
Binary Search.pptx
SheherBano57
 
PDF
In the binary search, if the array being searched has 32 elements in.pdf
arpitaeron555
 
PPTX
Divide and conquer 1
Kumar
 
PPTX
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
PDF
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 

More Related Content

Similar to BINARY SEARCH - A - DATA STRUCTURE AND ALGORITHM.pdf (20)

PPTX
Binary search algorithm.pptx
bhuvansaachi18
 
PPT
Binary Search
kunj desai
 
PPTX
Binary search
sana younas
 
PPTX
Binary Searching Algorithm PowerPoint Presentation
NicoleAngelaGilaRamo
 
PPT
Binary search in ds
chauhankapil
 
PPT
Chapter 11 ds
Hanif Durad
 
PPTX
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
PPTX
data_structure_Chapter two_computer.pptx
Mohammed472103
 
PPTX
Binary search in data structure
Meherul1234
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
DOCX
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
PDF
Linear and Binary Search
WinNie Sjr
 
PDF
Binary search algorithm
maamir farooq
 
PDF
binary search
Abdelrahman Saleh
 
PPTX
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 
PDF
Binary search
Ramkrishna bhagat
 
PPTX
Binary Search.pptx
SheherBano57
 
PDF
In the binary search, if the array being searched has 32 elements in.pdf
arpitaeron555
 
PPTX
Divide and conquer 1
Kumar
 
Binary search algorithm.pptx
bhuvansaachi18
 
Binary Search
kunj desai
 
Binary search
sana younas
 
Binary Searching Algorithm PowerPoint Presentation
NicoleAngelaGilaRamo
 
Binary search in ds
chauhankapil
 
Chapter 11 ds
Hanif Durad
 
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
data_structure_Chapter two_computer.pptx
Mohammed472103
 
Binary search in data structure
Meherul1234
 
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASI...
Sitamarhi Institute of Technology
 
Linear and Binary Search
WinNie Sjr
 
Binary search algorithm
maamir farooq
 
binary search
Abdelrahman Saleh
 
Chapter #3 (Searchinmmmg ALgorithm).pptx
hekmatyarzahir44
 
Binary search
Ramkrishna bhagat
 
Binary Search.pptx
SheherBano57
 
In the binary search, if the array being searched has 32 elements in.pdf
arpitaeron555
 
Divide and conquer 1
Kumar
 

Recently uploaded (20)

PPTX
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
PDF
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 
PPTX
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
PDF
Boost Business Efficiency with Professional Data Entry Services
eloiacs eloiacs
 
PPTX
Daily, Weekly, Monthly Report MTC March 2025.pptx
PanjiDewaPamungkas1
 
PDF
Predicting Titanic Survival Presentation
praxyfarhana
 
PPTX
最新版美国威斯康星大学河城分校毕业证(UWRF毕业证书)原版定制
taqyea
 
PDF
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
PDF
presentation4.pdf Intro to mcmc methodss
SergeyTsygankov6
 
PDF
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
PPTX
Communication_Skills_Class10_Visual.pptx
namanrastogi70555
 
PPTX
Attendance Presentation Project Excel.pptx
s2025266191
 
PPTX
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
DOCX
Artigo - Playing to Win.planejamento docx
KellyXavier15
 
PDF
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
PDF
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
DOCX
Starbucks in the Indian market through its joint venture.
sales480687
 
PDF
Measurecamp Copenhagen - Consent Context
Human37
 
PDF
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
PDF
ilide.info-tg-understanding-culture-society-and-politics-pr_127f984d2904c57ec...
jed P
 
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
Boost Business Efficiency with Professional Data Entry Services
eloiacs eloiacs
 
Daily, Weekly, Monthly Report MTC March 2025.pptx
PanjiDewaPamungkas1
 
Predicting Titanic Survival Presentation
praxyfarhana
 
最新版美国威斯康星大学河城分校毕业证(UWRF毕业证书)原版定制
taqyea
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
presentation4.pdf Intro to mcmc methodss
SergeyTsygankov6
 
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
Communication_Skills_Class10_Visual.pptx
namanrastogi70555
 
Attendance Presentation Project Excel.pptx
s2025266191
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
Artigo - Playing to Win.planejamento docx
KellyXavier15
 
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
 
Informatics Market Insights AI Workforce.pdf
karizaroxx
 
Starbucks in the Indian market through its joint venture.
sales480687
 
Measurecamp Copenhagen - Consent Context
Human37
 
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
ilide.info-tg-understanding-culture-society-and-politics-pr_127f984d2904c57ec...
jed P
 
Ad

BINARY SEARCH - A - DATA STRUCTURE AND ALGORITHM.pdf

  • 1. BINARY SEARCH GROUP 1 EDEN ROSE CONICAN LESHE SENINA GREEZE LEE OMANDAM JHON MARK ALIPOYO MACGEREM ANRO PAGLINAWAN
  • 2. INTRODUCTION • Binary search is search algorithm that finds the position of a target value within a sorted array. • Binary search is also known as half-interval search or logarithmic search. • Binary search algorithm works on the principle of Divide and Conquer. • Binary search can be implemented on only sorted list of elements.
  • 3. Binary search is a searching algorithm for finding an element’s position in a sorted array. In this approach, the element is always searched in the middle of a portion of an array. Binary search can be implemented only on a sorted list of items. If the elements are not sorted already, we need to sort them first. BINARY SEARCH WORKING Binary Search Algorithms can be implemented in two ways which are discussed below: 1. Iterative Method 2. Recursive Method
  • 4. 1. ITERATIVE METHOD • The iterative binary search method is a highly efficient algorithm for finding a specific target value within a sorted array. It works by repeatedly dividing the search interval in half, eliminating half of the remaining elements in each steps. Here how it functions: 1. Initialization • Start with the entire arrays as the search interval, defining the leftmost index (low) and rightmost index (high). • Set the middle index (mid) to the middle of the interval.
  • 5. 2. Iteration: • Comparison: Compare the target value with the element at the middle index (mid). - If the target value is equal to the middle element, the search is successful, and the index (mid) is returned. - If the target value is less than the middle element, the search continues in the left half of the interval (low to mid – 1). - If the target value is greater than the middle element, the search continues in the right half of the interval (mid + 1 to high). 3. Updating the Search Interval: • In each iteration, the search interval is halved based on the comparison result. • If the target value is less than the middle element, the right boundary (high) becomes mid -1. • If the target value is greater than the middle element, the left boundary (low) becomes mid + 1.
  • 6. 4. Termination: • The search continues until the left index (low) becomes greater than the right index (high), indicating that the target value is not present in the array. In this case, the search returns -1.
  • 7. 2. RECURSIVE METHOD • The recursive binary search algorithms is a powerful and elegant approach to efficiently finding a target value in a sorted array. It works by repeatedly dividing the search interval in half, eliminating half of the remaining elements in each steps. Here how it functions: 1. Base Case: • If the left index (low) becomes greater than the right index (high), it means that the target value is not present in the array. In this case, the function returns -1.
  • 8. 2. Recursive Steps: • Calculate the middle index (mid) of the search interval. • Compare the target value with the element at the middle index: - If the target value is equal to the middle element, the search is successful, and the index (mid) is returned. - If the target value is less than the middle element, recursively search the left half of the array (low to mid -1). - If the target value is greater than the middle element, recursively search the right half of the array (mid + 1 to high). 3. Recursion: • The function calls itself with updated search intervals (low and high) based on the comparison result, effectively dividing the problem into smaller subproblems.
  • 9. DIVIDE AND CONQUER • Divide and Conquer is the most well-known algorithm strategy. • A Divide and Conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same or related type, until this become simple enough to be solved directly. • The solutions to the sub-problems are then combine to give a solution to the original problem.
  • 10. EXAMPLE : • Consider an Array: A 0 1 2 3 4 5 6 7 8 min mid = ( min + max)/2 max If(37 == a[mid]) return mid Else if(37<a[mid]) max=mid-1 Else if(37>a[mid]) min=mid+1 20 35 37 40 45 50 51 55 67
  • 11. ALGORITHM Input : A sorted array N size of array Key value to be searched BinarySearch(a,key,n) : Set min=0 Set max=n-1 while (min < max) Set mid = (min+max)/2
  • 12. ALGORITHM If(key ==A(mid) Return mid Else if(key<A[mid]) Set max= mid – 1 Else Set min= mid + 1 End if End while Retun (-1)
  • 13. TIME COMPLEXITY • The running times complexity for Binary Search are of three types:- In Worst Case , Time Complexity : O(log n) In Average Case, Time Complexity : O(log n) In Best Case , Time Complexity : O(1)
  • 14. ADVANTAGE • Binary Search is an optimal searching algorithm using which we can desired element very efficiently. DISADVANTAGE Binary Search algoritm requires the list to be sorted. Then only method is Applicable.
  • 15. APPLICATION • The Binary Search is an efficient searching method and used to search record from database. • For solving non-linear equations with one unknown this method to used.