The Basic Definition of time complexity is, In computer science, the time complexity is the computational(*involving the calculation of answers, amounts, results, etc*) complexity that describes the amount of computer time it takes to run an algorithm.

E.g **Consider the below simple code**

`class Demo {`

public static void main(String[] args) {

System.out.println("Hello There Good Morning");

}

}

In the above example the output prints only one time so its time is number 1, in and its denotes by Big Oh of 1 (O(1)) that is constant time, **The above O -> is called Big – Oh which is an asymptotic notation.**

E.g **Consider The Below Simple code**

`class Demo2 {`

public static void main(String[] args)

{

int i, n = 8;

for (i = 1; i <= n; i++) {

System.out.println("Hello Good Evening");

}

}

}

**so the output of the above code is Hello Good Evening will print 8 times in console**

so thats means the time complexity of above code is O(n) where n = 8 and as the value of n can changes according to programmer so thats why its time complexity is O(n).

## Top comments (0)