# Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

## Binary Search

See original GitHub issue

### Description

Binary search is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array.

``````Input  : 10 20 30 40 50 60 70 80 90 100
Target : 30

Output : 2
``````

### Steps to implement Binary Search

1. Compare x with the middle element.
2. If x matches with middle element, we return the mid index.
3. Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half.
4. Else (x is smaller) recur for the left half.
5. End
``````10 20 30 40 50 60 70 80 90 100
------------------------------
^
``````
``````10 20 30 40 50 60 70 80 90 100
--------------
^
30 => Found
``````

### Issue Analytics

• State:
• Created 5 months ago

1reaction
harshraj8843commented, Oct 9, 2022

The workflow for adding a new dsa program is as follows :

0reactions
harshraj8843commented, Oct 9, 2022

#### Top Results From Across the Web

Binary Search
Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. The idea of binary...
Binary search algorithm
In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position...
Binary Search (With Code)
Binary Search is a searching algorithm for finding an element's position in a sorted array. In this approach, the element is always searched...
Binary search (article) | Algorithms
Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing in half...
Data Structure and Algorithms Binary Search
Binary search is a fast search algorithm with run-time complexity of Ο(log n). This search algorithm works on the principle of divide and...

#### Troubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free