I am curious. What is the correct way to describe this using Big-O Notation?
var prices = [100, 180, 260, 590, 40, 310, 535, 10, 5, 3];
var biggest_profit = 0;
for (var i = 0; i < prices.length; i++) {
var first_price = prices[i];
for (var j = i + 1; j <= prices.length; j++) {
// do something here
}
}
This is the bit that throws me off:
j = i + 1
Every time we go through i, the j becomes shorter and shorter.
What is the correct name for this pattern in Big O Notation?
You can use Sigma notation to calculate the number of visits of the inner loop ("do something here")

Where (*) follows from a summation rule made famous by the rumour that Gauss once derived it on-the-spot as a young student.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With