+ 1

What will be the time complexity when functions like reverse is used?

Analysis of time complexity needs to be clear

14th Aug 2020, 1:42 PM
alagammai uma
alagammai uma - avatar
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.
14th Aug 2020, 2:39 PM
Avinesh
Avinesh - avatar
+ 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)
14th Aug 2020, 1:59 PM
Taste
Taste - avatar
0
I asked like if I use StringBuffer a="hi hello"; System. out.print(a.reverse());
14th Aug 2020, 2:01 PM
alagammai uma
alagammai uma - avatar
0
Then what would be the time complexity?
14th Aug 2020, 2:01 PM
alagammai uma
alagammai uma - avatar
0
Ok then what about other default functions like reverse?
14th Aug 2020, 4:53 PM
alagammai uma
alagammai uma - avatar