Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Java include the time/space complexity of each function in the javadoc?

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.

like image 907
jan1 Avatar asked Apr 10 '12 15:04

jan1


People also ask

What is time and space complexity in Java?

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.

How to find time and space complexity of an 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.

What is space complexity explain?

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.


1 Answers

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.

like image 158
Peter Lawrey Avatar answered Oct 21 '22 21:10

Peter Lawrey