[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Precise Big O?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 2

File: 1101ffprau-1444846806-94.jpg (305KB, 2243x3000px) Image search: [Google]
1101ffprau-1444846806-94.jpg
305KB, 2243x3000px
Anyone know how to find the 'precise' big O for this?

[code]
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
sum += i;
}
}
[/code]

It's one of these, but I'm too stupid to figure it out. My shit isn't adding up.

1. O(4N2 + 5N + 2)
2..O(2N2 + 7N + 2)
3. O(N(N + 1) / 2)
4. O(3N^2 + 11N + 4)/2
5. O(N2)
>>
>>8302534
I stopped caring about computer science when I was introduced to the concept of Big O notation. What a crock of shit. If your algorithm can only be analyzed by inventing an asymptotic limit that can't exist, like some kind of computer science deity , then you are fucking wrong and the computer science is flawed.
>>
File: 1460348954512.png (394KB, 445x441px) Image search: [Google]
1460348954512.png
394KB, 445x441px
>>8302534
They're all correct.
>>
>>8302559
ya know, he ain't wrong

It's also O(1)
sum = (n-1)n(n+1)/6
>>
>>8302548
>/sci/ will actually fall for this copypasta
>>
>>8302534
It's 3
>>
>>8302548
>>>/g/56299762
>>
>>8302534
It's 5. The time complexity is given by answer 3 but n(n+1)/2 is of order O(n^2).

You can work it out because the innermost operation is run n + (n-1) + (n-2) + ... + 2 + 1 times which is equal to n(n+1)/2
>>
>>8302534
>'precise' big O

It's Θ(n^2)
>>
>>8302534
I think it's 2, I'm going to submit my homework soon so I'll let you know whether I was right.
>>
>>8304522
>>8302534
I just submitted it, it's 2. If you need help let me know, I might be able to help a little.
>>
O (n^2)
If it was for (..){} and then a non-nested for loop it would be O (n + k)
>>
>comp sci majors proving once again that they are nothing more than code monkeys
>>
>>8302534
Why would you care about the exact big O and not just the type of complexity?
>>
"Precise"??? Big O

Big O notation doesn't have scaling factors or lower powers in it, that defeats the point, it's about dividing algorithms into broad complexity classes.

Because of how much backend variance there is due to the specific data set, execution architecture, and possible compiler optimization, there literally isn't anything more meaningful you can say about it besides O(n^2). The other ones give you no insight into judging actual run times.
>>
>>8302534
It's [math] \mathcal{O}(n^{2}) [/math]
>>
>>8302534
All of these are equal, but if you absolutely must count the operations, then it's 3.
Thread posts: 17
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.