java - Order of growth of the code below -


what order of growth of worst case running time of following code fragment function of n? 

int sum = 0;  (int = 0; i*i < n; i++)     (int j = 0; j*j < 4*n; j++)         (int k = 0; k < n*n; k++)             sum++; 

  1. outer loop runs until i*i >= n, means runs total of
    sqrt(n) times.
  2. for each iteration of outer loop, inner loop runs until j*j >= 4*n, means runs sqrt(4n) = 2sqrt(n) times.
  3. for each iteration of middle loop, inner loop runs until k>=n*n, means n^2 iterations.
  4. increasing sum done in constant time.

multiply above because (3) each iteration of (2), , (2) each iteration of (1), , sqrt(n)*2sqrt(n)*n^2 = 2n^3, in o(n^3)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -