SlideShare a Scribd company logo
Analysis of Algorithm
BINARY SEARCH
Presented by
Raunak, Ankush, Sukalyan, Aziza,
Sweta & Hasibul
CONTENTS
1. Introduction
2. Algorithm
3. Example
4. Time Complexity
5. Advantages and Disadvantages
6. Applications
Binary Search 2
INTRODUCTION
 Binary Search is the search technique that works efficiently on sorted lists. Hence, to
search an element into some list using the binary search technique, we must ensure
that the list is sorted.
 Binary search follows the divide and conquer approach in which the list is divided into
two halves, and the item is compared with the middle element of the list. If the match
is found then, the location of the middle element is returned. Otherwise, we search
into either of the halves depending upon the result produced through the match.
Binary Search 3
 Binary Search is also known as half-interval search or logarithmic search, is a search
algorithm that finds the position of target value within a sorted array.
 Binary Search runs in at worst logarithmic time, making {O(log n)} comparisons,
where {n} is the number of elements in the array and {log} is the binary algorithm; and
using only constant {(O(1))} space.
Binary Search 4
 Difference between Linear Search and Binary Search –
Binary Search 5
Basis of Comparison Linear Search Binary Search
Definition The linear search starts
searching from the first
element and compares each
element with a searched
element till the element is not
found.
It finds the position of the
searched element by finding the
middle element of the array.
Approach It is based on the sequential
approach.
It is based on the divide and
conquer approach.
Size It is preferrable for the small-
sized data sets.
It is preferrable for the large-size
data sets.
Efficiency It is less efficient in the case
of large-size data sets.
It is more efficient in the case of
large-size data sets.
Sorted data In a linear search, the
elements don't need to be
arranged in sorted order.
The pre-condition for the binary
search is that the elements must
be arranged in a sorted order.
ALGORITHM
 There are two methods to implement the binary search algorithm –
 Iterative Method:
o If the target value is equal to the middle element, its position in the array is
returned.
o If the target value is less than the middle element, then we continue the
search in the lower half of the array.
o If the target value is greater than the middle element, then we continue
the search in the upper half of the array.
 Recursive Method:
o Recursive implementation of binary search algorithm, in the method
binarySearch(), follows almost the same logic as iterative version, except
for a couple of differences.
Binary Search 6
Now, let’s see the algorithm of binary search –
Binary_Search(a, lower_bound, upper_bound, val)
Step 1: set start = lower_bound, end = upper_bound, pos = - 1
Step 2: repeat steps 3 and 4 while start <=end
Step 3: set mid = (start + end)/2
Step 4: if a[mid] = val
set pos = mid
print pos
Binary Search 7
go to step 6
else if a[mid] > val
set end = mid - 1
else
set start = mid + 1
[end of if]
[end of loop]
Step 5: if pos = -1
print "value is not present in the array"
[end of if]
Step 6: exit
Binary Search 8
EXAMPLE
Let the elements of array are –
Let the element to search is, K=56
We have to use the below formula to calculate the mid of the array –
mid=(start+end)/2
So, in the given array –
start = 0, end = 8 and mid = (0+8)/2 = 4
So, 4 is the mid of the array.
Binary Search 9
So, mid=4
Binary Search 10
Now, the element to search is found. So algorithm will return the index of the element
matched.
Binary Search 11
TIME COMPLEXITY
Now, let's see the time complexity of Binary search in the best case, average case, and
worst case.
1. Best Case –
 The element to be search is in the middle of the list.
 In this case, the element is found in the first step itself and this involves 1
comparison.
 Therefore, the Best Case Time Complexity of Binary Search is O(1).
Binary Search 12
2. Average Case –
 The average case time complexity of Binary search is O(log n).
3. Worst Case –
 The element is to search is in the first index or last index.
 In this case, the total number of comparisons required is {log n} comparisons.
 Therefore, the worst case time complexity of Binary Search is O(log n).
Binary Search 13
Time Complexity:
Space Complexity
 The Space Complexity of Binary Search is O(1).
Binary Search 14
Case Time Complexity
Best Case O(1)
Average Case O(log n)
Worst Case O(log n)
Space Complexity O(1)
ADVANTAGES & DISADVANTAGES
 Advantages of Binary Search:
 It is better than a linear search algorithm since its run time complexity is O(log
n).
 At each iteration, the binary search algorithm eliminates half of the list and
significantly reduces the search space.
 The binary search algorithm works even when the array is rotated by some
position and finds the target element.
Binary Search 15
 Disadvantages of Binary Search:
 The recursive method uses stack space.
 Binary search is error-prone. Some of the common errors are as follows:
 Off-by-one errors: While determining the boundary of the next interval, there
might be overlapping errors.
o Handling of duplicate items: While returning the first item, it might be
possible we return a subsequence similar item.
o Numerical underflows/overflows: In huge arrays when computing indices.
There might be overflows
o Recursive vs non-recursive implementation, which should be considered
while designing as recursive takes stack space.
Binary Search 16
APPLICATIONS
The applications of Binary Search are:
1. Find an element in a sorted array
2. Applications of Binary Search beyond arrays
 To find if n is a square of an integer
 Find the first value greater than or equal to x in a given array of sorted
integers
 Find the frequency of a given target value in an array of integers
 Find the peak of an array which increases and then decreases
 A sorted array is rotated n times. Search for a target value in the array
Binary Search 17
3. Real life applications of Binary Search –
 Dictionary
 Debugging a linear piece of code
 Figuring out resource requirements
for a large system
 Find values in sorted collection
 Semiconductor test programs
 Numerical solutions to an equation
18
Binary Search
REFERENCE
 GeeksForGeeks [https://www.geeksforgeeks.org/]
 Javatpoint [https://www.javatpoint.com/]
 SlideShare [https://www.slideshare.net/]
Binary Search 19
THANK YOU!
Binary Search 20

More Related Content

What's hot

Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
Kaushal Shah
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
Nisha Soms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Mohammed Hussein
 
Binary search
Binary search Binary search
Binary search
Ramkrishna bhagat
 
Searching
SearchingSearching
Searching
Ashim Lamichhane
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
prabhakar jalasutram
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
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
03446940736
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
NeoClassical
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
District Administration
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Space complexity
Space complexitySpace complexity
Space complexity
Bhanusree Koduru
 
Searching algorithm
Searching algorithmSearching algorithm
Searching algorithm
MG Thushara Pradeesh
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
asmhemu
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Binary search
Binary searchBinary search
Binary search
Gaurav Solanki
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 

What's hot (20)

Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Binary search
Binary search Binary search
Binary search
 
Searching
SearchingSearching
Searching
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort 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
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Space complexity
Space complexitySpace complexity
Space complexity
 
Searching algorithm
Searching algorithmSearching algorithm
Searching algorithm
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Binary search
Binary searchBinary search
Binary search
 
Binary Search
Binary SearchBinary Search
Binary Search
 

Similar to Analysis of Algorithm - Binary Search.pptx

advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
Aftabali702240
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
ThenmozhiK5
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
sajinis3
 
Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++
shahidameer8
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
SSN College of Engineering, Kalavakkam
 
Binary.pptx
Binary.pptxBinary.pptx
Binary.pptx
hasantahamid15
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Abdul Khan
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
FazalRehman79
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sortingguest2cb109
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
IRJET Journal
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
chauhankapil
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
LavanyaJ28
 
Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms  in Data StructuresSearching and Sorting Algorithms  in Data Structures
Searching and Sorting Algorithms in Data Structures
poongothai11
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
maamir farooq
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
Anushdika Jeganathan
 
arrays in c
arrays in carrays in c
arrays in c
vidhi mehta
 

Similar to Analysis of Algorithm - Binary Search.pptx (20)

advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Ch05 Black Jack
Ch05  Black  JackCh05  Black  Jack
Ch05 Black Jack
 
Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
 
Binary.pptx
Binary.pptxBinary.pptx
Binary.pptx
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms  in Data StructuresSearching and Sorting Algorithms  in Data Structures
Searching and Sorting Algorithms in Data Structures
 
Binary search algorithm
Binary search algorithmBinary search algorithm
Binary search algorithm
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
 
arrays in c
arrays in carrays in c
arrays in c
 

More from Maulana Abul Kalam Azad University of Technology

Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT) Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT)
Maulana Abul Kalam Azad University of Technology
 
IOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptx
IOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptxIOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptx
IOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptx
Maulana Abul Kalam Azad University of Technology
 
SMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptx
SMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptxSMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptx
SMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptx
Maulana Abul Kalam Azad University of Technology
 
Interprocess Communication.pptx
Interprocess Communication.pptxInterprocess Communication.pptx
Interprocess Communication.pptx
Maulana Abul Kalam Azad University of Technology
 
Green house gases & effects
Green house gases & effectsGreen house gases & effects
8085 Microprocessor
8085 Microprocessor8085 Microprocessor
Samsung Galaxy S9+
Samsung Galaxy S9+Samsung Galaxy S9+
5G Wireless Technology
5G Wireless Technology5G Wireless Technology
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Introduction to manufacturing process
Introduction to manufacturing processIntroduction to manufacturing process
Introduction to manufacturing process
Maulana Abul Kalam Azad University of Technology
 
Samsung Galaxy S8 Plus
Samsung Galaxy S8 PlusSamsung Galaxy S8 Plus
Robotic Science
Robotic ScienceRobotic Science

More from Maulana Abul Kalam Azad University of Technology (12)

Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT) Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT)
 
IOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptx
IOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptxIOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptx
IOT BASED RFID SMART DOOR LOCK SYSTEM USING NODE MCU - MAJOR.pptx
 
SMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptx
SMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptxSMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptx
SMART SECURITY SYSTEM USING IOT - MID-TERM PROJECT.pptx
 
Interprocess Communication.pptx
Interprocess Communication.pptxInterprocess Communication.pptx
Interprocess Communication.pptx
 
Green house gases & effects
Green house gases & effectsGreen house gases & effects
Green house gases & effects
 
8085 Microprocessor
8085 Microprocessor8085 Microprocessor
8085 Microprocessor
 
Samsung Galaxy S9+
Samsung Galaxy S9+Samsung Galaxy S9+
Samsung Galaxy S9+
 
5G Wireless Technology
5G Wireless Technology5G Wireless Technology
5G Wireless Technology
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Introduction to manufacturing process
Introduction to manufacturing processIntroduction to manufacturing process
Introduction to manufacturing process
 
Samsung Galaxy S8 Plus
Samsung Galaxy S8 PlusSamsung Galaxy S8 Plus
Samsung Galaxy S8 Plus
 
Robotic Science
Robotic ScienceRobotic Science
Robotic Science
 

Recently uploaded

Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
vcaxypu
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
nscud
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
ewymefz
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 

Recently uploaded (20)

Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 

Analysis of Algorithm - Binary Search.pptx

  • 1. Analysis of Algorithm BINARY SEARCH Presented by Raunak, Ankush, Sukalyan, Aziza, Sweta & Hasibul
  • 2. CONTENTS 1. Introduction 2. Algorithm 3. Example 4. Time Complexity 5. Advantages and Disadvantages 6. Applications Binary Search 2
  • 3. INTRODUCTION  Binary Search is the search technique that works efficiently on sorted lists. Hence, to search an element into some list using the binary search technique, we must ensure that the list is sorted.  Binary search follows the divide and conquer approach in which the list is divided into two halves, and the item is compared with the middle element of the list. If the match is found then, the location of the middle element is returned. Otherwise, we search into either of the halves depending upon the result produced through the match. Binary Search 3
  • 4.  Binary Search is also known as half-interval search or logarithmic search, is a search algorithm that finds the position of target value within a sorted array.  Binary Search runs in at worst logarithmic time, making {O(log n)} comparisons, where {n} is the number of elements in the array and {log} is the binary algorithm; and using only constant {(O(1))} space. Binary Search 4
  • 5.  Difference between Linear Search and Binary Search – Binary Search 5 Basis of Comparison Linear Search Binary Search Definition The linear search starts searching from the first element and compares each element with a searched element till the element is not found. It finds the position of the searched element by finding the middle element of the array. Approach It is based on the sequential approach. It is based on the divide and conquer approach. Size It is preferrable for the small- sized data sets. It is preferrable for the large-size data sets. Efficiency It is less efficient in the case of large-size data sets. It is more efficient in the case of large-size data sets. Sorted data In a linear search, the elements don't need to be arranged in sorted order. The pre-condition for the binary search is that the elements must be arranged in a sorted order.
  • 6. ALGORITHM  There are two methods to implement the binary search algorithm –  Iterative Method: o If the target value is equal to the middle element, its position in the array is returned. o If the target value is less than the middle element, then we continue the search in the lower half of the array. o If the target value is greater than the middle element, then we continue the search in the upper half of the array.  Recursive Method: o Recursive implementation of binary search algorithm, in the method binarySearch(), follows almost the same logic as iterative version, except for a couple of differences. Binary Search 6
  • 7. Now, let’s see the algorithm of binary search – Binary_Search(a, lower_bound, upper_bound, val) Step 1: set start = lower_bound, end = upper_bound, pos = - 1 Step 2: repeat steps 3 and 4 while start <=end Step 3: set mid = (start + end)/2 Step 4: if a[mid] = val set pos = mid print pos Binary Search 7
  • 8. go to step 6 else if a[mid] > val set end = mid - 1 else set start = mid + 1 [end of if] [end of loop] Step 5: if pos = -1 print "value is not present in the array" [end of if] Step 6: exit Binary Search 8
  • 9. EXAMPLE Let the elements of array are – Let the element to search is, K=56 We have to use the below formula to calculate the mid of the array – mid=(start+end)/2 So, in the given array – start = 0, end = 8 and mid = (0+8)/2 = 4 So, 4 is the mid of the array. Binary Search 9
  • 11. Now, the element to search is found. So algorithm will return the index of the element matched. Binary Search 11
  • 12. TIME COMPLEXITY Now, let's see the time complexity of Binary search in the best case, average case, and worst case. 1. Best Case –  The element to be search is in the middle of the list.  In this case, the element is found in the first step itself and this involves 1 comparison.  Therefore, the Best Case Time Complexity of Binary Search is O(1). Binary Search 12
  • 13. 2. Average Case –  The average case time complexity of Binary search is O(log n). 3. Worst Case –  The element is to search is in the first index or last index.  In this case, the total number of comparisons required is {log n} comparisons.  Therefore, the worst case time complexity of Binary Search is O(log n). Binary Search 13
  • 14. Time Complexity: Space Complexity  The Space Complexity of Binary Search is O(1). Binary Search 14 Case Time Complexity Best Case O(1) Average Case O(log n) Worst Case O(log n) Space Complexity O(1)
  • 15. ADVANTAGES & DISADVANTAGES  Advantages of Binary Search:  It is better than a linear search algorithm since its run time complexity is O(log n).  At each iteration, the binary search algorithm eliminates half of the list and significantly reduces the search space.  The binary search algorithm works even when the array is rotated by some position and finds the target element. Binary Search 15
  • 16.  Disadvantages of Binary Search:  The recursive method uses stack space.  Binary search is error-prone. Some of the common errors are as follows:  Off-by-one errors: While determining the boundary of the next interval, there might be overlapping errors. o Handling of duplicate items: While returning the first item, it might be possible we return a subsequence similar item. o Numerical underflows/overflows: In huge arrays when computing indices. There might be overflows o Recursive vs non-recursive implementation, which should be considered while designing as recursive takes stack space. Binary Search 16
  • 17. APPLICATIONS The applications of Binary Search are: 1. Find an element in a sorted array 2. Applications of Binary Search beyond arrays  To find if n is a square of an integer  Find the first value greater than or equal to x in a given array of sorted integers  Find the frequency of a given target value in an array of integers  Find the peak of an array which increases and then decreases  A sorted array is rotated n times. Search for a target value in the array Binary Search 17
  • 18. 3. Real life applications of Binary Search –  Dictionary  Debugging a linear piece of code  Figuring out resource requirements for a large system  Find values in sorted collection  Semiconductor test programs  Numerical solutions to an equation 18 Binary Search
  • 19. REFERENCE  GeeksForGeeks [https://www.geeksforgeeks.org/]  Javatpoint [https://www.javatpoint.com/]  SlideShare [https://www.slideshare.net/] Binary Search 19