yesiamrajeev / Hacktoberfest2024

Do contribute to this repository and gain experience. Happy-Hacking.
27 stars 116 forks source link

Add binary_search.cpp: Implement binary search algorithm #206

Closed milesmoralis2411 closed 3 weeks ago

milesmoralis2411 commented 3 weeks ago

This C++ program implements the Binary Search algorithm, which efficiently searches for a target value in a sorted array. The program takes a sorted array and a target value as input, and it returns the index of the target if found, or -1 if the target is not present in the array. The algorithm operates with a time complexity of O(log n), making it suitable for large datasets. This implementation demonstrates how to use iterative binary search to locate elements efficiently.

Example Usage: Input: arr = [1, 2, 3, 4, 5, 6, 7], target = 5 Output: Element found at index: 4