Recently, I have encountered many situations in which I was asked the complexity of std::sqrt() in C++. Since my early cp days, I have known the time complexity of std::sqrt()
to be O(sqrt(n))
, the reason being this and a few other youtube channels. I was using C++17
at that point.
A friend of mine suggested it to be O(logn)
in C++20
after he tested it by printing cout<<sqrtl(N)
, where N
was set as 1e18
. The code compiled in 10 ms, giving the correct ans.
Later on, I ran the same code in C++14
in ideone and the code still compiled in 10 ms. This made me really confused...
I would really appreciate if someone helps me with this. I looked it up in cpp-reference but couldn't find it.