Can someone please explain in plain English how to calculate it?
I know that you have to visit n+2+(n-1)+2+...+2+2 elements, but how do you get to 1/2n^2 + 5/2n - 3? Thanks!
Can someone please explain in plain English how to calculate it? I know that
Share
n + 2 + (n - 1) + 2 + ... + 2 + 2is equal to(n + 2) + (n + 1) + ... + 4. It’s an arithmetic progression and its sum is calculated as(n + 2 + 4) * (n + 2 - 4 + 1) / 2. It’s equal to(n + 6) * (n - 1) / 2and finally1/2 * n^2 + 5/2 * n - 3.f(n) = O(g(n))means there exists such constantCthatf(n) <= C * g(n)for all sufficiently large n. If n is considered as natural number then1/2 * n^2 + 5/2 * n - 3 = O(n^2)withC = 3/2for example.