Often no. Methods like array.splice(), string.indexOf(), or list.contains() execute hidden O(N) traversal loops under the hood.
How to Calculate Time Complexity in an Interview
Are built-in language methods O(1)?
The answer
More FAQs in How to Calculate Time Complexity in an Interview
Identify all loops. Add sequential loops together. Multiply nested loops. Expose the complexity of built-in methods, and drop non-dominant terms and constants.
It is O(N) + O(N^2). Since N^2 is the dominant term that scales the fastest, the final time complexity is strictly O(N^2).
No, Big O calculates the worst-case scenario. Even if an if-statement breaks the loop on the first try, the algorithm is still classified as O(N).
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.