big O

function sum_char_codes(n: string): number {
    let sum = 0;
    for (let i = 0; i < n.length; ++i) {
        sum += n.charCodeAt(i);
    }
    return sum;
}
  1. growth is with respect to input
  2. constants dropped
  3. usually measure worst case

Pasted image 20230709014641.png

function sum_char_codes(n: string): number {
    let sum = 0;
    for (let i = 0; i < n.length; ++i) {
        for (let j = 0; j < n.length; ++j) {
            sum += charCode;
        }
    }

    return sum;
}

This is O(N2)

O(n)

The two crystal ball problem

Bubble sort