Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Created February 20, 2015 04:17
Show Gist options
  • Save greggnakamura/2436822139e13556c0c7 to your computer and use it in GitHub Desktop.
Save greggnakamura/2436822139e13556c0c7 to your computer and use it in GitHub Desktop.
Javascript: # of steps it takes to execute naive(a, b) as a function of 'a'
var naive = function (a, b) {
var x = a; // 1 unit
var y = b; // 1 unit
var z = 0; // 1 unit
while (x > 0) { // runs twice
z = z + y;
x = x - 1;
return z;
}
};
var time = function (a) {
/* # of steps it takes to execute naive(a, b) as a function of 'a' */
return 2*a + 3;
};
var naiveTest = naive(10,5);
var timeTest = time(10);
console.log('Naive test: ' + naiveTest + ' && Time test: ' + timeTest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment