Time Complexity of std::sqrt() , O(sqrt(n)) or O(logn)?

Revision en2, by roycf123, 2023-08-04 21:30:08

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.

Tags time complexity, sqrt

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English roycf123 2023-08-04 21:30:08 18 (published)
en1 English roycf123 2023-08-04 21:28:42 837 Initial revision (saved to drafts)