Order the common complexity classes according to their growth rate
Identify the complexity classes of common sort methods
Sort Name | Time Complexity | Space Complexity |
---|---|---|
bubble | O(__) | O(_) |
selection | O(__) | O(_) |
insertion | O(__) | O(_) |
merge | O(__) | O(_) |
quick | O(__) | O(_) |
Identify complexity classes of code
// O(_) ?
function example1(n) {
for (let i = 1; i <= 20; i++) {
console.log(i);
}
}
// O(_) ?
function example2(n) {
for (let i = 1; i <= n; i++) {
for (let j = 1; j <= n; j++) {
console.log(`${i}, ${j}`);
}
}
}
// O(_) ?
function example3(n) {
console.log(n);
if (n === 1) return;
example3(n - 1);
example3(n - 1);
}
Apply memoization to recursive problems to make them less than polynomial time.
Apply tabulation to iterative problems to make them less than polynomial time.