0% found this document useful (0 votes)
6 views6 pages

On Binary Search2 Humza

The binary search algorithm is an efficient method for finding an item in a sorted list using a divide-and-conquer strategy, with a time complexity of O(log n). It involves initializing pointers, comparing the target value to the middle element, and narrowing down the search space based on the comparison. While it is faster than linear search for large datasets, it requires the data to be sorted, which can be time-consuming.

Uploaded by

Honey Solanki
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)
6 views6 pages

On Binary Search2 Humza

The binary search algorithm is an efficient method for finding an item in a sorted list using a divide-and-conquer strategy, with a time complexity of O(log n). It involves initializing pointers, comparing the target value to the middle element, and narrowing down the search space based on the comparison. While it is faster than linear search for large datasets, it requires the data to be sorted, which can be time-consuming.

Uploaded by

Honey Solanki
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
You are on page 1/ 6

Binary Search Algorithm

Efficient Searching In Sorted Arrays

1
Binary Search

A binary search looks for an


item in a sorted list using a
divide-and-conquer strategy
 It works by repeatedly dividing
the search space in half

2
How Binary Search Woks ?
1. Initialize three pointers: Mid, Low,
High.
2. Compare the target value to the
Middle element of the array.
3. If they are equal the search is
complete.
4. If the target is less than the middle
element, repeat the search in left
half.
5. If the target is greater, repeat on the
right half.

3
Binary search example

4
Unsuccessful
binary
search
example

5
Advantages and Disadvantages
 Advantages of Binary Search
 Efficiency: Binary search has a time
complexity of O(log n), making it significantly
faster than linear search, especially for large
datasets.
 Wide Applicability: It can be used for
various search problems, including
searching in sorted arrays, sorted linked
lists, and sorted files.
 Disadvantages of Binary Search
 Requires Sorted Data: must be sorted in
ascending or descending order. Sorting itself
can be time-consuming, especially for large
datasets.

You might also like