A = {5, 3, 8, 9, 16} After one iteration A = {3-5,8-3,9-8,16-9}={-2,5,1,7} After second iteration A = {5-(-2),1-5,7-1} sum =7+(-4)+6=9 Given an array, return sum after n iterations
my sol/ void abc(int arr[],n) { for(i=0;i<n;i++) arr[i]=arr[i+1]-arr[i]; abc(arr,n-1); } I wana ask that the complexity is o(n) or o(n)2......as loop is executed n times..say n is 10...so fxn is called 10 times....i.e 10 n..and ignoring n it comes out to be...n......but if we implemeted with 2 loops then complexity is n2 ...and both sol are taking same no of iterations...please tell whether complexity is n or n2 for above code....if it is n2 then how??? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.