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

Правка en1, от roycf123, 2023-08-04 21:28:42

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.

Теги time complexity, sqrt

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский roycf123 2023-08-04 21:30:08 18 (published)
en1 Английский roycf123 2023-08-04 21:28:42 837 Initial revision (saved to drafts)