Analyzing worst case order-of-growth
问题 I'm trying to analyze the worst case order of growth as a function of N for this algorithm: for (int i = N*N; i > 1; i = i/2) for (int j = 0; j < i; j++) { total++; } What I'm trying is to analyze how many times the line total++ will run by looking at the inner and outer loops. The inner loop should run (N^2)/2 times. The outer loop I don't know. Could anyone point me in the right direction? 回答1: The statement total++; shall run following number of times: = N^2 + N^2 / 2 + N^2 / 4 ... N^2 / 2