Day 2 of 100daysofcode : Time Complexity and Big-O Notation

let’s suppose we write a code and we understand it well, but do you ever thought if your code is scalable and clean?

So here comes time complexity to help us measures how the runtime of an algorithm changes as the input size increases. It helps evaluate the efficiency of algorithms and choose the best one for a task. Often expressed using Big-O notation, which provides an upper bound on the worst-case scenario.

Big O notation is used to describe the upper bound of an algorithm’s runtime. It gives an idea of the worst-case scenario as input size grows.

Common Big O notations include:

O(1): Constant time
O(log n): Logarithmic time
O(n): Linear time
O(n²): Quadratic time
O(2ⁿ): Exponential time

Below are two examples on how to find complexity using Big-O notation:

So why it matters?

Understanding time complexity helps in predicting the performance of algorithms, and choosing scalable solutions.

Big O notation provides a universal way to compare algorithms, ensuring the best choice for the problem at hand.

100daysofcode lebanon-mug