Skip to main content

Big 'O' notation

Yeyy finally! I got time! I am so happy that I am finally going to read the analytic theory! However, I have added some CS stuff. Not sure if they are accurate. I have taken up CS in school so hopefully, it's correct! 


Big $O$ notation: 

We say $f(x)=O(g(x))$ if there exists $c$ such that $|f(x)|< c(g(x)$ for all $x\ge x_0$.

Arithmetic of Big $O$ notation:

  • $O(f(x))+O(g(x))= O(f(x)+g(x))$. Moreover, if $f(x)=O(g(x))\implies O(f(x)+g(x))=O(g(x)) $

  • $O(f(x))\times O(g(x))= O(f(x)\cdot g(x))$

  • $O(f(x)) - O(g(x))= O(f(x) +g(x))$ ( Yes, it is "+")

  • $O(\int f(x) dx)=\int O(f(x) dx$


I want to dive into the CS part; it looks pretty nice and attractive :p.


Introduction


In CS, it is important to measure the efficiency of the algorithm before applying it on a big size of data. The "performance" depends on internal and external factors. Internal factors ( which we care more) specify the algorithm's efficiency in terms of: Time required to run and Space required to run.
External is like Size of the input, quality of compiler etc.

The motivation to study time complexity is to compare algorithms and use the one that is the most efficient in a particular situation. 

The big $O$ notation ( wrt CS)


The big $O$ notation is used to depict an algorithm's growth rate. The growth rate determines the algorithm's performance when its input size grows. Through big-$O$, the upper bound of an algorithm's performance is specified i.e if we say an algorithm takes $O(n^2)$ times; this means that this algorithm will take at most $N^2$ steps for size $N$.

The big-$O$ notation is very useful for comparing performance of two or more algorithms. For example, the algorithm with time complexity $O(n^2)$ performs better than the algorithm with time complexity $O(2^n)$.
 
n=int(input("Enter the value of n:"))

i=1
sum=0
while i<=n:
    sum += i**2
    i+= 1

print("sum=", sum)

The complexity of the above code is $O(n)$. Each step except "while i<=n:"  take $O(1)$ time. But "while i<=n:" takes $O(n)$ time. Summing we get $O(n)$  

Comments

Post a Comment

Popular posts from this blog

My experiences at EGMO, IMOTC and PROMYS experience

Yes, I know. This post should have been posted like 2 months ago. Okay okay, sorry. But yeah, I was just waiting for everything to be over and I was lazy. ( sorry ) You know, the transitioning period from high school to college is very weird. I will join CMI( Chennai Mathematical  Institue) for bsc maths and cs degree. And I am very scared. Like very very scared. No, not about making new friends and all. I don't care about that part because I know a decent amount of CMI people already.  What I am scared of is whether I will be able to handle the coursework and get good grades T_T Anyways, here's my EGMO PDC, EGMO, IMOTC and PROMYS experience. Yes, a lot of stuff. My EGMO experience is a lot and I wrote a lot of details, IMOTC and PROMYS is just a few paras. Oh to those, who don't know me or are reading for the first time. I am Sunaina Pati. I was IND2 at EGMO 2023 which was held in Slovenia. I was also invited to the IMOTC or International Mathematical Olympiad Training Cam...

Geometry ( Finally!!!)

 This is just such an unfair blog.  Like if one goes through this blog, one can notice how dominated  Algebra is!! Like 6 out of 9 blog post is Algebra dominated -_- Where as I am not a fan of Algebra, compared to other genres of Olympiad Math(as of now). And this was just injustice for Synthetic Geo. So this time , go geo!!!!!!!!!!!  These problems are randomly from A Beautiful Journey through Olympiad Geometry.  Also perhaps I will post geo after March, because I am studying combi.  Problem:  Let $ABC$ be an acute triangle where $\angle BAC = 60^{\circ}$. Prove that if the Euler’s line of $\triangle ABC$ intersects $AB$ and $AC$ at $D$ and $E$, respectively, then $\triangle ADE$ is equilateral. Solution:  Since $\angle A=60^{\circ}$ , we get $AH=2R\cos A=R=AO$. So $\angle EHA=\angle DOA.$ Also it's well known that $H$ and $O $ isogonal conjugates.$\angle OAD =\angle EAH.$ By $ASA$ congruence, we get $AE=AD.$ Hence $\triangle ADE$ is equilateral....

Orders and Primitive roots

 Theory  We know what Fermat's little theorem states. If $p$ is a prime number, then for any integer $a$, the number $a^p − a$ is an integer multiple of $p$. In the notation of modular arithmetic, this is expressed as \[a^{p}\equiv a{\pmod {p}}.\] So, essentially, for every $(a,m)=1$, ${a}^{\phi (m)}\equiv 1 \pmod {m}$. But $\phi (m)$ isn't necessarily the smallest exponent. For example, we know $4^{12}\equiv 1\mod 13$ but so is $4^6$. So, we care about the "smallest" exponent $d$ such that $a^d\equiv 1\mod m$ given $(a,m)=1$.  Orders Given a prime $p$, the order of an integer $a$ modulo $p$, $p\nmid a$, is the smallest positive integer $d$, such that $a^d \equiv 1 \pmod p$. This is denoted $\text{ord}_p(a) = d$. If $p$ is a primes and $p\nmid a$, let $d$ be order of $a$ mod $p$. Then $a^n\equiv 1\pmod p\implies d|n$. Let $n=pd+r, r\ll d$. Which implies $a^r\equiv 1\pmod p.$ But $d$ is the smallest natural number. So $r=0$. So $d|n$. Show that $n$ divid...

IMO Shortlist 2021 C1

 I am planning to do at least one ISL every day so that I do not lose my Olympiad touch (and also they are fun to think about!). Today, I tried the 2021 IMO shortlist C1.  (2021 ISL C1) Let $S$ be an infinite set of positive integers, such that there exist four pairwise distinct $a,b,c,d \in S$ with $\gcd(a,b) \neq \gcd(c,d)$. Prove that there exist three pairwise distinct $x,y,z \in S$ such that $\gcd(x,y)=\gcd(y,z) \neq \gcd(z,x)$. Suppose not. Then any $3$ elements $x,y,z\in S$ will be $(x,y)=(y,z)=(x,z)$ or $(x,y)\ne (y,z)\ne (x,z)$. There exists an infinite set $T$ such that $\forall x,y\in T,(x,y)=d,$ where $d$ is constant. Fix a random element $a$. Note that $(x,a)|a$. So $(x,a)\le a$.Since there are infinite elements and finite many possibilities for the gcd (atmost $a$). So $\exists$ set $T$ which is infinite such that $\forall b_1,b_2\in T$ $$(a,b_1)=(a,b_2)=d.$$ Note that if $(b_1,b_2)\ne d$ then we get a contradiction as we get a set satisfying the proble...

Birthday Functional Equations problems

Heyoo!!! Birthday FEs!!!!!! $11$ FEs!! Also I would be posting solutions to RG's FE handout, I am done with 10 prs :P!! Problem: Find all functions $f :\Bbb R \rightarrow \Bbb R$ such that $$2f (x) - 5f (y) = 8, \forall x, y \in \Bbb R$$ Solution: $$2f(x)-5f(y)=8$$ $$\implies 2f(x)-5f(x)=8$$ $$\implies f(x)=\frac{-8}{3}, \text{ a constant function }$$ We did this in Rohan Bhaiya's FE class..Oh btw the EGMO camp is sooo niceee! I am loving it!! It's such a big deal to be able to train and attend the camp with EGMO team members! Problem: Find all functions $f :\Bbb R \rightarrow \Bbb R$ such that $$f (x) + xf (1 -x) = x, \forall x\in \Bbb R.$$ Solution: $$f(x)+xf(1-x)=x$$ $$f(1-x)+(1-x)f(x)=1-x$$ This is actually in the linear equations in two variable form! $$x+ay=a$$ $$y+bx=b$$ Anyways,  $$f(x)+xf(1-x)=x$$ $$xf(1-x)+f(x)(1-x)x=(1-x)x$$ $$ \implies f(x)(x-x^2)-f(x)=-x^2\implies f(x)=\frac{-x^2}{x-x^2-1}=\frac{x^2}{x^2-x+1}$$ But verifying, this doesn't work. Problem: ...

Problems with meeting people!

Yeah, I did some problems and here are a few of them! I hope you guys try them! Putnam, 2018 B3 Find all positive integers $n < 10^{100}$ for which simultaneously $n$ divides $2^n$, $n-1$ divides $2^n - 1$, and $n-2$ divides $2^n - 2$. Proof We have $$n|2^n\implies n=2^a\implies 2^a-1|2^n-1\implies a|n\implies a=2^b$$ $$\implies 2^{2^b}-2|2^{2^a}-2\implies 2^b-1|2^a-1\implies b|a\implies b=2^c.$$ Then simply bounding. USAMO 1987 Determine all solutions in non-zero integers $a$ and $b$ of the equation $$(a^2+b)(a+b^2) = (a-b)^3.$$ Proof We get $$ 2b^2+(a^2-3a)b+(a+3a^2)=0\implies b = \frac{3a-a^2\pm\sqrt{a^4-6a^3-15a^2-8a}}{4}$$ $$\implies a^4-6a^3-15a^2-8a=a(a-8)(a+1)^2\text{ a perfect square}$$ $$\implies a(a-8)=k^2\implies a^2-8a-k^2=0\implies \implies a=\frac{8\pm\sqrt{64+4k^2}}{2}=4\pm\sqrt{16+k^2}. $$ $$ 16+k^2=m^2\implies (m-k)(m+k)=16.$$ Now just bash. USAMO 1988 Suppose that the set $\{1,2,\cdots, 1998\}$ has been partitioned into disjoint pairs $\{a_i,b_i\}$ ($1...

Symmetric Polynomials #week 6

Well... I haven't seen much symmetric polynomials in Olympiads, but still I am learning, because I found them cute. And I am basically using this blog as my notes :P What are symmetric polynomials?  One can understand this with  examples. If we are considering over 3 variables, $x_1,x_2,x_3$ then  $$\sum_{sym}x_1^2\cdot x_2^3\cdot x_3=x_1^2\cdot x_2^3\cdot x_3+x_1^2\cdot x_3^3\cdot x_2+x_2^2\cdot x_1^3\cdot x_3+x_2^2\cdot x_3^3\cdot x_1+x_3^2\cdot x_1^3\cdot x_2.$$ See? $3!$ terms! Let's take one more example with again over 3 variables, $x_1,x_2,x_3$ then $$\sum_{sym}x_1^2\cdot x_2^2= x_1^2\cdot x_2^2+x_1^2\cdot x_3^2+x_2^2\cdot x_1^2+x_2^2\cdot x_3^2+x_3^2\cdot x_1^2+x_3^2\cdot x_2^2$$ Wait.. why 2 times ? So basically what happens in symmetrictric sums, is we go through all $n!$ possible permutations. So, here we have $a^2\cdot b^2\cdot c^0$ as like the "general" form type, right? Now, list down all the $3!=6$ permutations of $x_1,x_2,x_3$, and put them in the gene...

Problems I did this week [Jan8-Jan14]

Yeyy!! I am being so consistent with my posts~~ Here are a few problems I did the past week and yeah INMO going to happen soon :) All the best to everyone who is writing!  I wont be trying any new problems and will simply revise stuffs :) Some problems here are hard. Try them yourself and yeah~~Solutions (with sources) are given at the end! Problems discussed in the blog post Problem1: Let $ABC$ be a triangle whose incircle $\omega$ touches sides $BC, CA, AB$ at $D,E,F$ respectively. Let $H$ be the orthocenter of $DEF$ and let altitude $DH$ intersect $\omega$ again at $P$ and $EF$ intersect $BC$ at $L$. Let the circumcircle of $BPC$ intersect $\omega$ again at $X$. Prove that points $L,D,H,X$ are concyclic. Problem 2: Let $ ABCD$ be a convex quadrangle, $ P$ the intersection of lines $ AB$ and $ CD$, $ Q$ the intersection of lines $ AD$ and $ BC$ and $ O$ the intersection of diagonals $ AC$ and $ BD$. Show that if $ \angle POQ= 90^\circ$ then $ PO$ is the bisector of $ \angle AOD$ ...

Let's complex bash Part 1

I have to learn complex bash. And almost everyone knows that I am notes taking girl so thought why not make a post on complex bash ( so that I don't get emotionally demotivated lol).😇 There wasn't any need for learning complex bash, but it was in my dream checklist i.e " To learn a bash." And since I am not loaded with exams, I think it's high time to learn Bash and new topics.  Also if anyone from the "anti-bash" community is reading, sorry in advance and R.I.P.  Notes:- 1. Complex numbers are of the form $z=a+ib,$ where $a$ and $b$ are real numbers and $i^2=-1.$ 2. In polar form, $z=r(\cos \theta+~~i\sin\theta)=~~re^{i\theta},$ where $r=~~|z|=~~\sqrt{a^2+b^2},$ which is called the magnitude. 3. Here we used euler's formula i.e $\cos \theta+~~i\sin\theta=~~e^{i\theta}.$ 4. The $\theta $ is called the argument of $z,$ denored $\arg z.$ ( $\theta$ can be considered in $\mod 360$ and it is  measured anti-clockwise). 5. The complex conjugate of $z$ is ...

Number Theory Revise part 1

I thought to revise David Burton and try out some problems which I didn't do. It's been almost 2 years since I touched that book so let's see! Also, this set of problems/notes is quite weird since it's actually a memory lane. You will get to know on your own! I started with proving a problem, remembered another problem and then another and so on! It was quite fun cause all these questions were the ones I really wanted to solve! And this is part1 or else the post would be too long. Problem1: Prove that for $n\ge 1$  $$\binom{n}{r}<\binom{n}{r+1}$$ iff $0\le r\le \frac{n-1}{2}$ Proof: We show that $\binom{n}{r}<\binom{n}{r+1}$ for $0\le r\le \frac{n-1}{2}$ and use the fact that $$\binom{n}{n-r}=\binom{n}{r}$$ Note that $\binom{n}{r}= \frac{n!}{r!(n-r)!}, \binom{n}{r+1}=\frac{n!}{(r+1)!(n-r-1)!}$  Comparing, it's enough to show that $$\frac{1}{n-r}<\frac{1}{r+1}\text{ or show } n-r>r+1$$ which is true as $0\le r\le \frac{n-1}{2}$ Problem2: Show that the exp...