C# Big O: find ##c## and ##n_0## if ##g(n)## is known

  • Thread starter Thread starter Korisnik
  • Start date Start date
AI Thread Summary
The discussion centers on whether constants c and n_0 can be determined for any function f when a known function g is provided. It explores the example of f(n) = a·n^143 + b·n! + d·(n!)! + m·2^n - p·√n + 42, concluding that f is O((n!)!). The author suggests that by summing the absolute values of the coefficients in f, one could establish c, but questions the validity of this method for all functions. The conversation highlights that negative terms in f may not need to be included, as they do not contribute positively to the growth rate. However, a counterexample illustrates that careful selection of n_0 is crucial for the method to hold true.
Korisnik
Messages
62
Reaction score
1
TL;DR Summary
easy way to find c and n0 if g(n) known in O(g(n))
Is it guaranteed that when I have any kind of function ##f##, that I'll be able to find constants ##c## and ##n_0## if I know ##g## by simply adding up the factors multiplying all the terms in the equation?

Suppose ##f(n) = a\cdot n^{143} + b \cdot n! + d \cdot (n!)! + m \cdot 2^n - p \cdot \sqrt{n} + 42##, now I know here that ##f## is ##\mathcal{O}((n!)!)##, meaning that ##g(n) = (n!)!## (where ##\mathcal{O}## takes ##g(n)##).

But can I immediately assume that that holds if I pick ##c = a + b + d + m + p + 42## (taking absolute values of all the factors multiplying each term in ##f(n)##) and letting ##n_0 = 1## such that ## 0 \leq f(n) \leq c \cdot g(n), \ \forall n\in\mathbb{Z}^+,\ n\geq n_0##?

Will this technique work for all functions ##f##? Moreover, I think this can be simplified further by not even taking the factors before negative terms (in this case ##p##).

Thanks in advance.

Edit:

Actually, I think this is sort of trivial to prove, because if indeed we have the "biggest" function ##g(n)## figured out, then if we simply do the following: $$0 \leq f(n) = a\cdot n^{143} + b \cdot n! + d \cdot (n!)! + m \cdot 2^n - p \cdot \sqrt{n} + 42 \leq c \cdot g(n) = (a + b + d + m + p + 42) \cdot (n!)! = a \cdot (n!)! + b \cdot (n!)! + d \cdot (n!)! + m \cdot (n!)! + p \cdot (n!)! + 42 \cdot (n!)!$$ and each of these new terms grows faster than each of the terms in ##f(n)##, and further, since negative terms only "discontribute", there's no need to even include those, because by excluding them, you get a faster growing function than ##f(n)##.
 
Technology news on Phys.org
With n0=1 this won't work.

Consider f(x)=x!+2x. Your approach would lead to g(x)=2x!, then g(1)=2 but f(1)=3.

The approach works if you choose an n0 such that the other terms have the asymptotic inequalities, in this case ##x! \geq 2^x##.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
15
Views
3K
Replies
1
Views
2K
Replies
7
Views
2K
Replies
16
Views
4K
2
Replies
61
Views
9K
Back
Top