> For the complete documentation index, see [llms.txt](https://haoyu2.gitbook.io/cs310/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haoyu2.gitbook.io/cs310/untitled.md).

# Bisect

## Bisect\_left

```java
// all i < lo, arr[i] < x
int bisect_left(int arr, int x){
    int lo = 0, hi = arr.length, mid;
    while (lo < hi):
        mid = (lo+hi) / 2;
        if (a[mid] < x) lo = mid+1;
        else hi = mid;
    return lo;

}
    

```

## Bisect\_right

```java
// all i >= lo, arr[i] > x
int bisect_left(int arr, int x){
    int lo = 0, hi = arr.length, mid;
    while (lo < hi):
        mid = (lo+hi) / 2;
        if (a[mid] > x) hi = mid;
        else lo = mid + 1;
    return lo;

}
```
