In this tutorial, you will learn about Binary Search Algorithm, how it works and how to implement it with Java

### What is Binary Search?

Binary Search is an algorithm for finding the position of a target value within a sorted array

### How Binary Search works

Binary Search works on sorted array. Let's say you have a sorted array A, middle element is A_{M}, target value is T. The algorithm will compare A_{M} with T

If A

_{M}= T, return position of A_{M}If A

_{M}< T, the search continues with the lower half of the array AIf A

_{M}> T, the search continues with the upper half of A

### Implementation example with Java

```
```

Time complexity O(logN)

Space complexity O(N)