Quick actions

cmd+k|ctrl+k

Navigation

Languages

Big O #4

Snippet info

Language

JavaScript

Visibility

public

Author

my.samnang

Created

2025-02-06T21:56:42.931626Z

Updated

2025-02-06T22:06:57.424794Z

// Rule #4 drop non dominants

function printAllNumbersThenAllPairSums(numbers) {
    
    console.log('these are the numbers:');
    numbers.forEach(function(number) {
        console.log(number);
    });
    
   console.log('and these are their sums:');
    numbers.forEach(function(firstNumber) {
        numbers.forEach(function(secondNumber) {
            console.log(firstNumber + secondNumber);
        });
    });
}

printAllNumbersThenAllPairSums([1,2,3,4,5])

// O(n + n^2) = O(n^2) dominant term

// O(x^2+3x+100+x/2) = O(x^2) again dominant term

INFO