Binary Search on double

Can anyone suggest me a good blog for binary search on double ? I found these type of implementation on different blog without explanation. Could anyone explain it ?
Type 1:

#include<bits/stdc++.h>
using namespace std;

//We want to find an element which a<0.0000001

const float target = 0.0000001;

int main(){
    float l=0.00000000,r=100000.00000000;
    cout << l << " " << r;
    while((r-l)>0.0000000001){
        float mid = (float)((l+r)/2);
        cout << mid << endl;
        if(mid>target) r=mid;
        else l=mid;
    }cout << l;
 }

Type 2:

int iterations = 0;
while(iterations < 300)
{
  // your binary search logic
  iterations++;
}
1 Like

video
jump to 23:25
thanks to @errichto for the crystal clear explanation of binary search…

3 Likes

thanks

1 Like