Last active
August 29, 2015 14:27
-
-
Save leonw007/77f062bf774ba474907f to your computer and use it in GitHub Desktop.
time complexity
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
// assume n>m | |
//case 1 | |
for(int i=0; i< n ; i++) { | |
someOperation(); // this line takes O(n) time | |
} | |
//case 2 | |
for(int i=0; i< n ; i++) { | |
if (i < (n/m) ) { | |
someOperation(); // this line takes O(n) time | |
} | |
} | |
//case 3 | |
int t = n/m; | |
for(int i=0; i< n ; i++) { | |
if (i < t ) { | |
someOperation(); // this line takes O(n) time | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment