If not time, then what?
⇒ Rather than counting seconds which are so variable..
→ Let’s count the number of simple operations the computer has to perform!
Counting Operation
function addUpTo(n){
return n * (n + 1) /2;
}
* - multiplication
+ - addition
/ - division
there are 3 operations,regardless of the size of *n*
function addUpTo(n){
let total = 0;
for(let i = 1;i <= n; i++){
total += i;
}
return total;
}
total = 0
assigning 1 time at the beginning
let i = 1
assigning 1 time
i <= n
again n comparisions ??
total += i;
n additions
n assignments
i++
n additions and n assingments
`Counting is hard!`
As the n grows ,the number of operations grow proportion to n