Created
February 20, 2015 04:17
-
-
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'
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
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