I am using this algorithm in my program :
for( i=0 ; i<N ; i++ )
for( j=i+1 ; j<N+1 ; j++ )
for( k=0 ; k<i ; k++ )
doWork();
Can anyone help me find the time complexity of this snippet ?
I guess for the first two loops it is
N*(N+1)/2
right ? what about the three loops all together?
Thanks to @Tim Meyer to correct me:
Simple equation gives for (N= 0,1,2,3,4,5,6, 7, 8 …) following series: 0, 0, 1, 4, 10, 20, 35, 56, 84 … , which is resolved with following formula:
So it will have O((N – 1)N(N + 1)/6) time complexity, which can be simplified to O(N^3)