Basics of Time complexity and Space complexity
It is a relation between Input Size & Running Time (operations). Time complexity represents the number of times a statement is executed.
Three types of Time complexitya = int(input('Enter value: '));for i in range(a):print(i)
- BEST CASE
- AVERAGE CASE
- WORST CASE
1. Best case : it means the output found in 1st position. therefore time complexity is Ω(1).
aThe time complexity of this program is O(n²)a = int(input('Enter value: '))for i in range(a):for j in range(a):print("hello", end=" ")print('\n')
few Time complexity Examples
1. two input fields
the time complexity of this example is O(n * m)a = int(input('Enter value: '));b = int(input('enter value'))for i in range(a):for j in range(b):print("hello", end=" ")print('\n')
2. two input fields with two for loop
--> O(n+m)a = int(input('Enter value: '));b = int(input('enter value'))for i in range(a):print("hello", end=" ")for j in range(b):print("hello", end=" ")
Post a Comment