+ 1
What will be the time complexity when functions like reverse is used?
Analysis of time complexity needs to be clear
5 ответов
0
alagammai uma the time complexity of reverse method would be O(n) only. You cannot reverse it faster than that since you need to iterate over each character atleast once.
+ 1
depend on how its implemented.
lets just say reverse is only itterate and taking its value from the back
for (int i = n-1; i>= 0 ; i--)
the complexity should be O(n)
0
I asked like if I use
StringBuffer a="hi hello";
System. out.print(a.reverse());
0
Then what would be the time complexity?
0
Ok then what about other default functions like reverse?