Created
September 8, 2012 12:22
-
-
Save mebubo/3674368 to your computer and use it in GitHub Desktop.
Estimate order of growth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What is the order of growth of the worst case running time of the following code fragment as a function of N? | |
int sum = 0; | |
for (int i = 1; i <= N*N; i = i*2) | |
for (int j = 0; j < i; j++) | |
sum++; | |
The body of the innermost loop executes 1 + 2 + 4 + 8 + ... + N^2 ~ 2 N^2 times. | |
int sum = 0; | |
for (int i = 1; i <= N; i++) | |
for (int j = 1; j <= i*i; j++) | |
sum++; | |
The body of the innermost loop executes 1 + 4 + 9 + 16 + ... + N^2 ~ 1/3 N^3 times. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment