0% found this document useful (0 votes)
25 views9 pages

Sour BH Title

Binary Search is an efficient algorithm for finding an item in a sorted list with a time complexity of O(log n). It works by repeatedly dividing the search interval in half and is applicable only to random access data structures like arrays. The algorithm has various applications, including database searches and dictionary lookups, but is limited to sorted arrays.

Uploaded by

ajayjallendhra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Sour BH Title

Binary Search is an efficient algorithm for finding an item in a sorted list with a time complexity of O(log n). It works by repeatedly dividing the search interval in half and is applicable only to random access data structures like arrays. The algorithm has various applications, including database searches and dictionary lookups, but is limited to sorted arrays.

Uploaded by

ajayjallendhra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Title: Binary Search

Algorithum
Presented by: Sourbh
Class: [Link]. CSE Batch 2
Roll no.: 230010130134
Introduction
• What is Binary Search?

• It is an efficient algorithm for finding an item from a sorted list.

• Time Complexity: O(log n)


Prerequisites
• The list must be sorted in increasing or decreasing order.

• This works only on random access data structures.

• Like arrays, not linked lists.


Concept
• Repeatedly divide the search interval in half.

• Compare the middle element with the target:


• If equal, return position.
• If target < middle, search left half.
• If target > middle, search right half.
Algorithm
• binarySearch(arr, target):
low = 0
high = length(arr) - 1

while low <= high:


mid = (low + high) / 2
if arr[mid] == target:
return mid
else if arr[mid] < target:
low = mid + 1
else:
high = mid – 1
return -1
Time and Space Complexity
• Time complexity of Binary Search is:
Time: O(log n)

• Space complexity for Binary Search is:

O(1) for iterative,


O(log n) for recursive(due to call stack)
Applications
• Searching in databases.
• Dictionary lookups.
• Games (guessing strategies).
• Binary search on answers in optimization problems,etc.
Limitations
• It only works on sorted arrays

• It is not suitable for linked lists without modification,etc.


Summary
• It is a very fast and efficient method for searching operations.

• It requires sorted data.

• This is widely used in real world scenarios,etc.

You might also like