Skip to content

Instantly share code, notes, and snippets.

@leonw007
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonw007/77f062bf774ba474907f to your computer and use it in GitHub Desktop.
Save leonw007/77f062bf774ba474907f to your computer and use it in GitHub Desktop.
time complexity
// 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