Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Created July 11, 2014 17:49
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 jfhbrook/730c9e11928dc6a79295 to your computer and use it in GitHub Desktop.
Save jfhbrook/730c9e11928dc6a79295 to your computer and use it in GitHub Desktop.
I HERD U LIEK RUNTIME COMPLEXITY PUZZLES

What is the runtime complexity of:

for (var i = 1; i <= N; i *= 2) {
  for (var j = 1; j <= N; j *= 2) {
    for (var k = 1; k <= i; k++) {
      constantTime();
    }
  }
}

(ie, how many iterations does this gnar-dogg nested loop run through?)

@jfhbrook
Copy link
Author

I (we) don't know the answer, by the way. But it's kind of an interesting math puzzle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment