[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Is this thought process correct? int fac (int i) if i <
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 11
Thread images: 1
File: 1449153509227.gif (89 KB, 325x245) Image search: [Google]
1449153509227.gif
89 KB, 325x245
Is this thought process correct?

int fac (int i)
if i < 1 // O(1) |+
return 0 // O(1)
else if i == 1 // O(1) |+
return 1 // O(1)
else
return i * fac(i - 1) // O(n)
} // => O(max(O(1),O(1))+O(n))
= O(n)


while (n >= 1) { // O(n)
n = n/4 // O(1)
instr with f(n) // O(f(n))
} // => O(n)+O(1)+O(f(n)) = max(O(n),O(f(n))
>>
>>54502041
>not using code brackets

can't even read m8
>>
use code tags
>>
>>54502041
> O(n)

> O(n)*O(f(n))
>>
int fac (int i) {
if i < 1 // O(1) |+
return 0 // O(1)
else if i == 1 // O(1) |+
return 1 // O(1)
else
return i * fac(i - 1) // O(n)
} // => O(max(O(1),O(1))+O(n))
= O(n)


while (n >= 1) { // O(n)
n = n/4 // O(1)
instr with f(n) // O(f(n))
} // => O(n)+O(1)+O(f(n)) = max(O(n),O(f(n))
>>
>>54502166
>still using big O
Shiggymydiggy
>>
>>54502166
Only choices count, or so I've heard.
>>
>>54504369
you heard wrong
>>
>>54502041
>>54502166
Nope, that thought process is incorrect. Are you smoking meth?
>>
>>54502166
>>54504369
>>54504459
Eh, it depends on what you're measuring.

O is an abstract notation that just gives you some way of categorizing the growth behavior of an arbitrary function. In itself it has absolutely nothing to do with performance or memory usage or anything.

But you can use it to talk about exactly those things. For that, it depends on what exactly you're trying to capture.

For example, in a claim like “This sorting algorithm will perform O(n) pairwise comparisons”, then only the number of comparisons matters.

In a claim like “This algorithm will perform O(n) integer multiplications”, then only the number of multiplications matters.

When the exact quantity you're counting is left away, it's generally taken to mean something vague like “atomic instructions”, where an atomic instruction is anything that runs in some small fixed amount of time. (For example, doing a comparison, or performing a branch, or adding two fixed-width integers)

Special care needs to be taken to distinguish between bit complexity (for theoretical algorithms running on unbounded inputs) and integer complexity (for real-world algorithms running on fixed integers). In the case of the former, you're generally counting the number of bit operations (e.g. gate evaluations) that need to be done.

Or the number of state transitions in a turing machine. Or whatever.
>>
>>54504459
I heard that from the guy who interviewed me for a developer job. I had a feeling he's wrong because he gave a very simple Big-O notation for my complicated recursive function.
Thread replies: 11
Thread images: 1

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.