The last example doesn't look quadratic to me but linear, because the second loop is executed a fixed number of times. Its complexity would be O(10 * n), which is proportional to O(n)
Engineering leader in AI, search and product engineering. Nearly three decades building search, data and AI systems. Ex-Google, Microsoft, Salesforce, Tableau.
The last example doesn't look quadratic to me but linear, because the second loop is executed a fixed number of times. Its complexity would be O(10 * n), which is proportional to O(n)
Updated
O(10 *n) how ?
Can you explain please !
The author fixed it, but the code used to be something like:
The
console.logstatement is executedarr.length * 10times. That's a complexity of O(10* n), n being the size of thearrarray.Looking forward to read the next tuts ! 👍
checkout next tutorial .
the last example should have
for (var j = 1; j <= n; j++) {
or
for (var j = 1; j <= i; j++) {
for 2'd loop
to be O(n2). That's critical. Any constants in Big O notation can be dropped
Updated
It would be nice if you could expand a bit on this topic since there's more to it.
The Big-O Cheat Sheet is nice, especially that poster!!
Ouch, logarithms one were the content I was looking for when I entered here, I hope you will post it soon.
checkout Logarithms