Hi I want to know what is the time complexity of the "replaceAll" function of the String class but I can't find any information on it.(http://docs.oracle.com/javase/6/docs/api/java/lang/String.html)
Wouldn't it be better for Java to include the complexities in the Javadoc? I believe it's a very important thing for someone to know.
Time complexity is the time taken by the algorithm to execute each set of instructions. It is always better to select the most efficient algorithm when a simple problem can solve with different methods. Space complexity is usually referred to as the amount of memory consumed by the algorithm.
Algorithm ComplexityTime Factor − The time is calculated or measured by counting the number of key operations such as comparisons in sorting algorithm. Space Factor − The space is calculated or measured by counting the maximum memory space required by the algorithm.
The space complexity of an algorithm or a computer program is the amount of memory space required to solve an instance of the computational problem as a function of characteristics of the input. It is the memory required by an algorithm until it executes completely.
Most functions have fairly straight forward time complexities. AFAIK, replaceAll is O(n)
IMHO. Nothing beats testing this yourself empirically e.g. with a profiler, because its highly likely that 99% of the methods you use have little to no impact on the performance of your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With