0% found this document useful (0 votes)
3 views

Binary_Search_Visualization_Assignment

Binary Search is an efficient algorithm for locating a target element in a sorted array with a time complexity of O(log n). It works by repeatedly dividing the search interval in half and comparing the middle element to the target. The document includes pseudocode for the algorithm and mentions the inclusion of visualization images.

Uploaded by

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

Binary_Search_Visualization_Assignment

Binary Search is an efficient algorithm for locating a target element in a sorted array with a time complexity of O(log n). It works by repeatedly dividing the search interval in half and comparing the middle element to the target. The document includes pseudocode for the algorithm and mentions the inclusion of visualization images.

Uploaded by

Tharun Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Visualization of Binary Search

1. Introduction
Binary Search is an efficient algorithm for finding a target element in a sorted array. It
repeatedly divides the search interval in half and compares the middle element with the
target. Its time complexity is O(log n), making it faster than linear search for large datasets.

2. How Binary Search Works


The Binary Search algorithm follows these steps:
1. Set the low and high pointers to the start and end of the array.
2. Find the middle element and compare it to the target.
3. If the middle element matches, return its index.
4. If the target is smaller, repeat the search on the left half; else, on the right half.
5. Repeat until the element is found or the search space is exhausted.

3. Pseudocode
 Binary Search Function:

function 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 // Element not found

4. Visualization Images
Paste your binary search visualization images below this section.

You might also like