Definition of Algorithm and notation
Definition of Algorithm and notation
Definition of Algorithm
Notation refers to how we represent and analyze algorithms in terms of time and
space requirements.
Big O Notation gives the hardest or maximum complexity of an algorithm. It shows how
much work an algorithm might need to do in the worst-case scenario when the input size
increases.
The letter 'O' in Big O stands for "Order", which means how an algorithm grows
as the input size increases. (Big means large data)
If the library has n books, the time taken is proportional to n → Big O is O(n)
Omega (Ω) Notation
It shows how easy or fast an algorithm can be in the best-case scenario, where the time
taken is the minimum possible.
it is useful to check How little time can the algorithm take
Example:
If the first number in the array matches, the search stops → Best case = Ω(1)
Example:
Searching for a book:
If the book is the very first one you pick, you only need one step → Best case
= Ω(1).
On average, the search might take half the size of the array → Θ(n/2)
simplifies to Θ(n).
Example:
Searching for a book:
On average, you might find the book after checking half the books in the
library.
If there are n books, the time is proportional to n/2 → Θ(n)
Symbo
Notation Meaning Example
l
Worst-case O(n) → Check all
Big O (O) O
performance books
Best-case Ω(1) → Find in 1
Omega (Ω) Ω
performance step
Average-case Θ(n) → Check
Theta (Θ) Θ
performance half books
Why Are These Notations Important?