1 votes 1 votes void xyz(char *s) { if(s[0]=='\0') return; xyz(s+1); xyz(s+1); printf("%c",s[0]); } void main() { xyz("123"); } if the input string constant is of length $n$ then what is the time complexity? $O(2^n)$ $O(n^2)$ $O(n)$ $O(n\log n)$ Algorithms recursion + – Nishikant kumar asked Nov 11, 2015 Nishikant kumar 495 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 3 votes 3 votes Since in the output is of length 7 it means that there were 7 non trivial function calls in total which is (2$^{n}$ - 1) and hence the time complexity is O(2$^{n}$). Riya Roy(Arayana) answered Nov 11, 2015 • selected Nov 12, 2015 by Pooja Palod Riya Roy(Arayana) comment Share Follow See 1 comment See all 1 1 comment reply Arjun commented Nov 11, 2015 reply Follow Share $T(n) = 2T(n-1) + 1$ 2 votes 2 votes Please log in or register to add a comment.