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.