Skip to content

Instantly share code, notes, and snippets.

@eengineergz
Created February 27, 2021 04:45
Show Gist options
  • Save eengineergz/cc953ba2bd6e1d6f524a6d8b297aad5b to your computer and use it in GitHub Desktop.
Save eengineergz/cc953ba2bd6e1d6f524a6d8b297aad5b to your computer and use it in GitHub Desktop.
// O(n)
function linear1(n) {
for (let i = 1; i <= n; i++) {
console.log(i);
}
}
// O(n), where n is the length of the array
function linear2(array) {
for (let i = 0; i < array.length; i++) {
console.log(i);
}
}
// O(n)
function linear3(n) {
if (n === 1) return;
linear3(n - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment