I've been told different things over my course on algorithms, and was wondering if I could get a definitive answer as to the time complexity of Java's System.out.println() command.
For example, what would the time complexity of the following be, with respect to N?
String stringy = "";
while(stringy.length() < N) {
System.out.println(stringy);
stringy += "X";
}
Thanks for helping out the new guy!
the Time complexity of this code is O(N*N) because it's a loop of N times that prints. I don't know what have you been told but the time complexity of printing it not worse then O(N) in Java.
in your code you add "X" to each line, and therefor your printing will be:
so it's complexity is calculated as an Arithmetic progression and we get:
to read on how the command work you can read here or here: